Skip to content

Commit ef08ed1

Browse files
committed
fix(integrations): keep exact ids in encoded path segments and require a pinecone search namespace
1 parent 151fdb6 commit ef08ed1

19 files changed

Lines changed: 104 additions & 29 deletions

‎apps/sim/tools/elasticsearch/delete_document.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ export const deleteDocumentTool: ToolConfig<
7878
request: {
7979
url: (params) => {
8080
const baseUrl = buildBaseUrl(params)
81-
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}`
81+
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(
82+
params.documentId,
83+
'documentId',
84+
{
85+
allowSeparators: true,
86+
preserveWhitespace: true,
87+
}
88+
)}`
8289

8390
if (params.refresh) {
8491
url += `?refresh=${params.refresh}`

‎apps/sim/tools/elasticsearch/get_document.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ export const getDocumentTool: ToolConfig<
8383
request: {
8484
url: (params) => {
8585
const baseUrl = buildBaseUrl(params)
86-
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}`
86+
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc/${safeUrlPathSegment(
87+
params.documentId,
88+
'documentId',
89+
{
90+
allowSeparators: true,
91+
preserveWhitespace: true,
92+
}
93+
)}`
8794

8895
const queryParams: string[] = []
8996
if (params.sourceIncludes) {

‎apps/sim/tools/elasticsearch/index_document.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export const indexDocumentTool: ToolConfig<
8585
const baseUrl = buildBaseUrl(params)
8686
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_doc`
8787
if (params.documentId) {
88-
url += `/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}`
88+
url += `/${safeUrlPathSegment(params.documentId, 'documentId', {
89+
allowSeparators: true,
90+
preserveWhitespace: true,
91+
})}`
8992
}
9093
if (params.refresh) {
9194
url += `?refresh=${params.refresh}`

‎apps/sim/tools/elasticsearch/update_document.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ export const updateDocumentTool: ToolConfig<
8383
request: {
8484
url: (params) => {
8585
const baseUrl = buildBaseUrl(params)
86-
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_update/${safeUrlPathSegment(params.documentId, 'documentId', { allowSeparators: true })}`
86+
let url = `${baseUrl}/${safeUrlPathSegment(params.index, 'index')}/_update/${safeUrlPathSegment(
87+
params.documentId,
88+
'documentId',
89+
{
90+
allowSeparators: true,
91+
preserveWhitespace: true,
92+
}
93+
)}`
8794

8895
if (params.retryOnConflict !== undefined) {
8996
url += `?retry_on_conflict=${params.retryOnConflict}`

‎apps/sim/tools/nested-model-input-adapters.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ describe('nested model-input adapters', () => {
374374
apiKey: 'key',
375375
rerank,
376376
searchQuery: patch.searchQuery as string,
377-
}) as { rerank: { query: { text: string } } }
378-
expect(body.rerank.query.text).toBe('{{SEARCH_QUERY}}')
377+
}) as { query: { inputs: { text: string } }; rerank: { query?: string } }
378+
expect(body.query.inputs.text).toBe('{{SEARCH_QUERY}}')
379+
expect(body.rerank.query).toBeUndefined()
379380
})
380381

