Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
executeCopilotWorkflowUseCase,
messageForCopilotWorkflowError,
} from '@/lib/copilot/application/execute-workflow-use-case'
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
import { OrchestrationError } from '@/lib/core/orchestration/types'
import { workflowOperations } from '@/lib/workflows/application/operations'

Expand Down Expand Up @@ -57,7 +58,7 @@ describe('Copilot Workflow application adapter', () => {
delegationId: 'copilot-tool:tool-call-1',
audience: 'sim:workflows',
issuedAt: new Date('2026-01-01T00:00:00Z'),
expiresAt: new Date('2026-01-01T00:05:00Z'),
expiresAt: new Date(Date.now() + ORCHESTRATION_TIMEOUT_MS),
resourceScope: { chatId: 'chat-1', executionId: 'execution-1' },
},
input: { workflowId: 'workflow-1', assertedWorkspaceId: 'workspace-1' },
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/lib/copilot/auth/application-delegation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { DelegatedPrincipal } from '@sim/auth/principal'
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'

export const COPILOT_APPLICATION_DELEGATION_TTL_MS = 5 * 60 * 1000
/** Keeps delegated authority valid for the full bounded Copilot orchestration lifetime. */
export const COPILOT_APPLICATION_DELEGATION_TTL_MS = ORCHESTRATION_TIMEOUT_MS

export interface CopilotExecutionContext {
userId?: string
Expand Down
7 changes: 5 additions & 2 deletions apps/sim/lib/copilot/auth/file-delegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
messageForCopilotFileError,
resolveCopilotFilePrincipal,
} from '@/lib/copilot/auth/file-delegation'
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
import { OrchestrationError } from '@/lib/core/orchestration/types'

const trustedContext = {
Expand All @@ -20,7 +21,7 @@ const trustedContext = {
}

describe('Copilot file delegation', () => {
it('creates a short-lived principal scoped to the trusted workspace and file', () => {
it('creates an orchestration-bounded principal scoped to the trusted workspace and file', () => {
const principal = resolveCopilotFilePrincipal(trustedContext, 'file-1')

expect(principal).toMatchObject({
Expand All @@ -36,7 +37,9 @@ describe('Copilot file delegation', () => {
executionId: 'execution-1',
},
})
expect(principal.expiresAt.getTime()).toBeGreaterThan(principal.issuedAt.getTime())
expect(principal.expiresAt.getTime() - principal.issuedAt.getTime()).toBe(
ORCHESTRATION_TIMEOUT_MS
)
})

it('creates a workspace-scoped principal for file creation', () => {
Expand Down
Loading