Skip to content

Commit fea4067

Browse files
committed
improvement(agent): remove permission mode feature flag
1 parent 82e55e9 commit fea4067

42 files changed

Lines changed: 122 additions & 1241 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/realtime/src/database/agent-tool-permissions.test.ts

Lines changed: 0 additions & 113 deletions
This file was deleted.

apps/realtime/src/database/operations.test.ts

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/** @vitest-environment node */
22
import {
33
BLOCK_OPERATIONS,
4-
BLOCKS_OPERATIONS,
54
OPERATION_TARGETS,
65
SUBBLOCK_OPERATIONS,
7-
WORKFLOW_OPERATIONS,
86
} from '@sim/realtime-protocol/constants'
97
import { beforeEach, describe, expect, it, vi } from 'vitest'
108

@@ -46,21 +44,10 @@ vi.mock('drizzle-orm/postgres-js', () => ({ drizzle: () => ({ transaction: mockT
4644
vi.mock('postgres', () => ({ default: vi.fn() }))
4745
vi.mock('@/env', () => ({
4846
env: { DATABASE_URL: 'postgres://localhost/test' },
49-
getInternalApiBaseUrl: () => 'http://localhost:3000',
5047
}))
5148

52-
import { mergeSubBlockValues } from '@sim/workflow-persistence/subblocks'
53-
import { afterEach } from 'vitest'
5449
import { persistWorkflowOperation } from '@/database/operations'
5550

56-
const mockFetch = vi.fn()
57-
beforeEach(() => {
58-
vi.stubGlobal('fetch', mockFetch)
59-
mockFetch.mockReset()
60-
mockFetch.mockImplementation(async () => Response.json({ agentToolPermissionModeEnabled: true }))
61-
})
62-
afterEach(() => vi.unstubAllGlobals())
63-
6451
const transaction = {
6552
select: () => ({ from: () => ({ where: mockSelectWhere }) }),
6653
update: () => ({ set: mockSet }),
@@ -141,7 +128,7 @@ describe('search replacement persistence', () => {
141128
})
142129
})
143130

144-
describe('variable permissions at every realtime transaction write boundary', () => {
131+
describe('atomic tool reordering', () => {
145132
const block = {
146133
id: 'agent-1',
147134
type: 'agent',
@@ -170,53 +157,9 @@ describe('variable permissions at every realtime transaction write boundary', ()
170157
}
171158
)
172159
)
173-
mockFetch.mockImplementation(async () =>
174-
Response.json({ agentToolPermissionModeEnabled: false })
175-
)
176-
})
177-
178-
it.each([
179-
{
180-
operation: WORKFLOW_OPERATIONS.REPLACE_STATE,
181-
target: OPERATION_TARGETS.WORKFLOW,
182-
payload: { state: { blocks: { 'agent-1': block } } },
183-
},
184-
{
185-
operation: BLOCK_OPERATIONS.UPDATE_CANONICAL_MODE,
186-
target: OPERATION_TARGETS.BLOCK,
187-
payload: { id: 'agent-1', canonicalId: '0:agentToolUsageControl', canonicalMode: 'advanced' },
188-
},
189-
{
190-
operation: BLOCK_OPERATIONS.REPLACE_CANONICAL_MODES,
191-
target: OPERATION_TARGETS.BLOCK,
192-
payload: {
193-
id: 'agent-1',
194-
data: { canonicalModes: { '0:agentToolUsageControl': 'advanced' } },
195-
},
196-
},
197-
{
198-
operation: BLOCKS_OPERATIONS.BATCH_ADD_BLOCKS,
199-
target: OPERATION_TARGETS.BLOCKS,
200-
payload: { blocks: [block] },
201-
},
202-
{
203-
operation: SUBBLOCK_OPERATIONS.BATCH_UPDATE,
204-
target: OPERATION_TARGETS.SUBBLOCK,
205-
payload: {
206-
updates: [{ blockId: 'agent-1', subblockId: 'tools', value: block.subBlocks.tools.value }],
207-
},
208-
},
209-
])('refuses $operation before changing any block rows', async (operation) => {
210-
vi.mocked(mergeSubBlockValues).mockReturnValue(block.subBlocks)
211-
await expect(
212-
persistWorkflowOperation('workflow-1', { ...operation, timestamp: Date.now() })
213-
).rejects.toThrow('disabled')
214-
expect(mockSet).toHaveBeenCalledTimes(1)
215-
expect(transaction.delete).not.toHaveBeenCalled()
216-
expect(transaction.insert).not.toHaveBeenCalled()
217160
})
218161

219-
it('persists a reordered tool array and its mode map in one write while the flag is off', async () => {
162+
it('persists a reordered tool array and its mode map in one write', async () => {
220163
const first = { type: 'function', usageControlExpression: 'auto' }
221164
const second = { type: 'function', usageControlExpression: 'force' }
222165
const original = {
@@ -239,7 +182,6 @@ describe('variable permissions at every realtime transaction write boundary', ()
239182
payload: { id: block.id, subBlocks, data: { canonicalModes } },
240183
})
241184
).resolves.toBeUndefined()
242-
expect(mockFetch).not.toHaveBeenCalled()
243185
expect(mockSet).toHaveBeenLastCalledWith(
244186
expect.objectContaining({ subBlocks, data: { canonicalModes } })
245187
)

apps/realtime/src/database/operations.ts

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
import { and, eq, inArray, isNull, or, sql } from 'drizzle-orm'
4141
import { drizzle } from 'drizzle-orm/postgres-js'
4242
import postgres from 'postgres'
43-
import { assertAgentToolPermissionModeEnabled } from '@/database/workflow-authoring'
4443
import { env } from '@/env'
4544

4645
const logger = createLogger('SocketDatabase')
@@ -782,12 +781,7 @@ async function handleBlockOperationTx(
782781
}
783782

784783
const existingBlock = await tx
785-
.select({
786-
id: workflowBlocks.id,
787-
type: workflowBlocks.type,
788-
subBlocks: workflowBlocks.subBlocks,
789-
data: workflowBlocks.data,
790-
})
784+
.select({ data: workflowBlocks.data })
791785
.from(workflowBlocks)
792786
.where(and(eq(workflowBlocks.id, payload.id), eq(workflowBlocks.workflowId, workflowId)))
793787
.limit(1)
@@ -799,18 +793,6 @@ async function handleBlockOperationTx(
799793
[payload.canonicalId]: payload.canonicalMode,
800794
}
801795

802-
if (existingBlock[0]) {
803-
await assertAgentToolPermissionModeEnabled(
804-
[
805-
{
806-
...existingBlock[0],
807-
data: { ...currentData, canonicalModes },
808-
},
809-
],
810-
existingBlock
811-
)
812-
}
813-
814796
const updateResult = await tx
815797
.update(workflowBlocks)
816798
.set({
@@ -842,7 +824,6 @@ async function handleBlockOperationTx(
842824
.select({
843825
id: workflowBlocks.id,
844826
locked: workflowBlocks.locked,
845-
type: workflowBlocks.type,
846827
subBlocks: workflowBlocks.subBlocks,
847828
data: workflowBlocks.data,
848829
})
@@ -863,19 +844,6 @@ async function handleBlockOperationTx(
863844

864845
const subBlocks = { ...(existingBlock[0]?.subBlocks || {}), ...(payload.subBlocks || {}) }
865846

866-
if (existingBlock[0]) {
867-
await assertAgentToolPermissionModeEnabled(
868-
[
869-
{
870-
...existingBlock[0],
871-
subBlocks,
872-
data: { ...currentData, canonicalModes: payload.data.canonicalModes },
873-
},
874-
],
875-
existingBlock
876-
)
877-
}
878-
879847
const updateResult = await tx
880848
.update(workflowBlocks)
881849
.set({
@@ -968,13 +936,7 @@ async function handleBlocksOperationTx(
968936
if (blocks && blocks.length > 0) {
969937
// Fetch existing blocks to check for locked parents
970938
const existingBlocks = await tx
971-
.select({
972-
id: workflowBlocks.id,
973-
type: workflowBlocks.type,
974-
subBlocks: workflowBlocks.subBlocks,
975-
data: workflowBlocks.data,
976-
locked: workflowBlocks.locked,
977-
})
939+
.select({ id: workflowBlocks.id, locked: workflowBlocks.locked })
978940
.from(workflowBlocks)
979941
.where(eq(workflowBlocks.workflowId, workflowId))
980942

@@ -1030,8 +992,6 @@ async function handleBlocksOperationTx(
1030992
}
1031993
})
1032994

1033-
await assertAgentToolPermissionModeEnabled(blockValues, existingBlocks)
1034-
1035995
await tx
1036996
.insert(workflowBlocks)
1037997
.values(blockValues)
@@ -2063,7 +2023,6 @@ async function handleSubblockOperationTx(
20632023
const allBlocks = await tx
20642024
.select({
20652025
id: workflowBlocks.id,
2066-
type: workflowBlocks.type,
20672026
subBlocks: workflowBlocks.subBlocks,
20682027
locked: workflowBlocks.locked,
20692028
data: workflowBlocks.data,
@@ -2103,10 +2062,6 @@ async function handleSubblockOperationTx(
21032062
? { ...currentSubBlock, value }
21042063
: { id: subblockId, type: 'unknown', value }
21052064

2106-
if (subblockId === 'tools') {
2107-
await assertAgentToolPermissionModeEnabled([{ ...block, subBlocks }], [block])
2108-
}
2109-
21102065
await tx
21112066
.update(workflowBlocks)
21122067
.set({
@@ -2218,16 +2173,6 @@ async function handleWorkflowOperationTx(
22182173
}
22192174

22202175
const { blocks, edges, loops, parallels } = payload.state
2221-
const previousBlocks = await tx
2222-
.select({
2223-
id: workflowBlocks.id,
2224-
type: workflowBlocks.type,
2225-
subBlocks: workflowBlocks.subBlocks,
2226-
data: workflowBlocks.data,
2227-
})
2228-
.from(workflowBlocks)
2229-
.where(eq(workflowBlocks.workflowId, workflowId))
2230-
await assertAgentToolPermissionModeEnabled(Object.values(blocks || {}), previousBlocks)
22312176

22322177
logger.info(`Replacing workflow state for ${workflowId}`, {
22332178
blockCount: Object.keys(blocks || {}).length,

0 commit comments

Comments
 (0)