Skip to content
Prev Previous commit
Next Next commit
fix(kb): fix Linear connector GraphQL type errors and tag slot reuse
  • Loading branch information
waleedlatif1 committed Apr 3, 2026
commit e12f15f5a7f5e31e6f34b07bc41ee85bbe3381bd
24 changes: 21 additions & 3 deletions apps/sim/app/api/knowledge/[id]/connectors/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,37 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
}

const tagSlotMapping: Record<string, string> = {}
const newTagSlotMapping: Record<string, string> = {}

if (connectorConfig.tagDefinitions?.length) {
const disabledIds = new Set((sourceConfig.disabledTagIds as string[] | undefined) ?? [])
const enabledDefs = connectorConfig.tagDefinitions.filter((td) => !disabledIds.has(td.id))

const existingDefs = await db
.select({ tagSlot: knowledgeBaseTagDefinitions.tagSlot })
.select({
tagSlot: knowledgeBaseTagDefinitions.tagSlot,
displayName: knowledgeBaseTagDefinitions.displayName,
})
.from(knowledgeBaseTagDefinitions)
.where(eq(knowledgeBaseTagDefinitions.knowledgeBaseId, knowledgeBaseId))

const usedSlots = new Set<string>(existingDefs.map((d) => d.tagSlot))
const { mapping, skipped: skippedTags } = allocateTagSlots(enabledDefs, usedSlots)
const existingByName = new Map(existingDefs.map((d) => [d.displayName, d.tagSlot]))

/** Reuse existing tag definitions that match by display name */
const defsNeedingSlots: typeof enabledDefs = []
for (const td of enabledDefs) {
const existingSlot = existingByName.get(td.displayName)
if (existingSlot) {
tagSlotMapping[td.id] = existingSlot
} else {
defsNeedingSlots.push(td)
}
}

const { mapping, skipped: skippedTags } = allocateTagSlots(defsNeedingSlots, usedSlots)
Object.assign(tagSlotMapping, mapping)
Object.assign(newTagSlotMapping, mapping)

for (const name of skippedTags) {
logger.warn(`[${requestId}] No available slots for "${name}"`)
Expand Down Expand Up @@ -208,7 +226,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
throw new Error('Knowledge base not found')
}

for (const [semanticId, slot] of Object.entries(tagSlotMapping)) {
for (const [semanticId, slot] of Object.entries(newTagSlotMapping)) {
const td = connectorConfig.tagDefinitions!.find((d) => d.id === semanticId)!
await createTagDefinition(
{
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/connectors/linear/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const ISSUE_FIELDS = `
`

const ISSUE_BY_ID_QUERY = `
query GetIssue($id: String!) {
query GetIssue($id: ID!) {
issue(id: $id) {
${ISSUE_FIELDS}
}
Expand Down Expand Up @@ -147,13 +147,13 @@ function buildIssuesQuery(sourceConfig: Record<string, unknown>): {
const variables: Record<string, unknown> = {}

if (teamId) {
varDefs.push('$teamId: String!')
varDefs.push('$teamId: ID!')
filterClauses.push('team: { id: { eq: $teamId } }')
variables.teamId = teamId
}

if (projectId) {
varDefs.push('$projectId: String!')
varDefs.push('$projectId: ID!')
filterClauses.push('project: { id: { eq: $projectId } }')
variables.projectId = projectId
}
Expand Down
Loading