FEAT - TASKER: управление Codex Agent API через Gateway proxy

This commit is contained in:
DCCONSTRUCTIONS
2026-05-14 21:11:45 +03:00
parent 97566faba3
commit 3b8e0ea594
9 changed files with 728 additions and 1 deletions
@@ -0,0 +1,128 @@
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
import { API_BASE_URL } from "@plane/constants";
import { APIService } from "@/services/api.service";
export type TCodexAgentStatus = "active" | "disabled" | "revoked";
export type TCodexAgentGrantMode = "voluntary" | "reporting";
export type TCodexAgentTokenStatus = "active" | "revoked" | "expired";
export type TCodexAgent = {
id: string;
owner_user_id: string;
owner_email: string | null;
display_name: string;
avatar_url: string | null;
status: TCodexAgentStatus;
created_at: string;
updated_at: string;
};
export type TCodexAgentGrant = {
id: string;
agent_id: string;
workspace_slug: string;
project_id: string | null;
scopes: string[];
mode: TCodexAgentGrantMode;
created_by_user_id: string;
created_at: string;
updated_at: string;
};
export type TCodexAgentToken = {
id: string;
agent_id: string;
name: string;
status: TCodexAgentTokenStatus;
expires_at: string | null;
last_used_at: string | null;
created_at: string;
};
export type TCodexAgentSetupPacket = {
agents_md?: string;
codex_config_template?: Record<string, unknown>;
mcp_server?: {
name: string;
url: string;
headers: Record<string, string>;
};
};
export type TCodexAgentListResponse = {
ok: boolean;
agents: TCodexAgent[];
};
export type TCodexAgentCreateTokenResponse = {
ok: boolean;
setup?: TCodexAgentSetupPacket;
token: string;
token_record: TCodexAgentToken;
};
export class WorkspaceCodexAgentService extends APIService {
constructor() {
super(API_BASE_URL);
}
async listAgents(workspaceSlug: string): Promise<TCodexAgentListResponse> {
return this.get(`/api/workspaces/${workspaceSlug}/codex-agent-api/agents/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async createAgent(
workspaceSlug: string,
data: { display_name: string; avatar_url?: string | null }
): Promise<{ ok: boolean; agent: TCodexAgent }> {
return this.post(`/api/workspaces/${workspaceSlug}/codex-agent-api/agents/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async upsertGrant(
workspaceSlug: string,
agentId: string,
data: {
mode?: TCodexAgentGrantMode;
project_id?: string | null;
scopes: string[];
}
): Promise<{ ok: boolean; grant: TCodexAgentGrant }> {
return this.post(`/api/workspaces/${workspaceSlug}/codex-agent-api/agents/${agentId}/grants/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async createToken(
workspaceSlug: string,
agentId: string,
data: { name?: string }
): Promise<TCodexAgentCreateTokenResponse> {
return this.post(`/api/workspaces/${workspaceSlug}/codex-agent-api/agents/${agentId}/tokens/`, data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async revokeAgent(workspaceSlug: string, agentId: string): Promise<{ ok: boolean; agent: TCodexAgent }> {
return this.post(`/api/workspaces/${workspaceSlug}/codex-agent-api/agents/${agentId}/revoke/`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}