Skip to content

Commit eb7ca3e

Browse files
refactor(knowledge): compose copilot batch commands
1 parent 79c5879 commit eb7ca3e

14 files changed

Lines changed: 1380 additions & 345 deletions

apps/sim/lib/copilot/application/execute-knowledge-use-case.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ const registeredKnowledgeOperationIds = new Set<string>(
2121
Object.values(knowledgeOperations).map((operation) => operation.id)
2222
)
2323

24-
/** Normalizes immutable Copilot execution identity into a knowledge delegation. */
25-
export function resolveCopilotKnowledgePrincipal(
24+
type TrustedCopilotKnowledgeDelegationContext = CopilotKnowledgeDelegationContext & {
25+
workspaceId: string
26+
toolCallId: string
27+
copilotToolExecution: true
28+
}
29+
30+
function requireTrustedCopilotKnowledgeContext(
2631
context: CopilotKnowledgeDelegationContext | undefined
27-
): DelegatedPrincipal {
32+
): TrustedCopilotKnowledgeDelegationContext {
2833
if (!context) throw new Error('Knowledge delegation requires a Copilot execution context')
2934
if (!context.copilotToolExecution) {
3035
throw new Error('Knowledge delegation requires a trusted Copilot execution context')
@@ -33,7 +38,23 @@ export function resolveCopilotKnowledgePrincipal(
3338
if (!context.workspaceId) throw new Error('Knowledge delegation requires a workspace ID')
3439
if (!context.toolCallId) throw new Error('Knowledge delegation requires a tool call ID')
3540

36-
return createCopilotWorkspacePrincipal(context, {
41+
return context as TrustedCopilotKnowledgeDelegationContext
42+
}
43+
44+
/** Requires the immutable trusted workspace bound to a Copilot Knowledge execution. */
45+
export function requireCopilotKnowledgeWorkspaceId(
46+
context: CopilotKnowledgeDelegationContext | undefined
47+
): string {
48+
return requireTrustedCopilotKnowledgeContext(context).workspaceId
49+
}
50+
51+
/** Normalizes immutable Copilot execution identity into a knowledge delegation. */
52+
export function resolveCopilotKnowledgePrincipal(
53+
context: CopilotKnowledgeDelegationContext | undefined
54+
): DelegatedPrincipal {
55+
const trustedContext = requireTrustedCopilotKnowledgeContext(context)
56+
57+
return createCopilotWorkspacePrincipal(trustedContext, {
3758
audience: KNOWLEDGE_DELEGATION_AUDIENCE,
3859
})
3960
}

0 commit comments

Comments
 (0)