Skip to content

Commit 491f9ed

Browse files
committed
fix(kb): fix Linear connector GraphQL type errors and tag slot reuse
1 parent 7971a64 commit 491f9ed

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,37 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
151151
}
152152

153153
const tagSlotMapping: Record<string, string> = {}
154+
const newTagSlotMapping: Record<string, string> = {}
154155

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

159160
const existingDefs = await db
160-
.select({ tagSlot: knowledgeBaseTagDefinitions.tagSlot })
161+
.select({
162+
tagSlot: knowledgeBaseTagDefinitions.tagSlot,
163+
displayName: knowledgeBaseTagDefinitions.displayName,
164+
})
161165
.from(knowledgeBaseTagDefinitions)
162166
.where(eq(knowledgeBaseTagDefinitions.knowledgeBaseId, knowledgeBaseId))
163167

164168
const usedSlots = new Set<string>(existingDefs.map((d) => d.tagSlot))
165-
const { mapping, skipped: skippedTags } = allocateTagSlots(enabledDefs, usedSlots)
169+
const existingByName = new Map(existingDefs.map((d) => [d.displayName, d.tagSlot]))
170+
171+
/** Reuse existing tag definitions that match by display name */
172+
const defsNeedingSlots: typeof enabledDefs = []
173+
for (const td of enabledDefs) {
174+
const existingSlot = existingByName.get(td.displayName)
175+
if (existingSlot) {
176+
tagSlotMapping[td.id] = existingSlot
177+
} else {
178+
defsNeedingSlots.push(td)
179+
}
180+
}
181+
182+
const { mapping, skipped: skippedTags } = allocateTagSlots(defsNeedingSlots, usedSlots)
166183
Object.assign(tagSlotMapping, mapping)
184+
Object.assign(newTagSlotMapping, mapping)
167185

168186
for (const name of skippedTags) {
169187
logger.warn(`[${requestId}] No available slots for "${name}"`)
@@ -197,7 +215,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
197215
throw new Error('Knowledge base not found')
198216
}
199217

200-
for (const [semanticId, slot] of Object.entries(tagSlotMapping)) {
218+
for (const [semanticId, slot] of Object.entries(newTagSlotMapping)) {
201219
const td = connectorConfig.tagDefinitions!.find((d) => d.id === semanticId)!
202220
await createTagDefinition(
203221
{

apps/sim/connectors/linear/linear.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const ISSUE_FIELDS = `
119119
`
120120

121121
const ISSUE_BY_ID_QUERY = `
122-
query GetIssue($id: String!) {
122+
query GetIssue($id: ID!) {
123123
issue(id: $id) {
124124
${ISSUE_FIELDS}
125125
}
@@ -147,13 +147,13 @@ function buildIssuesQuery(sourceConfig: Record<string, unknown>): {
147147
const variables: Record<string, unknown> = {}
148148

149149
if (teamId) {
150-
varDefs.push('$teamId: String!')
150+
varDefs.push('$teamId: ID!')
151151
filterClauses.push('team: { id: { eq: $teamId } }')
152152
variables.teamId = teamId
153153
}
154154

155155
if (projectId) {
156-
varDefs.push('$projectId: String!')
156+
varDefs.push('$projectId: ID!')
157157
filterClauses.push('project: { id: { eq: $projectId } }')
158158
variables.projectId = projectId
159159
}

0 commit comments

Comments
 (0)