Skip to content

Commit 526b85e

Browse files
committed
fix(knowledge): preserve credential access guidance
1 parent ff561ec commit 526b85e

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

apps/sim/lib/copilot/tools/server/knowledge/knowledge-base.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,33 @@ describe('knowledge_base trusted application delegation', () => {
631631
})
632632
})
633633

634+
it('preserves credential access guidance for connector creation', async () => {
635+
mockCreateKnowledgeConnector.mockRejectedValueOnce(
636+
new OrchestrationError(
637+
'validation',
638+
'Credential is not available to you in this workspace. Ask a credential administrator to grant access or select another credential.'
639+
)
640+
)
641+
642+
const result = await knowledgeBaseServerTool.execute(
643+
{
644+
operation: 'add_connector',
645+
args: {
646+
knowledgeBaseId: KNOWLEDGE_BASE.id,
647+
connectorType: 'notion',
648+
credentialId: 'credential-1',
649+
},
650+
},
651+
CONTEXT
652+
)
653+
654+
expect(result).toEqual({
655+
success: false,
656+
message:
657+
'Credential is not available to you in this workspace. Ask a credential administrator to grant access or select another credential.',
658+
})
659+
})
660+
634661
it('preserves caller-actionable tag provenance conflicts', async () => {
635662
mockDeleteKnowledgeTag.mockRejectedValueOnce(
636663
new OrchestrationError(

apps/sim/lib/knowledge/application/connectors.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ describe('knowledge connector application use cases', () => {
363363
resolveBillingAttribution: mocks.resolveBilling,
364364
},
365365
})
366-
).rejects.toMatchObject({ code: 'validation' })
366+
).rejects.toMatchObject({
367+
code: 'validation',
368+
message:
369+
'Credential is not available to you in this workspace. Ask a credential administrator to grant access or select another credential.',
370+
})
367371

368372
expect(mocks.getCredentialActorContext).toHaveBeenCalledWith('credential-1', 'shared-user')
369373
expect(mocks.resolveTokenIdentity).not.toHaveBeenCalled()
@@ -423,9 +427,10 @@ describe('knowledge connector application use cases', () => {
423427
},
424428
{ space: 'ENG' }
425429
)
426-
).resolves.toEqual({
427-
message: 'Credential is no longer usable in this workspace. Please reconnect it.',
428-
errorCode: 'validation',
430+
).rejects.toMatchObject({
431+
code: 'validation',
432+
message:
433+
'Credential is not available to you in this workspace. Ask a credential administrator to grant access or select another credential.',
429434
})
430435
expect(mocks.resolveTokenIdentity).not.toHaveBeenCalled()
431436
expect(mocks.refreshToken).not.toHaveBeenCalled()

apps/sim/lib/knowledge/application/connectors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ async function resolveAuthorizedConnectorCredentialIdentity(input: {
131131
access.credential.workspaceId !== input.workspaceId ||
132132
!canUseCredential(access)
133133
) {
134-
return null
134+
throw new OrchestrationError(
135+
'validation',
136+
'Credential is not available to you in this workspace. Ask a credential administrator to grant access or select another credential.'
137+
)
135138
}
136139
return resolveCredentialTokenIdentity(input.credentialId, input.workspaceId)
137140
}

0 commit comments

Comments
 (0)