From 151fdb65570c0254166587bd172ac2759e3a2723 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 18 Nov 2026 10:11:47 -0800 Subject: [PATCH 1/2] fix(integrations): validate pinecone, qdrant, elasticsearch and zep Pinecone fetch sends one ids query param per vector, search text targets __default__ when no namespace is set and sends rerank.query as a string. Qdrant, Elasticsearch and Zep path segments are encoded and dot segments rejected. --- apps/sim/tools/elasticsearch/bulk.ts | 3 +- apps/sim/tools/elasticsearch/count.ts | 3 +- apps/sim/tools/elasticsearch/create_index.ts | 3 +- .../tools/elasticsearch/delete_document.ts | 3 +- apps/sim/tools/elasticsearch/delete_index.ts | 3 +- apps/sim/tools/elasticsearch/get_document.ts | 3 +- apps/sim/tools/elasticsearch/get_index.ts | 3 +- .../sim/tools/elasticsearch/index_document.ts | 5 +- apps/sim/tools/elasticsearch/search.ts | 3 +- .../tools/elasticsearch/update_document.ts | 3 +- apps/sim/tools/pinecone/fetch.ts | 6 +- apps/sim/tools/pinecone/requests.test.ts | 56 +++++++++++++++++++ apps/sim/tools/pinecone/search_text.ts | 16 ++++-- apps/sim/tools/pinecone/types.ts | 7 ++- apps/sim/tools/pinecone/upsert_text.ts | 3 +- apps/sim/tools/qdrant/fetch_points.ts | 3 +- apps/sim/tools/qdrant/upsert_points.ts | 3 +- apps/sim/tools/zep/add_messages.ts | 4 +- apps/sim/tools/zep/delete_thread.ts | 4 +- apps/sim/tools/zep/get_context.ts | 3 +- apps/sim/tools/zep/get_messages.ts | 3 +- apps/sim/tools/zep/get_user.ts | 4 +- apps/sim/tools/zep/get_user_threads.ts | 3 +- 23 files changed, 117 insertions(+), 30 deletions(-) create mode 100644 apps/sim/tools/pinecone/requests.test.ts diff --git a/apps/sim/tools/elasticsearch/bulk.ts b/apps/sim/tools/elasticsearch/bulk.ts index 040f7625f0e..c4835ee79fe 100644 --- a/apps/sim/tools/elasticsearch/bulk.ts +++ b/apps/sim/tools/elasticsearch/bulk.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const bulkTool: ToolConfig = { id: 'elasticsearch_bulk', @@ -77,7 +78,7 @@ export const bulkTool: ToolConfig { const baseUrl = buildBaseUrl(params) let url = params.index - ? `${baseUrl}/${encodeURIComponent(params.index)}/_bulk` + ? `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_bulk` : `${baseUrl}/_bulk` if (params.refresh) { diff --git a/apps/sim/tools/elasticsearch/count.ts b/apps/sim/tools/elasticsearch/count.ts index 19a555f12bd..7bd841bb925 100644 --- a/apps/sim/tools/elasticsearch/count.ts +++ b/apps/sim/tools/elasticsearch/count.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const countTool: ToolConfig = { id: 'elasticsearch_count', @@ -70,7 +71,7 @@ export const countTool: ToolConfig { const baseUrl = buildBaseUrl(params) - return `${baseUrl}/${encodeURIComponent(params.index)}/_count` + return `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_count` }, method: 'POST', headers: (params) => buildAuthHeaders(params), diff --git a/apps/sim/tools/elasticsearch/create_index.ts b/apps/sim/tools/elasticsearch/create_index.ts index 44a3c97f6a0..b2b12282c35 100644 --- a/apps/sim/tools/elasticsearch/create_index.ts +++ b/apps/sim/tools/elasticsearch/create_index.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const createIndexTool: ToolConfig< ElasticsearchCreateIndexParams, @@ -76,7 +77,7 @@ export const createIndexTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - return `${baseUrl}/${encodeURIComponent(params.index)}` + return `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}` }, method: 'PUT', headers: (params) => buildAuthHeaders(params), diff --git a/apps/sim/tools/elasticsearch/delete_document.ts b/apps/sim/tools/elasticsearch/delete_document.ts index 0572fc714fa..36c992f9b34 100644 --- a/apps/sim/tools/elasticsearch/delete_document.ts +++ b/apps/sim/tools/elasticsearch/delete_document.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const deleteDocumentTool: ToolConfig< ElasticsearchDeleteDocumentParams, @@ -77,7 +78,7 @@ export const deleteDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${encodeURIComponent(params.index)}/_doc/${encodeURIComponent(params.documentId)}` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` if (params.refresh) { url += `?refresh=${params.refresh}` diff --git a/apps/sim/tools/elasticsearch/delete_index.ts b/apps/sim/tools/elasticsearch/delete_index.ts index 62154f1df60..eff20d97ac5 100644 --- a/apps/sim/tools/elasticsearch/delete_index.ts +++ b/apps/sim/tools/elasticsearch/delete_index.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const deleteIndexTool: ToolConfig< ElasticsearchDeleteIndexParams, @@ -66,7 +67,7 @@ export const deleteIndexTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - return `${baseUrl}/${encodeURIComponent(params.index)}` + return `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}` }, method: 'DELETE', headers: (params) => buildAuthHeaders(params), diff --git a/apps/sim/tools/elasticsearch/get_document.ts b/apps/sim/tools/elasticsearch/get_document.ts index 6b62b51fd8b..758d1956fb2 100644 --- a/apps/sim/tools/elasticsearch/get_document.ts +++ b/apps/sim/tools/elasticsearch/get_document.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const getDocumentTool: ToolConfig< ElasticsearchGetDocumentParams, @@ -82,7 +83,7 @@ export const getDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${encodeURIComponent(params.index)}/_doc/${encodeURIComponent(params.documentId)}` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` const queryParams: string[] = [] if (params.sourceIncludes) { diff --git a/apps/sim/tools/elasticsearch/get_index.ts b/apps/sim/tools/elasticsearch/get_index.ts index 4b6ea6a0fca..4e84cf2c0e1 100644 --- a/apps/sim/tools/elasticsearch/get_index.ts +++ b/apps/sim/tools/elasticsearch/get_index.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const getIndexTool: ToolConfig = { @@ -64,7 +65,7 @@ export const getIndexTool: ToolConfig { const baseUrl = buildBaseUrl(params) - return `${baseUrl}/${encodeURIComponent(params.index)}` + return `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}` }, method: 'GET', headers: (params) => buildAuthHeaders(params), diff --git a/apps/sim/tools/elasticsearch/index_document.ts b/apps/sim/tools/elasticsearch/index_document.ts index c7f9b18067d..2e8f835af81 100644 --- a/apps/sim/tools/elasticsearch/index_document.ts +++ b/apps/sim/tools/elasticsearch/index_document.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const indexDocumentTool: ToolConfig< ElasticsearchIndexDocumentParams, @@ -82,9 +83,9 @@ export const indexDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${encodeURIComponent(params.index)}/_doc` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc` if (params.documentId) { - url += `/${encodeURIComponent(params.documentId)}` + url += `/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` } if (params.refresh) { url += `?refresh=${params.refresh}` diff --git a/apps/sim/tools/elasticsearch/search.ts b/apps/sim/tools/elasticsearch/search.ts index 9419c6a6152..d9c960f0bf9 100644 --- a/apps/sim/tools/elasticsearch/search.ts +++ b/apps/sim/tools/elasticsearch/search.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const searchTool: ToolConfig = { id: 'elasticsearch_search', @@ -105,7 +106,7 @@ export const searchTool: ToolConfig { const baseUrl = buildBaseUrl(params) - return `${baseUrl}/${encodeURIComponent(params.index)}/_search` + return `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_search` }, method: 'POST', headers: (params) => buildAuthHeaders(params), diff --git a/apps/sim/tools/elasticsearch/update_document.ts b/apps/sim/tools/elasticsearch/update_document.ts index 5d90adeb996..8a927f8a583 100644 --- a/apps/sim/tools/elasticsearch/update_document.ts +++ b/apps/sim/tools/elasticsearch/update_document.ts @@ -4,6 +4,7 @@ import type { } from '@/tools/elasticsearch/types' import { buildAuthHeaders, buildBaseUrl } from '@/tools/elasticsearch/utils' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const updateDocumentTool: ToolConfig< ElasticsearchUpdateDocumentParams, @@ -82,7 +83,7 @@ export const updateDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${encodeURIComponent(params.index)}/_update/${encodeURIComponent(params.documentId)}` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_update/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` if (params.retryOnConflict !== undefined) { url += `?retry_on_conflict=${params.retryOnConflict}` diff --git a/apps/sim/tools/pinecone/fetch.ts b/apps/sim/tools/pinecone/fetch.ts index 8425e4780de..1179fefafb5 100644 --- a/apps/sim/tools/pinecone/fetch.ts +++ b/apps/sim/tools/pinecone/fetch.ts @@ -1,4 +1,5 @@ import type { PineconeFetchParams, PineconeResponse, PineconeVector } from '@/tools/pinecone/types' +import { parseJsonParam } from '@/tools/pinecone/utils' import type { ToolConfig } from '@/tools/types' export const fetchTool: ToolConfig = { @@ -39,7 +40,10 @@ export const fetchTool: ToolConfig = { url: (params) => { const baseUrl = `${params.indexHost}/vectors/fetch` const queryParams = new URLSearchParams() - queryParams.append('ids', params.ids.join(',')) + const ids = parseJsonParam(params.ids, 'ids') + for (const id of Array.isArray(ids) ? ids : [ids]) { + queryParams.append('ids', String(id)) + } if (params.namespace) { queryParams.append('namespace', params.namespace) } diff --git a/apps/sim/tools/pinecone/requests.test.ts b/apps/sim/tools/pinecone/requests.test.ts new file mode 100644 index 00000000000..be36d62dadf --- /dev/null +++ b/apps/sim/tools/pinecone/requests.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, it } from 'vitest' +import { fetchTool } from '@/tools/pinecone/fetch' +import { searchTextTool } from '@/tools/pinecone/search_text' +import type { PineconeFetchParams, PineconeSearchTextParams } from '@/tools/pinecone/types' + +const INDEX_HOST = 'https://example-index.svc.example.pinecone.io' + +function buildUrl

(tool: { request: { url: unknown } }, params: P): URL { + const url = tool.request.url as (params: P) => string + return new URL(url(params)) +} + +describe('pinecone_fetch request', () => { + it('repeats the ids query parameter once per vector id', () => { + const url = buildUrl(fetchTool, { + indexHost: INDEX_HOST, + ids: ['vec-1', 'vec-2'], + namespace: 'docs', + apiKey: 'key', + }) + + expect(url.searchParams.getAll('ids')).toEqual(['vec-1', 'vec-2']) + }) +}) + +describe('pinecone_search_text request', () => { + const baseParams: PineconeSearchTextParams = { + indexHost: INDEX_HOST, + searchQuery: 'capital of France', + apiKey: 'key', + } + + it('searches the default namespace when no namespace is given', () => { + const url = buildUrl(searchTextTool, baseParams) + + expect(url.pathname).toBe('/records/namespaces/__default__/search') + }) + + it('sends the rerank query as a string', () => { + const body = searchTextTool.request.body as ( + params: PineconeSearchTextParams + ) => Record> + + const withoutQuery = body({ + ...baseParams, + rerank: { model: 'bge-reranker-v2-m3', rank_fields: ['chunk_text'] }, + }) + expect(withoutQuery.rerank.query).toBeUndefined() + + const withObjectQuery = body({ + ...baseParams, + rerank: { model: 'bge-reranker-v2-m3', query: { text: 'Paris' } }, + }) + expect(withObjectQuery.rerank.query).toBe('Paris') + }) +}) diff --git a/apps/sim/tools/pinecone/search_text.ts b/apps/sim/tools/pinecone/search_text.ts index c102da2ea21..c7734792534 100644 --- a/apps/sim/tools/pinecone/search_text.ts +++ b/apps/sim/tools/pinecone/search_text.ts @@ -22,6 +22,7 @@ function selectRerankModelInput( const rerank = parseRerank(value) if (!rerank) return undefined const query = rerank.query + if (typeof query === 'string') return { query } if ( query === null || typeof query !== 'object' || @@ -132,7 +133,8 @@ export const searchTextTool: ToolConfig `${params.indexHost}/records/namespaces/${params.namespace}/search`, + url: (params) => + `${params.indexHost}/records/namespaces/${encodeURIComponent(params.namespace?.trim() || '__default__')}/search`, headers: (params) => ({ 'Api-Key': params.apiKey, 'Content-Type': 'application/json', @@ -162,11 +164,13 @@ export const searchTextTool: ToolConfig).text } + : rerank } return body diff --git a/apps/sim/tools/pinecone/types.ts b/apps/sim/tools/pinecone/types.ts index ef911c9cc2a..0b023a9053b 100644 --- a/apps/sim/tools/pinecone/types.ts +++ b/apps/sim/tools/pinecone/types.ts @@ -81,13 +81,14 @@ export interface PineconeUpsertTextParams extends PineconeBaseParams { interface PineconeRerank { model: string - rank_fields: string[] + rank_fields?: string[] top_n?: number parameters?: Record - query?: { text: string } + query?: string | { text: string } } -export interface PineconeSearchTextParams extends PineconeBaseParams { +export interface PineconeSearchTextParams extends Omit { + namespace?: string searchQuery: string topK?: string fields?: string[] | string diff --git a/apps/sim/tools/pinecone/upsert_text.ts b/apps/sim/tools/pinecone/upsert_text.ts index 62218eb572a..ae6faddca1d 100644 --- a/apps/sim/tools/pinecone/upsert_text.ts +++ b/apps/sim/tools/pinecone/upsert_text.ts @@ -90,7 +90,8 @@ export const upsertTextTool: ToolConfig `${params.indexHost}/records/namespaces/${params.namespace}/upsert`, + url: (params) => + `${params.indexHost}/records/namespaces/${encodeURIComponent(params.namespace.trim())}/upsert`, headers: (params) => ({ 'Api-Key': params.apiKey, 'Content-Type': 'application/x-ndjson', diff --git a/apps/sim/tools/qdrant/fetch_points.ts b/apps/sim/tools/qdrant/fetch_points.ts index 5350755f34e..831845f8274 100644 --- a/apps/sim/tools/qdrant/fetch_points.ts +++ b/apps/sim/tools/qdrant/fetch_points.ts @@ -57,7 +57,8 @@ export const fetchPointsTool: ToolConfig = { request: { method: 'POST', - url: (params) => `${params.url.replace(/\/$/, '')}/collections/${params.collection}/points`, + url: (params) => + `${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points`, headers: (params) => ({ 'Content-Type': 'application/json', ...(params.apiKey ? { 'api-key': params.apiKey } : {}), diff --git a/apps/sim/tools/qdrant/upsert_points.ts b/apps/sim/tools/qdrant/upsert_points.ts index 10260c90ebc..987fc3131d7 100644 --- a/apps/sim/tools/qdrant/upsert_points.ts +++ b/apps/sim/tools/qdrant/upsert_points.ts @@ -42,7 +42,8 @@ export const upsertPointsTool: ToolConfig = request: { method: 'PUT', - url: (params) => `${params.url.replace(/\/$/, '')}/collections/${params.collection}/points`, + url: (params) => + `${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points`, headers: (params) => ({ 'Content-Type': 'application/json', ...(params.apiKey ? { 'api-key': params.apiKey } : {}), diff --git a/apps/sim/tools/zep/add_messages.ts b/apps/sim/tools/zep/add_messages.ts index b8a22cb666b..7fa41057c1d 100644 --- a/apps/sim/tools/zep/add_messages.ts +++ b/apps/sim/tools/zep/add_messages.ts @@ -1,5 +1,6 @@ import { ZEP_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' import type { ZepResponse } from '@/tools/zep/types' import { THREAD_OUTPUT_PROPERTIES } from '@/tools/zep/types' @@ -100,7 +101,8 @@ export const zepAddMessagesTool: ToolConfig = } }, }, - url: (params) => `https://api.getzep.com/api/v2/threads/${params.threadId}/messages`, + url: (params) => + `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}/messages`, method: 'POST', headers: (params) => ({ Authorization: `Api-Key ${params.apiKey}`, diff --git a/apps/sim/tools/zep/delete_thread.ts b/apps/sim/tools/zep/delete_thread.ts index 24757a56a60..11a71b97aed 100644 --- a/apps/sim/tools/zep/delete_thread.ts +++ b/apps/sim/tools/zep/delete_thread.ts @@ -1,5 +1,6 @@ import { ZEP_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' import type { ZepResponse } from '@/tools/zep/types' export const zepDeleteThreadTool: ToolConfig = { @@ -25,7 +26,8 @@ export const zepDeleteThreadTool: ToolConfig = { }, request: { - url: (params) => `https://api.getzep.com/api/v2/threads/${params.threadId}`, + url: (params) => + `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}`, method: 'DELETE', headers: (params) => ({ Authorization: `Api-Key ${params.apiKey}`, diff --git a/apps/sim/tools/zep/get_context.ts b/apps/sim/tools/zep/get_context.ts index 6fae8b3f5d2..86a61089c93 100644 --- a/apps/sim/tools/zep/get_context.ts +++ b/apps/sim/tools/zep/get_context.ts @@ -1,5 +1,6 @@ import { ZEP_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' import type { ZepResponse } from '@/tools/zep/types' export const zepGetContextTool: ToolConfig = { @@ -44,7 +45,7 @@ export const zepGetContextTool: ToolConfig = { queryParams.append('mode', mode) if (params.minRating !== undefined) queryParams.append('minRating', String(Number(params.minRating))) - return `https://api.getzep.com/api/v2/threads/${params.threadId}/context?${queryParams.toString()}` + return `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}/context?${queryParams.toString()}` }, method: 'GET', headers: (params) => ({ diff --git a/apps/sim/tools/zep/get_messages.ts b/apps/sim/tools/zep/get_messages.ts index d4067dc0be5..663b78fb768 100644 --- a/apps/sim/tools/zep/get_messages.ts +++ b/apps/sim/tools/zep/get_messages.ts @@ -1,5 +1,6 @@ import { ZEP_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' import type { ZepResponse } from '@/tools/zep/types' import { MESSAGES_ARRAY_OUTPUT, PAGINATION_OUTPUT_PROPERTIES } from '@/tools/zep/types' @@ -51,7 +52,7 @@ export const zepGetMessagesTool: ToolConfig = { if (params.lastn) queryParams.append('lastn', String(Number(params.lastn))) const queryString = queryParams.toString() - return `https://api.getzep.com/api/v2/threads/${params.threadId}/messages${queryString ? `?${queryString}` : ''}` + return `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}/messages${queryString ? `?${queryString}` : ''}` }, method: 'GET', headers: (params) => ({ diff --git a/apps/sim/tools/zep/get_user.ts b/apps/sim/tools/zep/get_user.ts index ee66925c54d..4f306bbff42 100644 --- a/apps/sim/tools/zep/get_user.ts +++ b/apps/sim/tools/zep/get_user.ts @@ -1,5 +1,6 @@ import { ZEP_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' import type { ZepResponse } from '@/tools/zep/types' import { USER_OUTPUT_PROPERTIES } from '@/tools/zep/types' @@ -26,7 +27,8 @@ export const zepGetUserTool: ToolConfig = { }, request: { - url: (params) => `https://api.getzep.com/api/v2/users/${params.userId}`, + url: (params) => + `https://api.getzep.com/api/v2/users/${safeUrlPathSegment(params.userId, 'userId', { allowSeparators: true })}`, method: 'GET', headers: (params) => ({ Authorization: `Api-Key ${params.apiKey}`, diff --git a/apps/sim/tools/zep/get_user_threads.ts b/apps/sim/tools/zep/get_user_threads.ts index cc13efc7322..083c4328e2b 100644 --- a/apps/sim/tools/zep/get_user_threads.ts +++ b/apps/sim/tools/zep/get_user_threads.ts @@ -1,5 +1,6 @@ import { ZEP_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' import type { ZepResponse } from '@/tools/zep/types' import { PAGINATION_OUTPUT_PROPERTIES, THREADS_ARRAY_OUTPUT } from '@/tools/zep/types' @@ -35,7 +36,7 @@ export const zepGetUserThreadsTool: ToolConfig = { request: { url: (params) => { const limit = Number(params.limit || 10) - return `https://api.getzep.com/api/v2/users/${params.userId}/threads?limit=${limit}` + return `https://api.getzep.com/api/v2/users/${safeUrlPathSegment(params.userId, 'userId', { allowSeparators: true })}/threads?limit=${limit}` }, method: 'GET', headers: (params) => ({ From ef08ed13ce0b73a9eb73daa79049d43beabc3c6b Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 18 Nov 2026 10:21:58 -0800 Subject: [PATCH 2/2] fix(integrations): keep exact ids in encoded path segments and require a pinecone search namespace --- apps/sim/tools/elasticsearch/delete_document.ts | 9 ++++++++- apps/sim/tools/elasticsearch/get_document.ts | 9 ++++++++- apps/sim/tools/elasticsearch/index_document.ts | 5 ++++- apps/sim/tools/elasticsearch/update_document.ts | 9 ++++++++- .../tools/nested-model-input-adapters.test.ts | 5 +++-- apps/sim/tools/pinecone/requests.test.ts | 14 ++++++++++---- apps/sim/tools/pinecone/search_text.ts | 16 ++++++++++------ apps/sim/tools/pinecone/upsert_text.ts | 3 ++- apps/sim/tools/qdrant/fetch_points.ts | 3 ++- apps/sim/tools/qdrant/search_vector.ts | 3 ++- apps/sim/tools/qdrant/upsert_points.ts | 3 ++- apps/sim/tools/url-path.test.ts | 6 ++++++ apps/sim/tools/url-path.ts | 10 +++++++--- apps/sim/tools/zep/add_messages.ts | 5 ++++- apps/sim/tools/zep/delete_thread.ts | 5 ++++- apps/sim/tools/zep/get_context.ts | 9 ++++++++- apps/sim/tools/zep/get_messages.ts | 9 ++++++++- apps/sim/tools/zep/get_user.ts | 5 ++++- apps/sim/tools/zep/get_user_threads.ts | 5 ++++- 19 files changed, 104 insertions(+), 29 deletions(-) diff --git a/apps/sim/tools/elasticsearch/delete_document.ts b/apps/sim/tools/elasticsearch/delete_document.ts index 36c992f9b34..272225f9fc8 100644 --- a/apps/sim/tools/elasticsearch/delete_document.ts +++ b/apps/sim/tools/elasticsearch/delete_document.ts @@ -78,7 +78,14 @@ export const deleteDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment( + params.documentId, + 'documentId', + { + allowSeparators: true, + preserveWhitespace: true, + } + )}` if (params.refresh) { url += `?refresh=${params.refresh}` diff --git a/apps/sim/tools/elasticsearch/get_document.ts b/apps/sim/tools/elasticsearch/get_document.ts index 758d1956fb2..04ec60f9538 100644 --- a/apps/sim/tools/elasticsearch/get_document.ts +++ b/apps/sim/tools/elasticsearch/get_document.ts @@ -83,7 +83,14 @@ export const getDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment( + params.documentId, + 'documentId', + { + allowSeparators: true, + preserveWhitespace: true, + } + )}` const queryParams: string[] = [] if (params.sourceIncludes) { diff --git a/apps/sim/tools/elasticsearch/index_document.ts b/apps/sim/tools/elasticsearch/index_document.ts index 2e8f835af81..04ac52ccb65 100644 --- a/apps/sim/tools/elasticsearch/index_document.ts +++ b/apps/sim/tools/elasticsearch/index_document.ts @@ -85,7 +85,10 @@ export const indexDocumentTool: ToolConfig< const baseUrl = buildBaseUrl(params) let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc` if (params.documentId) { - url += `/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` + url += `/${safeUrlPathSegment(params.documentId, 'documentId', { + allowSeparators: true, + preserveWhitespace: true, + })}` } if (params.refresh) { url += `?refresh=${params.refresh}` diff --git a/apps/sim/tools/elasticsearch/update_document.ts b/apps/sim/tools/elasticsearch/update_document.ts index 8a927f8a583..9b71504de5f 100644 --- a/apps/sim/tools/elasticsearch/update_document.ts +++ b/apps/sim/tools/elasticsearch/update_document.ts @@ -83,7 +83,14 @@ export const updateDocumentTool: ToolConfig< request: { url: (params) => { const baseUrl = buildBaseUrl(params) - let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_update/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}` + let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_update/${safeUrlPathSegment( + params.documentId, + 'documentId', + { + allowSeparators: true, + preserveWhitespace: true, + } + )}` if (params.retryOnConflict !== undefined) { url += `?retry_on_conflict=${params.retryOnConflict}` diff --git a/apps/sim/tools/nested-model-input-adapters.test.ts b/apps/sim/tools/nested-model-input-adapters.test.ts index b544d5a31cc..3a19ba69695 100644 --- a/apps/sim/tools/nested-model-input-adapters.test.ts +++ b/apps/sim/tools/nested-model-input-adapters.test.ts @@ -374,8 +374,9 @@ describe('nested model-input adapters', () => { apiKey: 'key', rerank, searchQuery: patch.searchQuery as string, - }) as { rerank: { query: { text: string } } } - expect(body.rerank.query.text).toBe('{{SEARCH_QUERY}}') + }) as { query: { inputs: { text: string } }; rerank: { query?: string } } + expect(body.query.inputs.text).toBe('{{SEARCH_QUERY}}') + expect(body.rerank.query).toBeUndefined() }) it('preserves Pinecone singleton and legacy NDJSON input forms', () => { diff --git a/apps/sim/tools/pinecone/requests.test.ts b/apps/sim/tools/pinecone/requests.test.ts index be36d62dadf..99eb37f2b31 100644 --- a/apps/sim/tools/pinecone/requests.test.ts +++ b/apps/sim/tools/pinecone/requests.test.ts @@ -30,10 +30,10 @@ describe('pinecone_search_text request', () => { apiKey: 'key', } - it('searches the default namespace when no namespace is given', () => { - const url = buildUrl(searchTextTool, baseParams) - - expect(url.pathname).toBe('/records/namespaces/__default__/search') + it('rejects a missing namespace instead of searching a namespace named "undefined"', () => { + expect(() => buildUrl(searchTextTool, baseParams)).toThrow( + /namespace is required/ + ) }) it('sends the rerank query as a string', () => { @@ -52,5 +52,11 @@ describe('pinecone_search_text request', () => { rerank: { model: 'bge-reranker-v2-m3', query: { text: 'Paris' } }, }) expect(withObjectQuery.rerank.query).toBe('Paris') + + const withBlankQuery = body({ + ...baseParams, + rerank: { model: 'bge-reranker-v2-m3', query: ' ' }, + }) + expect(withBlankQuery.rerank.query).toBeUndefined() }) }) diff --git a/apps/sim/tools/pinecone/search_text.ts b/apps/sim/tools/pinecone/search_text.ts index c7734792534..39fc5eb739d 100644 --- a/apps/sim/tools/pinecone/search_text.ts +++ b/apps/sim/tools/pinecone/search_text.ts @@ -4,6 +4,7 @@ import type { PineconeSearchTextParams, } from '@/tools/pinecone/types' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' function parseRerank( value: PineconeSearchTextParams['rerank'] @@ -134,7 +135,7 @@ export const searchTextTool: ToolConfig - `${params.indexHost}/records/namespaces/${encodeURIComponent(params.namespace?.trim() || '__default__')}/search`, + `${params.indexHost}/records/namespaces/${safeUrlPathSegment(params.namespace ?? '', 'namespace', { allowSeparators: true, preserveWhitespace: true })}/search`, headers: (params) => ({ 'Api-Key': params.apiKey, 'Content-Type': 'application/json', @@ -164,12 +165,15 @@ export const searchTextTool: ToolConfig).text } + ? (rerankQuery as Record).text + : rerankQuery + // Pinecone takes `rerank.query` as a string and reranks against the search query when unset. + body.rerank = + typeof queryText === 'string' && queryText.trim() + ? { ...rerank, query: queryText } : rerank } diff --git a/apps/sim/tools/pinecone/upsert_text.ts b/apps/sim/tools/pinecone/upsert_text.ts index ae6faddca1d..c4f2122f593 100644 --- a/apps/sim/tools/pinecone/upsert_text.ts +++ b/apps/sim/tools/pinecone/upsert_text.ts @@ -4,6 +4,7 @@ import type { PineconeUpsertTextRecord, } from '@/tools/pinecone/types' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' function parseUpsertTextRecords( input: PineconeUpsertTextParams['records'] @@ -91,7 +92,7 @@ export const upsertTextTool: ToolConfig - `${params.indexHost}/records/namespaces/${encodeURIComponent(params.namespace.trim())}/upsert`, + `${params.indexHost}/records/namespaces/${safeUrlPathSegment(params.namespace, 'namespace', { allowSeparators: true, preserveWhitespace: true })}/upsert`, headers: (params) => ({ 'Api-Key': params.apiKey, 'Content-Type': 'application/x-ndjson', diff --git a/apps/sim/tools/qdrant/fetch_points.ts b/apps/sim/tools/qdrant/fetch_points.ts index 831845f8274..d7de769809b 100644 --- a/apps/sim/tools/qdrant/fetch_points.ts +++ b/apps/sim/tools/qdrant/fetch_points.ts @@ -2,6 +2,7 @@ import type { QdrantFetchParams, QdrantResponse } from '@/tools/qdrant/types' import { POINT_OUTPUT_PROPERTIES, QDRANT_RESPONSE_OUTPUT_PROPERTIES } from '@/tools/qdrant/types' import { QDRANT_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const fetchPointsTool: ToolConfig = { id: 'qdrant_fetch_points', @@ -58,7 +59,7 @@ export const fetchPointsTool: ToolConfig = { request: { method: 'POST', url: (params) => - `${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points`, + `${params.url.replace(/\/$/, '')}/collections/${safeUrlPathSegment(params.collection, 'collection', { preserveWhitespace: true })}/points`, headers: (params) => ({ 'Content-Type': 'application/json', ...(params.apiKey ? { 'api-key': params.apiKey } : {}), diff --git a/apps/sim/tools/qdrant/search_vector.ts b/apps/sim/tools/qdrant/search_vector.ts index 35a01061e30..9099c151774 100644 --- a/apps/sim/tools/qdrant/search_vector.ts +++ b/apps/sim/tools/qdrant/search_vector.ts @@ -5,6 +5,7 @@ import { } from '@/tools/qdrant/types' import { QDRANT_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const searchVectorTool: ToolConfig = { id: 'qdrant_search_vector', @@ -74,7 +75,7 @@ export const searchVectorTool: ToolConfig = request: { method: 'POST', url: (params) => - `${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points/query`, + `${params.url.replace(/\/$/, '')}/collections/${safeUrlPathSegment(params.collection, 'collection', { preserveWhitespace: true })}/points/query`, headers: (params) => ({ 'Content-Type': 'application/json', ...(params.apiKey ? { 'api-key': params.apiKey } : {}), diff --git a/apps/sim/tools/qdrant/upsert_points.ts b/apps/sim/tools/qdrant/upsert_points.ts index 987fc3131d7..1a5cef231e8 100644 --- a/apps/sim/tools/qdrant/upsert_points.ts +++ b/apps/sim/tools/qdrant/upsert_points.ts @@ -5,6 +5,7 @@ import { } from '@/tools/qdrant/types' import { QDRANT_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' +import { safeUrlPathSegment } from '@/tools/url-path' export const upsertPointsTool: ToolConfig = { id: 'qdrant_upsert_points', @@ -43,7 +44,7 @@ export const upsertPointsTool: ToolConfig = request: { method: 'PUT', url: (params) => - `${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points`, + `${params.url.replace(/\/$/, '')}/collections/${safeUrlPathSegment(params.collection, 'collection', { preserveWhitespace: true })}/points`, headers: (params) => ({ 'Content-Type': 'application/json', ...(params.apiKey ? { 'api-key': params.apiKey } : {}), diff --git a/apps/sim/tools/url-path.test.ts b/apps/sim/tools/url-path.test.ts index 9f81de42b79..92a0ca53530 100644 --- a/apps/sim/tools/url-path.test.ts +++ b/apps/sim/tools/url-path.test.ts @@ -103,6 +103,12 @@ describe('safeUrlPathSegment', () => { expect(safeUrlPathSegment(' users ', 'table')).toBe('users') }) + it.concurrent('keeps surrounding whitespace when asked to preserve it', () => { + expect(safeUrlPathSegment(' doc-1 ', 'id', { preserveWhitespace: true })).toBe('%20doc-1%20') + expect(() => safeUrlPathSegment('..', 'id', { preserveWhitespace: true })).toThrow(/id/) + expect(() => safeUrlPathSegment(' ', 'id', { preserveWhitespace: true })).toThrow(/id/) + }) + it.concurrent('every vector either throws or keeps the exact path shape', () => { for (const value of [...SEGMENT_REJECTED, ...NEUTRALIZED]) { let built: string | null = null diff --git a/apps/sim/tools/url-path.ts b/apps/sim/tools/url-path.ts index 944fe68b487..cc53c978fc3 100644 --- a/apps/sim/tools/url-path.ts +++ b/apps/sim/tools/url-path.ts @@ -168,6 +168,9 @@ function encodeSegment(segment: string, paramName: string): string { * @param options.allowSeparators - Percent-encode `/` and `\` instead of * rejecting them, for opaque ids (such as base64) that may legitimately * contain them. Empty values and dot segments are still rejected. + * @param options.preserveWhitespace - Encode the value as given instead of + * trimming it, for ids where surrounding whitespace is significant (an + * exact-match document id). Blank values and dot segments are still rejected. * @returns The trimmed, percent-encoded segment, safe to interpolate. * @throws If the value is not a string or a usable number, is empty, is a dot * segment, contains a path separator (unless allowed), or cannot be encoded. @@ -175,9 +178,10 @@ function encodeSegment(segment: string, paramName: string): string { export function safeUrlPathSegment( value: string | number | bigint, paramName: string, - options?: { allowSeparators?: boolean } + options?: { allowSeparators?: boolean; preserveWhitespace?: boolean } ): string { - const trimmed = toGuardedString(value, paramName).trim() + const raw = toGuardedString(value, paramName) + const trimmed = raw.trim() if (!trimmed) { throw new Error(`${paramName} is required`) @@ -191,7 +195,7 @@ export function safeUrlPathSegment( throw new Error(`${paramName} cannot contain a path separator`) } - return encodeSegment(trimmed, paramName) + return encodeSegment(options?.preserveWhitespace ? raw : trimmed, paramName) } /** Matches a scheme and authority, which end at the first `/`, `\`, `?`, or `#` in a special-scheme URL. */ diff --git a/apps/sim/tools/zep/add_messages.ts b/apps/sim/tools/zep/add_messages.ts index 7fa41057c1d..047fddc8f78 100644 --- a/apps/sim/tools/zep/add_messages.ts +++ b/apps/sim/tools/zep/add_messages.ts @@ -102,7 +102,10 @@ export const zepAddMessagesTool: ToolConfig = }, }, url: (params) => - `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}/messages`, + `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { + allowSeparators: true, + preserveWhitespace: true, + })}/messages`, method: 'POST', headers: (params) => ({ Authorization: `Api-Key ${params.apiKey}`, diff --git a/apps/sim/tools/zep/delete_thread.ts b/apps/sim/tools/zep/delete_thread.ts index 11a71b97aed..9e20095ccb3 100644 --- a/apps/sim/tools/zep/delete_thread.ts +++ b/apps/sim/tools/zep/delete_thread.ts @@ -27,7 +27,10 @@ export const zepDeleteThreadTool: ToolConfig = { request: { url: (params) => - `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}`, + `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { + allowSeparators: true, + preserveWhitespace: true, + })}`, method: 'DELETE', headers: (params) => ({ Authorization: `Api-Key ${params.apiKey}`, diff --git a/apps/sim/tools/zep/get_context.ts b/apps/sim/tools/zep/get_context.ts index 86a61089c93..5a617f66b98 100644 --- a/apps/sim/tools/zep/get_context.ts +++ b/apps/sim/tools/zep/get_context.ts @@ -45,7 +45,14 @@ export const zepGetContextTool: ToolConfig = { queryParams.append('mode', mode) if (params.minRating !== undefined) queryParams.append('minRating', String(Number(params.minRating))) - return `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}/context?${queryParams.toString()}` + return `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment( + params.threadId, + 'threadId', + { + allowSeparators: true, + preserveWhitespace: true, + } + )}/context?${queryParams.toString()}` }, method: 'GET', headers: (params) => ({ diff --git a/apps/sim/tools/zep/get_messages.ts b/apps/sim/tools/zep/get_messages.ts index 663b78fb768..26b9af44606 100644 --- a/apps/sim/tools/zep/get_messages.ts +++ b/apps/sim/tools/zep/get_messages.ts @@ -52,7 +52,14 @@ export const zepGetMessagesTool: ToolConfig = { if (params.lastn) queryParams.append('lastn', String(Number(params.lastn))) const queryString = queryParams.toString() - return `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment(params.threadId, 'threadId', { allowSeparators: true })}/messages${queryString ? `?${queryString}` : ''}` + return `https://api.getzep.com/api/v2/threads/${safeUrlPathSegment( + params.threadId, + 'threadId', + { + allowSeparators: true, + preserveWhitespace: true, + } + )}/messages${queryString ? `?${queryString}` : ''}` }, method: 'GET', headers: (params) => ({ diff --git a/apps/sim/tools/zep/get_user.ts b/apps/sim/tools/zep/get_user.ts index 4f306bbff42..b3f6e20adb6 100644 --- a/apps/sim/tools/zep/get_user.ts +++ b/apps/sim/tools/zep/get_user.ts @@ -28,7 +28,10 @@ export const zepGetUserTool: ToolConfig = { request: { url: (params) => - `https://api.getzep.com/api/v2/users/${safeUrlPathSegment(params.userId, 'userId', { allowSeparators: true })}`, + `https://api.getzep.com/api/v2/users/${safeUrlPathSegment(params.userId, 'userId', { + allowSeparators: true, + preserveWhitespace: true, + })}`, method: 'GET', headers: (params) => ({ Authorization: `Api-Key ${params.apiKey}`, diff --git a/apps/sim/tools/zep/get_user_threads.ts b/apps/sim/tools/zep/get_user_threads.ts index 083c4328e2b..138da91306b 100644 --- a/apps/sim/tools/zep/get_user_threads.ts +++ b/apps/sim/tools/zep/get_user_threads.ts @@ -36,7 +36,10 @@ export const zepGetUserThreadsTool: ToolConfig = { request: { url: (params) => { const limit = Number(params.limit || 10) - return `https://api.getzep.com/api/v2/users/${safeUrlPathSegment(params.userId, 'userId', { allowSeparators: true })}/threads?limit=${limit}` + return `https://api.getzep.com/api/v2/users/${safeUrlPathSegment(params.userId, 'userId', { + allowSeparators: true, + preserveWhitespace: true, + })}/threads?limit=${limit}` }, method: 'GET', headers: (params) => ({