Skip to content
Open
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
7 changes: 6 additions & 1 deletion apps/mesh/src/storage/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@ export interface ProjectStoragePort {

export interface ProjectPluginConfigStoragePort {
list(projectId: string): Promise<ProjectPluginConfig[]>;
get(projectId: string, pluginId: string): Promise<ProjectPluginConfig | null>;
get(
projectId: string,
pluginId: string,
organizationId: string,
): Promise<ProjectPluginConfig | null>;
upsert(
projectId: string,
pluginId: string,
data: {
connectionId?: string | null;
settings?: Record<string, unknown> | null;
},
organizationId: string,
): Promise<ProjectPluginConfig>;
delete(projectId: string, pluginId: string): Promise<boolean>;
}
Expand Down
21 changes: 13 additions & 8 deletions apps/mesh/src/storage/project-plugin-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ export class ProjectPluginConfigsStorage
async get(
projectId: string,
pluginId: string,
organizationId: string,
): Promise<ProjectPluginConfig | null> {
const row = await this.db
let query = this.db
.selectFrom("project_plugin_configs")
.selectAll()
.where("project_id", "=", projectId)
.where("plugin_id", "=", pluginId)
.executeTakeFirst();
.selectAll("project_plugin_configs")
.where("project_plugin_configs.project_id", "=", projectId)
.where("project_plugin_configs.plugin_id", "=", pluginId)
.innerJoin("projects", "projects.id", "project_plugin_configs.project_id")
.where("projects.organization_id", "=", organizationId);

const row = await query.executeTakeFirst();
return row ? this.parseRow(row) : null;
}

Expand All @@ -77,9 +81,10 @@ export class ProjectPluginConfigsStorage
connectionId?: string | null;
settings?: Record<string, unknown> | null;
},
organizationId: string,
): Promise<ProjectPluginConfig> {
const now = new Date().toISOString();
const existing = await this.get(projectId, pluginId);
const existing = await this.get(projectId, pluginId, organizationId);

if (existing) {
const updateData: Record<string, unknown> = { updated_at: now };
Expand All @@ -98,7 +103,7 @@ export class ProjectPluginConfigsStorage
.where("plugin_id", "=", pluginId)
.execute();

const updated = await this.get(projectId, pluginId);
const updated = await this.get(projectId, pluginId, organizationId);
if (!updated) {
throw new Error("Failed to update project plugin config");
}
Expand All @@ -119,7 +124,7 @@ export class ProjectPluginConfigsStorage
})
.execute();

const created = await this.get(projectId, pluginId);
const created = await this.get(projectId, pluginId, organizationId);
if (!created) {
throw new Error("Failed to create project plugin config");
}
Expand Down
3 changes: 1 addition & 2 deletions apps/mesh/src/tools/projects/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const PROJECT_GET = defineTool({
},
inputSchema: z
.object({
organizationId: z.string().describe("Organization ID"),
projectId: z
.string()
.optional()
Expand Down Expand Up @@ -52,7 +51,7 @@ export const PROJECT_GET = defineTool({
project = await ctx.storage.projects.get(input.projectId);
} else if (input.slug) {
project = await ctx.storage.projects.getBySlug(
input.organizationId,
ctx.organization!.id,
input.slug,
);
}
Expand Down
9 changes: 9 additions & 0 deletions apps/mesh/src/tools/projects/plugin-config-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ export const PROJECT_PLUGIN_CONFIG_GET = defineTool({

const { projectId, pluginId } = input;

let organizationId = null;

if (ctx.organization?.id) {
organizationId = ctx.organization.id;
} else {
throw new Error("Organization context is required");
}

const config = await ctx.storage.projectPluginConfigs.get(
projectId,
pluginId,
organizationId,
);

if (!config) {
Expand Down
9 changes: 9 additions & 0 deletions apps/mesh/src/tools/projects/plugin-config-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export const PROJECT_PLUGIN_CONFIG_UPDATE = defineTool({
throw new Error(`Project not found: ${projectId}`);
}

let organizationId = null;

if (ctx.organization?.id) {
organizationId = ctx.organization.id;
} else {
throw new Error("Organization context is required");
}

const connectionExists = connectionId
? await ctx.storage.connections.findById(connectionId)
: null;
Expand Down Expand Up @@ -92,6 +100,7 @@ export const PROJECT_PLUGIN_CONFIG_UPDATE = defineTool({
connectionId,
settings,
},
organizationId,
);

return {
Expand Down