Skip to content

Commit f5640b2

Browse files
committed
regen migrations, ack PR comments
1 parent b0d9f4e commit f5640b2

File tree

9 files changed

+71
-47
lines changed

9 files changed

+71
-47
lines changed

apps/sim/app/api/knowledge/[id]/connectors/route.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
117117
}
118118

119119
let finalSourceConfig: Record<string, unknown> = sourceConfig
120+
const tagSlotMapping: Record<string, string> = {}
121+
120122
if (connectorConfig.tagDefinitions?.length) {
121123
const disabledIds = new Set((sourceConfig.disabledTagIds as string[] | undefined) ?? [])
122124
const enabledDefs = connectorConfig.tagDefinitions.filter((td) => !disabledIds.has(td.id))
123125

124-
const tagSlotMapping: Record<string, string> = {}
125126
const skippedTags: string[] = []
126127
for (const td of enabledDefs) {
127128
const slot = await getNextAvailableSlot(knowledgeBaseId, td.fieldType)
@@ -130,15 +131,6 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
130131
logger.warn(`[${requestId}] No available ${td.fieldType} slots for "${td.displayName}"`)
131132
continue
132133
}
133-
await createTagDefinition(
134-
{
135-
knowledgeBaseId,
136-
tagSlot: slot,
137-
displayName: td.displayName,
138-
fieldType: td.fieldType,
139-
},
140-
requestId
141-
)
142134
tagSlotMapping[td.id] = slot
143135
}
144136

@@ -157,17 +149,33 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
157149
const nextSyncAt =
158150
syncIntervalMinutes > 0 ? new Date(now.getTime() + syncIntervalMinutes * 60 * 1000) : null
159151