381382
it('preserves Pinecone singleton and legacy NDJSON input forms', () => {

‎apps/sim/tools/pinecone/requests.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ describe('pinecone_search_text request', () => {
3030
apiKey: 'key',
3131
}
3232

33-
it('searches the default namespace when no namespace is given', () => {
34-
const url = buildUrl<PineconeSearchTextParams>(searchTextTool, baseParams)
35-
36-
expect(url.pathname).toBe('/records/namespaces/__default__/search')
33+
it('rejects a missing namespace instead of searching a namespace named "undefined"', () => {
34+
expect(() => buildUrl<PineconeSearchTextParams>(searchTextTool, baseParams)).toThrow(
35+
/namespace is required/
36+
)
3737
})
3838

3939
it('sends the rerank query as a string', () => {
@@ -52,5 +52,11 @@ describe('pinecone_search_text request', () => {
5252
rerank: { model: 'bge-reranker-v2-m3', query: { text: 'Paris' } },
5353
})
5454
expect(withObjectQuery.rerank.query).toBe('Paris')
55+
56+
const withBlankQuery = body({
57+
...baseParams,
58+
rerank: { model: 'bge-reranker-v2-m3', query: ' ' },
59+
})
60+
expect(withBlankQuery.rerank.query).toBeUndefined()
5561
})
5662
})

‎apps/sim/tools/pinecone/search_text.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
PineconeSearchTextParams,
55
} from '@/tools/pinecone/types'
66
import type { ToolConfig } from '@/tools/types'
7+
import { safeUrlPathSegment } from '@/tools/url-path'
78

89
function parseRerank(
910
value: PineconeSearchTextParams['rerank']
@@ -134,7 +135,7 @@ export const searchTextTool: ToolConfig<PineconeSearchTextParams, PineconeRespon
134135
},
135136
method: 'POST',
136137
url: (params) =>
137-
`${params.indexHost}/records/namespaces/${encodeURIComponent(params.namespace?.trim() || '__default__')}/search`,
138+
`${params.indexHost}/records/namespaces/${safeUrlPathSegment(params.namespace ?? '', 'namespace', { allowSeparators: true, preserveWhitespace: true })}/search`,
138139
headers: (params) => ({
139140
'Api-Key': params.apiKey,
140141
'Content-Type': 'application/json',
@@ -164,12 +165,15 @@ export const searchTextTool: ToolConfig<PineconeSearchTextParams, PineconeRespon
164165
}
165166

166167
if (params.rerank) {
167-
const rerank = parseRerank(params.rerank)
168-
const rerankQuery = rerank?.query
169-
// Pinecone takes `rerank.query` as a string and falls back to the search query when unset.
170-
body.rerank =
168+
const { query: rerankQuery, ...rerank } = parseRerank(params.rerank) ?? {}
169+
const queryText =
171170
rerankQuery !== null && typeof rerankQuery === 'object' && !Array.isArray(rerankQuery)
172-
? { ...rerank, query: (rerankQuery as Record<string, unknown>).text }
171+
? (rerankQuery as Record<string, unknown>).text
172+
: rerankQuery
173+
// Pinecone takes `rerank.query` as a string and reranks against the search query when unset.
174+
body.rerank =
175+
typeof queryText === 'string' && queryText.trim()
176+
? { ...rerank, query: queryText }
173177
: rerank
174178
}
175179

‎apps/sim/tools/pinecone/upsert_text.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
PineconeUpsertTextRecord,
55
} from '@/tools/pinecone/types'
66
import type { ToolConfig } from '@/tools/types'
7+
import { safeUrlPathSegment } from '@/tools/url-path'
78

89
function parseUpsertTextRecords(
910
input: PineconeUpsertTextParams['records']
@@ -91,7 +92,7 @@ export const upsertTextTool: ToolConfig<PineconeUpsertTextParams, PineconeRespon
9192
},
9293
method: 'POST',
9394
url: (params) =>
94-
`${params.indexHost}/records/namespaces/${encodeURIComponent(params.namespace.trim())}/upsert`,
95+
`${params.indexHost}/records/namespaces/${safeUrlPathSegment(params.namespace, 'namespace', { allowSeparators: true, preserveWhitespace: true })}/upsert`,
9596
headers: (params) => ({
9697
'Api-Key': params.apiKey,
9798
'Content-Type': 'application/x-ndjson',

‎apps/sim/tools/qdrant/fetch_points.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { QdrantFetchParams, QdrantResponse } from '@/tools/qdrant/types'
22
import { POINT_OUTPUT_PROPERTIES, QDRANT_RESPONSE_OUTPUT_PROPERTIES } from '@/tools/qdrant/types'
33
import { QDRANT_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
44
import type { ToolConfig } from '@/tools/types'
5+
import { safeUrlPathSegment } from '@/tools/url-path'
56

67
export const fetchPointsTool: ToolConfig<QdrantFetchParams, QdrantResponse> = {
78
id: 'qdrant_fetch_points',
@@ -58,7 +59,7 @@ export const fetchPointsTool: ToolConfig<QdrantFetchParams, QdrantResponse> = {
5859
request: {
5960
method: 'POST',
6061
url: (params) =>
61-
`${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points`,
62+
`${params.url.replace(/\/$/, '')}/collections/${safeUrlPathSegment(params.collection, 'collection', { preserveWhitespace: true })}/points`,
6263
headers: (params) => ({
6364
'Content-Type': 'application/json',
6465
...(params.apiKey ? { 'api-key': params.apiKey } : {}),

‎apps/sim/tools/qdrant/search_vector.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@/tools/qdrant/types'
66
import { QDRANT_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
77
import type { ToolConfig } from '@/tools/types'
8+
import { safeUrlPathSegment } from '@/tools/url-path'
89

910
export const searchVectorTool: ToolConfig<QdrantSearchParams, QdrantResponse> = {
1011
id: 'qdrant_search_vector',
@@ -74,7 +75,7 @@ export const searchVectorTool: ToolConfig<QdrantSearchParams, QdrantResponse> =
7475
request: {
7576
method: 'POST',
7677
url: (params) =>
77-
`${params.url.replace(/\/$/, '')}/collections/${encodeURIComponent(params.collection)}/points/query`,
78+
`${params.url.replace(/\/$/, '')}/collections/${safeUrlPathSegment(params.collection, 'collection', { preserveWhitespace: true })}/points/query`,
7879
headers: (params) => ({
7980
'Content-Type': 'application/json',
8081
...(params.apiKey ? { 'api-key': params.apiKey } : {}),

0 commit comments

Comments
 (0)