Refactor global datasource part 2 (#16399)

## Context
Deprecating TwentyORMManager in favor of TwentyORMGlobalManager
(temporarily, as this will simplify the ultimate goal to later replace
all usages with the new TwentyORMGlobalManagerV2 which will have a
similar signature)
This means this PR had to refactor a bit of code to pass down the
workspaceId when not available directly as it is now a requirement,
meaning we also deprecated scopedWorkspaceContextFactory to have a less
obscure way to fetch the workspaceId and have something more
declarative.

Step 3 will be to update TwentyORMGlobalManager to use a featureFlag
toggling and use the new GlobalWorkspaceOrmManager internally using the
new cache service

Step 4 will be to remove the feature flag and pg_pool patch
This commit is contained in:
Weiko
2025-12-08 17:05:00 +01:00
committed by GitHub
parent c2d3fbcd21
commit 859004f4fc
101 changed files with 647 additions and 597 deletions
@@ -26,7 +26,8 @@ export class ToolRegistryService {
return {
description: httpTool.description,
inputSchema: httpTool.inputSchema,
execute: (params) => httpTool.execute(params),
execute: (params, workspaceId) =>
httpTool.execute(params, workspaceId),
flag: PermissionFlagType.HTTP_REQUEST_TOOL,
};
},
@@ -36,8 +37,8 @@ export class ToolRegistryService {
() => ({
description: this.sendEmailTool.description,
inputSchema: this.sendEmailTool.inputSchema,
execute: (params) =>
this.sendEmailTool.execute(params as SendEmailInput),
execute: (params, workspaceId) =>
this.sendEmailTool.execute(params as SendEmailInput, workspaceId),
flag: PermissionFlagType.SEND_EMAIL_TOOL,
}),
],
@@ -20,7 +20,10 @@ export class HttpTool implements Tool {
constructor(private readonly twentyConfigService: TwentyConfigService) {}
async execute(parameters: ToolInput): Promise<ToolOutput> {
async execute(
parameters: ToolInput,
_workspaceId: string,
): Promise<ToolOutput> {
const { url, method, headers, body } = parameters as HttpRequestInput;
const headersCopy = { ...headers };
const isMethodForBody = ['POST', 'PUT', 'PATCH'].includes(method);
@@ -18,7 +18,6 @@ import { SendEmailToolParametersZodSchema } from 'src/engine/core-modules/tool/t
import { type SendEmailInput } from 'src/engine/core-modules/tool/tools/send-email-tool/types/send-email-input.type';
import { type ToolOutput } from 'src/engine/core-modules/tool/types/tool-output.type';
import { type Tool } from 'src/engine/core-modules/tool/types/tool.type';
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { type ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessagingSendMessageService } from 'src/modules/messaging/message-import-manager/services/messaging-send-message.service';
@@ -36,7 +35,6 @@ export class SendEmailTool implements Tool {
inputSchema = SendEmailToolParametersZodSchema;
constructor(
private readonly scopedWorkspaceContextFactory: ScopedWorkspaceContextFactory,
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
private readonly sendMessageService: MessagingSendMessageService,
@InjectRepository(FileEntity)
@@ -160,9 +158,10 @@ export class SendEmailTool implements Tool {
return attachments;
}
async execute(parameters: SendEmailInput): Promise<ToolOutput> {
const { workspaceId } = this.scopedWorkspaceContextFactory.create();
async execute(
parameters: SendEmailInput,
workspaceId: string,
): Promise<ToolOutput> {
const { email, subject, body, files } = parameters;
let { connectedAccountId } = parameters;
@@ -180,13 +179,6 @@ export class SendEmailTool implements Tool {
);
}
if (!workspaceId) {
throw new SendEmailToolException(
'Workspace ID not found',
SendEmailToolExceptionCode.WORKSPACE_ID_NOT_FOUND,
);
}
if (!connectedAccountId) {
connectedAccountId =
await this.getOrThrowFirstConnectedAccountId(workspaceId);
@@ -7,6 +7,6 @@ import { type ToolOutput } from 'src/engine/core-modules/tool/types/tool-output.
export type Tool = {
description: string;
inputSchema: FlexibleSchema<unknown>;
execute(input: ToolInput): Promise<ToolOutput>;
execute(input: ToolInput, workspaceId: string): Promise<ToolOutput>;
flag?: PermissionFlagType;
};