160-
await db.insert(knowledgeConnector).values({
161-
id: connectorId,
162-
knowledgeBaseId,
163-
connectorType,
164-
credentialId,
165-
sourceConfig: finalSourceConfig,
166-
syncIntervalMinutes,
167-
status: 'active',
168-
nextSyncAt,
169-
createdAt: now,
170-
updatedAt: now,
152+
await db.transaction(async (tx) => {
153+
for (const [semanticId, slot] of Object.entries(tagSlotMapping)) {
154+
const td = connectorConfig.tagDefinitions!.find((d) => d.id === semanticId)!
155+
await createTagDefinition(
156+
{
157+
knowledgeBaseId,
158+
tagSlot: slot,
159+
displayName: td.displayName,
160+
fieldType: td.fieldType,
161+
},
162+
requestId,
163+
tx
164+
)
165+
}
166+
167+
await tx.insert(knowledgeConnector).values({
168+
id: connectorId,
169+
knowledgeBaseId,
170+
connectorType,
171+
credentialId,
172+
sourceConfig: finalSourceConfig,
173+
syncIntervalMinutes,
174+
status: 'active',
175+
nextSyncAt,
176+
createdAt: now,
177+
updatedAt: now,
178+
})
171179
})
172180

173181
logger.info(`[${requestId}] Created connector ${connectorId} for KB ${knowledgeBaseId}`)

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/document.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ export function Document({
745745
setEnabledFilter('all')
746746
setIsFilterPopoverOpen(false)
747747
setSelectedChunks(new Set())
748+
goToPage(1)
748749
}}
749750
>
750751
All
@@ -755,6 +756,7 @@ export function Document({
755756
setEnabledFilter('enabled')
756757
setIsFilterPopoverOpen(false)
757758
setSelectedChunks(new Set())
759+
goToPage(1)
758760
}}
759761
>
760762
Enabled
@@ -765,6 +767,7 @@ export function Document({
765767
setEnabledFilter('disabled')
766768
setIsFilterPopoverOpen(false)
767769
setSelectedChunks(new Set())
770+
goToPage(1)
768771
}}
769772
>
770773
Disabled

apps/sim/connectors/jira/jira.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ const logger = createLogger('JiraConnector')
88

99
const PAGE_SIZE = 50
1010

11-
/**
12-
* Escapes a value for use inside JQL double-quoted strings.
13-
*/
14-
function escapeJql(value: string): string {
15-
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
16-
}
17-
1811
/**
1912
* Computes a SHA-256 hash of the given content.
2013
*/
@@ -147,9 +140,9 @@ export const jiraConnector: ConnectorConfig = {
147140

148141
const cloudId = await getJiraCloudId(domain, accessToken)
149142

150-
let jql = `project = "${escapeJql(projectKey)}" ORDER BY updated DESC`
143+
let jql = `project = ${projectKey} ORDER BY updated DESC`
151144
if (jqlFilter.trim()) {
152-
jql = `project = "${escapeJql(projectKey)}" AND (${jqlFilter.trim()}) ORDER BY updated DESC`
145+
jql = `project = ${projectKey} AND (${jqlFilter.trim()}) ORDER BY updated DESC`
153146
}
154147

155148
const startAt = cursor ? Number(cursor) : 0
@@ -251,19 +244,13 @@ export const jiraConnector: ConnectorConfig = {
251244
return { valid: false, error: 'Max issues must be a positive number' }
252245
}
253246

254-
const jql = sourceConfig.jql as string | undefined
255-
if (jql?.trim()) {
256-
if (/\b(delete|drop|truncate|insert|update|alter|create|grant|revoke)\b/i.test(jql)) {
257-
return { valid: false, error: 'Invalid JQL filter' }
258-
}
259-
}
247+
const jqlFilter = (sourceConfig.jql as string | undefined)?.trim() || ''
260248

261249
try {
262250
const cloudId = await getJiraCloudId(domain, accessToken)
263251

264-
// Verify the project exists by running a minimal search
265252
const params = new URLSearchParams()
266-
params.append('jql', `project = "${escapeJql(projectKey)}"`)
253+
params.append('jql', `project = ${projectKey}`)
267254
params.append('maxResults', '0')
268255

269256
const url = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/search?${params.toString()}`
@@ -287,6 +274,29 @@ export const jiraConnector: ConnectorConfig = {
287274
return { valid: false, error: `Failed to validate: ${response.status} - ${errorText}` }
288275
}
289276

277+
if (jqlFilter) {
278+
const filterParams = new URLSearchParams()
279+
filterParams.append('jql', `project = ${projectKey} AND (${jqlFilter})`)
280+
filterParams.append('maxResults', '0')
281+
282+
const filterUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/search?${filterParams.toString()}`
283+
const filterResponse = await fetchWithRetry(
284+
filterUrl,
285+
{
286+
method: 'GET',
287+
headers: {
288+
Accept: 'application/json',
289+
Authorization: `Bearer ${accessToken}`,
290+
},
291+
},
292+
VALIDATE_RETRY_OPTIONS
293+
)
294+
295+
if (!filterResponse.ok) {
296+
return { valid: false, error: 'Invalid JQL filter. Check syntax and field names.' }
297+
}
298+
}
299+
290300
return { valid: true }
291301
} catch (error) {
292302
const message = error instanceof Error ? error.message : 'Failed to validate configuration'

apps/sim/lib/knowledge/connectors/sync-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export async function executeSync(
275275
}
276276
}
277277

278-
if (options?.fullSync || connector.syncMode === 'incremental') {
278+
if (options?.fullSync || connector.syncMode === 'full') {
279279
for (const existing of existingDocs) {
280280
if (existing.externalId && !seenExternalIds.has(existing.externalId)) {
281281
await db

apps/sim/lib/knowledge/tags/service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from '@sim/db'
33
import { document, embedding, knowledgeBaseTagDefinitions } from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
55
import { and, eq, isNotNull, isNull, sql } from 'drizzle-orm'
6+
import type { DbOrTx } from '@/lib/db/types'
67
import { getSlotsForFieldType, SUPPORTED_FIELD_TYPES } from '@/lib/knowledge/constants'
78
import type { BulkTagDefinitionsData, DocumentTagDefinition } from '@/lib/knowledge/tags/types'
89
import type {
@@ -485,8 +486,10 @@ export async function deleteTagDefinition(
485486
*/
486487
export async function createTagDefinition(
487488
data: CreateTagDefinitionData,
488-
requestId: string
489+
requestId: string,
490+
txDb?: DbOrTx
489491
): Promise<TagDefinition> {
492+
const dbInstance = txDb ?? db
490493
const tagDefinitionId = randomUUID()
491494
const now = new Date()
492495

@@ -500,7 +503,7 @@ export async function createTagDefinition(
500503
updatedAt: now,
501504
}
502505

503-
await db.insert(knowledgeBaseTagDefinitions).values(newDefinition)
506+
await dbInstance.insert(knowledgeBaseTagDefinitions).values(newDefinition)
504507

505508
logger.info(
506509
`[${requestId}] Created tag definition: ${data.displayName} -> ${data.tagSlot} in KB ${data.knowledgeBaseId}`

packages/db/migrations/0155_talented_ben_parker.sql renamed to packages/db/migrations/0155_bitter_maginty.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CREATE TABLE "knowledge_connector" (
44
"connector_type" text NOT NULL,
55
"credential_id" text NOT NULL,
66
"source_config" json NOT NULL,
7-
"sync_mode" text DEFAULT 'incremental' NOT NULL,
7+
"sync_mode" text DEFAULT 'full' NOT NULL,
88
"sync_interval_minutes" integer DEFAULT 1440 NOT NULL,
99
"status" text DEFAULT 'active' NOT NULL,
1010
"last_sync_at" timestamp,

packages/db/migrations/meta/0155_snapshot.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "4209f841-3ebf-469f-ad98-2df8a84766a1",
2+
"id": "0c80d49c-beb2-4792-a9c1-91ce6ef7eb11",
33
"prevId": "49f580f7-7eba-4431-bdf4-61db0e606546",
44
"version": "7",
55
"dialect": "postgresql",
@@ -4292,7 +4292,7 @@
42924292
"type": "text",
42934293
"primaryKey": false,
42944294
"notNull": true,
4295-
"default": "'incremental'"
4295+
"default": "'full'"
42964296
},
42974297
"sync_interval_minutes": {
42984298
"name": "sync_interval_minutes",

packages/db/migrations/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,8 @@
10831083
{
10841084
"idx": 155,
10851085
"version": "7",
1086-
"when": 1771305981173,
1087-
"tag": "0155_talented_ben_parker",
1086+
"when": 1771314071508,
1087+
"tag": "0155_bitter_maginty",
10881088
"breakpoints": true
10891089
}
10901090
]

packages/db/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ export const knowledgeConnector = pgTable(
22702270
connectorType: text('connector_type').notNull(),
22712271
credentialId: text('credential_id').notNull(),
22722272
sourceConfig: json('source_config').notNull(),
2273-
syncMode: text('sync_mode').notNull().default('incremental'),
2273+
syncMode: text('sync_mode').notNull().default('full'),
22742274
syncIntervalMinutes: integer('sync_interval_minutes').notNull().default(1440),
22752275
status: text('status').notNull().default('active'),
22762276
lastSyncAt: timestamp('last_sync_at'),

0 commit comments

Comments
 (0)