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
4 changes: 2 additions & 2 deletions apps/code/src/main/deep-links.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getDeeplinkProtocol } from "@posthog/shared";
import { app } from "electron";
import { container } from "./di/container";
import { MAIN_TOKENS } from "./di/tokens";
import { DEEP_LINK_SERVICE } from "./di/tokens";
import type { DeepLinkService } from "./services/deep-link/service";
import { isDevBuild } from "./utils/env";
import { logger } from "./utils/logger";
Expand All @@ -12,7 +12,7 @@ const log = logger.scope("deep-links");
let pendingDeepLinkUrl: string | null = null;

function getDeepLinkService(): DeepLinkService {
return container.get<DeepLinkService>(MAIN_TOKENS.DeepLinkService);
return container.get<DeepLinkService>(DEEP_LINK_SERVICE);
}

function findDeepLinkUrlInArgs(args: string[]): string | undefined {
Expand Down
71 changes: 32 additions & 39 deletions apps/code/src/main/di/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ import {
DATABASE_SERVICE as MAIN_DATABASE_SERVICE,
DEEP_LINK_SERVICE as MAIN_DEEP_LINK_SERVICE,
DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY as MAIN_DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY,
DISCORD_PRESENCE_SERVICE as MAIN_DISCORD_PRESENCE_SERVICE,
ENCRYPTION_SERVICE as MAIN_ENCRYPTION_SERVICE,
EXTERNAL_APPS_SERVICE as MAIN_EXTERNAL_APPS_SERVICE,
FILE_WATCHER_SERVICE as MAIN_FILE_WATCHER_SERVICE,
FS_SERVICE as MAIN_FS_SERVICE,
INBOX_LINK_SERVICE as MAIN_INBOX_LINK_SERVICE,
LLM_GATEWAY_SERVICE as MAIN_LLM_GATEWAY_SERVICE,
Expand All @@ -276,9 +278,9 @@ import {
SUSPENSION_REPOSITORY as MAIN_SUSPENSION_REPOSITORY,
SUSPENSION_SERVICE as MAIN_SUSPENSION_SERVICE,
TASK_LINK_SERVICE as MAIN_TASK_LINK_SERVICE,
MAIN_TOKENS,
UPDATES_SERVICE as MAIN_UPDATES_SERVICE,
WATCHER_REGISTRY_SERVICE as MAIN_WATCHER_REGISTRY_SERVICE,
WORKSPACE_CLIENT as MAIN_WORKSPACE_CLIENT,
WORKSPACE_REPOSITORY as MAIN_WORKSPACE_REPOSITORY,
WORKSPACE_SERVER_SERVICE as MAIN_WORKSPACE_SERVER_SERVICE,
WORKSPACE_SERVICE as MAIN_WORKSPACE_SERVICE,
Expand Down Expand Up @@ -340,17 +342,17 @@ container
.bind(AUTH_TOKEN_OVERRIDE)
.toConstantValue(process.env.VITE_POSTHOG_ACCESS_TOKEN_OVERRIDE ?? null);
container.bind(MAIN_AUTH_SERVICE).to(AuthService);
container.bind(AUTH_SERVICE).toService(MAIN_TOKENS.AuthService);
container.bind(AUTH_SERVICE).toService(MAIN_AUTH_SERVICE);
container.load(authProxyModule);
container.bind(AUTH_PROXY_AUTH).toDynamicValue((ctx) => ({
authenticatedFetch: (url: string, init?: RequestInit) =>
ctx
.get<AuthService>(MAIN_TOKENS.AuthService)
.get<AuthService>(MAIN_AUTH_SERVICE)
.authenticatedFetch(fetch, url, init),
}));
container.load(mcpProxyModule);
container.bind(MCP_PROXY_AUTH).toDynamicValue((ctx) => {
const auth = () => ctx.get<AuthService>(MAIN_TOKENS.AuthService);
const auth = () => ctx.get<AuthService>(MAIN_AUTH_SERVICE);
return {
authenticatedFetch: (url: string, init?: RequestInit) =>
auth().authenticatedFetch(fetch, url, init),
Expand All @@ -365,7 +367,7 @@ container.bind(ARCHIVE_SESSION_CANCELLER).toDynamicValue((ctx) => ({
container.bind(ARCHIVE_FILE_WATCHER).toDynamicValue((ctx) => ({
stopWatching: async (worktreePath: string) => {
ctx
.get<FileWatcherBridge>(MAIN_TOKENS.FileWatcherService)
.get<FileWatcherBridge>(MAIN_FILE_WATCHER_SERVICE)
.stopWatching(worktreePath);
},
}));
Expand All @@ -377,7 +379,7 @@ container.bind(SUSPENSION_SESSION_CANCELLER).toDynamicValue((ctx) => ({
container.bind(SUSPENSION_FILE_WATCHER).toDynamicValue((ctx) => ({
stopWatching: async (worktreePath: string) => {
ctx
.get<FileWatcherBridge>(MAIN_TOKENS.FileWatcherService)
.get<FileWatcherBridge>(MAIN_FILE_WATCHER_SERVICE)
.stopWatching(worktreePath);
},
}));
Expand All @@ -387,20 +389,20 @@ container.load(cloudTaskModule);
container.bind(CLOUD_TASK_AUTH).toDynamicValue((ctx) => ({
authenticatedFetch: (url: string, init?: RequestInit) =>
ctx
.get<AuthService>(MAIN_TOKENS.AuthService)
.get<AuthService>(MAIN_AUTH_SERVICE)
.authenticatedFetch(fetch, url, init),
}));
container.bind(MAIN_CLOUD_TASK_SERVICE).toService(CLOUD_TASK_SERVICE);
container.load(contextMenuCoreModule);
container
.bind(CONTEXT_MENU_EXTERNAL_APPS_SERVICE)
.toService(MAIN_TOKENS.ExternalAppsService);
.toService(MAIN_EXTERNAL_APPS_SERVICE);
container.bind(MAIN_CONTEXT_MENU_SERVICE).toService(CONTEXT_MENU_CONTROLLER);
container.bind(MAIN_DEEP_LINK_SERVICE).to(DeepLinkService);
container.bind(DEEP_LINK_SERVICE).toService(MAIN_TOKENS.DeepLinkService);
container.bind(DEEP_LINK_SERVICE).toService(MAIN_DEEP_LINK_SERVICE);
container.load(enrichmentModule);
container.bind(ENRICHMENT_AUTH).toDynamicValue((ctx) => {
const auth = () => ctx.get<AuthService>(MAIN_TOKENS.AuthService);
const auth = () => ctx.get<AuthService>(MAIN_AUTH_SERVICE);
return {
getState: () => {
const state = auth().getState();
Expand All @@ -423,7 +425,7 @@ container.bind(ENRICHMENT_FILE_READER).toConstantValue({
listFilesContainingText(repoPath, text),
});
container.bind(MAIN_PROVISIONING_SERVICE).to(ProvisioningService);
container.bind(PROVISIONING_SERVICE).toService(MAIN_TOKENS.ProvisioningService);
container.bind(PROVISIONING_SERVICE).toService(MAIN_PROVISIONING_SERVICE);

const externalAppsPrefsStore = new ExternalAppsStoreImpl<{
externalAppsPrefs: ExternalAppsPreferences;
Expand All @@ -441,7 +443,7 @@ container.load(externalAppsModule);
container.bind(MAIN_EXTERNAL_APPS_SERVICE).toService(EXTERNAL_APPS_SERVICE);
container.load(llmGatewayModule);
container.bind(LLM_GATEWAY_HOST).toDynamicValue((ctx) => {
const auth = () => ctx.get<AuthService>(MAIN_TOKENS.AuthService);
const auth = () => ctx.get<AuthService>(MAIN_AUTH_SERVICE);
return {
getValidAccessToken: () => auth().getValidAccessToken(),
authenticatedFetch: (url: string, init?: RequestInit) =>
Expand All @@ -460,9 +462,8 @@ container.bind(MAIN_MCP_APPS_SERVICE).toService(MCP_APPS_SERVICE);
container.load(foldersModule);
container.load(integrationsModule);
container.load(gitPrModule);
container.bind(GIT_DIFF_SOURCE).toDynamicValue(() => {
const wsClient = () =>
container.get<HostGitWorkspaceClient>(GIT_WORKSPACE_CLIENT);
container.bind(GIT_DIFF_SOURCE).toDynamicValue((ctx) => {
const wsClient = () => ctx.get<HostGitWorkspaceClient>(GIT_WORKSPACE_CLIENT);
const git = () => wsClient().git;
return {
getStagedDiff: (directoryPath: string) =>
Expand Down Expand Up @@ -523,7 +524,7 @@ container
container.load(handoffModule);
container.bind(HANDOFF_HOST).to(HandoffHostService).inSingletonScope();
container.bind(HANDOFF_GIT_GATEWAY).toDynamicValue((ctx): HandoffGitGateway => {
const workspace = ctx.get<WorkspaceClient>(MAIN_TOKENS.WorkspaceClient);
const workspace = ctx.get<WorkspaceClient>(MAIN_WORKSPACE_CLIENT);
return {
async getChangedFiles(repoPath) {
const files = await workspace.git.getChangedFilesHead.query({
Expand All @@ -548,7 +549,7 @@ container.bind(HANDOFF_GIT_GATEWAY).toDynamicValue((ctx): HandoffGitGateway => {
};
});
container.bind(HANDOFF_LOG_GATEWAY).toDynamicValue((ctx) => {
const ws = ctx.get<WorkspaceClient>(MAIN_TOKENS.WorkspaceClient);
const ws = ctx.get<WorkspaceClient>(MAIN_WORKSPACE_CLIENT);
return {
seedLocalLogs: (taskRunId: string, content: string) =>
ws.localLogs.seed.mutate({ taskRunId, content }),
Expand Down Expand Up @@ -584,26 +585,22 @@ container.load(skillsMarketplaceModule);
container.load(onboardingImportModule);
container.load(additionalDirectoriesModule);
container.bind(MAIN_SLEEP_SERVICE).to(SleepService);
container.bind(SLEEP_SERVICE).toService(MAIN_TOKENS.SleepService);
container.bind(SLEEP_SERVICE).toService(MAIN_SLEEP_SERVICE);
container.load(shellModule);
container.load(uiModule);
container.bind(UI_AUTH).toDynamicValue((ctx) => ({
invalidateAccessTokenForTest: () =>
ctx
.get<AuthService>(MAIN_TOKENS.AuthService)
.invalidateAccessTokenForTest(),
ctx.get<AuthService>(MAIN_AUTH_SERVICE).invalidateAccessTokenForTest(),
}));
container.load(updatesCoreModule);
container
.bind(UPDATE_LIFECYCLE_SERVICE)
.toService(MAIN_TOKENS.AppLifecycleService);
container.bind(UPDATE_LIFECYCLE_SERVICE).toService(MAIN_APP_LIFECYCLE_SERVICE);
container.bind(MAIN_UPDATES_SERVICE).toService(UPDATES_SERVICE);
container.load(usageMonitorModule);
container.bind(USAGE_HOST).toDynamicValue((ctx) => {
const agent = () => ctx.get<AgentService>(AGENT_SERVICE);
return {
fetchUsage: () =>
ctx.get<LlmGatewayService>(MAIN_TOKENS.LlmGatewayService).fetchUsage(),
ctx.get<LlmGatewayService>(MAIN_LLM_GATEWAY_SERVICE).fetchUsage(),
onLlmActivity: (listener: () => void) =>
agent().on(AgentServiceEvent.LlmActivity, listener),
offLlmActivity: (listener: () => void) =>
Expand All @@ -615,17 +612,15 @@ container.bind(USAGE_HOST).toDynamicValue((ctx) => {
};
});
container.bind(MAIN_TASK_LINK_SERVICE).to(TaskLinkService);
container.bind(TASK_LINK_SERVICE).toService(MAIN_TOKENS.TaskLinkService);
container.bind(TASK_LINK_SERVICE).toService(MAIN_TASK_LINK_SERVICE);
container.bind(MAIN_INBOX_LINK_SERVICE).to(InboxLinkService);
container.bind(INBOX_LINK_SERVICE).toService(MAIN_TOKENS.InboxLinkService);
container.bind(INBOX_LINK_SERVICE).toService(MAIN_INBOX_LINK_SERVICE);
container.bind(MAIN_SCOUT_LINK_SERVICE).to(ScoutLinkService);
container.bind(SCOUT_LINK_SERVICE).toService(MAIN_TOKENS.ScoutLinkService);
container.bind(SCOUT_LINK_SERVICE).toService(MAIN_SCOUT_LINK_SERVICE);
container.bind(MAIN_NEW_TASK_LINK_SERVICE).to(NewTaskLinkService);
container.bind(NEW_TASK_LINK_SERVICE).toService(MAIN_TOKENS.NewTaskLinkService);
container.bind(NEW_TASK_LINK_SERVICE).toService(MAIN_NEW_TASK_LINK_SERVICE);
container.bind(MAIN_APPROVAL_LINK_SERVICE).to(ApprovalLinkService);
container
.bind(APPROVAL_LINK_SERVICE)
.toService(MAIN_TOKENS.ApprovalLinkService);
container.bind(APPROVAL_LINK_SERVICE).toService(MAIN_APPROVAL_LINK_SERVICE);
container.load(watcherRegistryModule);
container
.bind(MAIN_WATCHER_REGISTRY_SERVICE)
Expand All @@ -642,9 +637,7 @@ container.bind(WORKSPACE_AGENT).toDynamicValue((ctx): WorkspaceAgent => {
container
.bind(WORKSPACE_FILE_WATCHER)
.toDynamicValue((ctx): WorkspaceFileWatcher => {
const fileWatcher = ctx.get<FileWatcherBridge>(
MAIN_TOKENS.FileWatcherService,
);
const fileWatcher = ctx.get<FileWatcherBridge>(MAIN_FILE_WATCHER_SERVICE);
return {
stopWatching: async (worktreePath) => {
fileWatcher.stopWatching(worktreePath);
Expand All @@ -666,7 +659,7 @@ container
.bind(WORKSPACE_PROVISIONING)
.toDynamicValue((ctx): WorkspaceProvisioning => {
const provisioning = ctx.get<ProvisioningService>(
MAIN_TOKENS.ProvisioningService,
MAIN_PROVISIONING_SERVICE,
);
return {
emitOutput: (taskId, data) => provisioning.emitOutput(taskId, data),
Expand All @@ -685,9 +678,9 @@ container
.bind(MAIN_SECURE_STORE_SERVICE)
.to(SecureStoreService)
.inSingletonScope();
container.bind(SECURE_STORE_SERVICE).toService(MAIN_TOKENS.SecureStoreService);
container.bind(SECURE_STORE_SERVICE).toService(MAIN_SECURE_STORE_SERVICE);
container.bind(LOGS_SERVICE).toDynamicValue((ctx) => {
const ws = ctx.get<WorkspaceClient>(MAIN_TOKENS.WorkspaceClient);
const ws = ctx.get<WorkspaceClient>(MAIN_WORKSPACE_CLIENT);
return {
fetchS3Logs: async (logUrl: string) => {
try {
Expand All @@ -706,7 +699,7 @@ container.bind(LOGS_SERVICE).toDynamicValue((ctx) => {
};
});
container.bind(MAIN_ENCRYPTION_SERVICE).to(EncryptionService);
container.bind(MAIN_TOKENS.DiscordPresenceService).to(DiscordPresenceService);
container.bind(MAIN_DISCORD_PRESENCE_SERVICE).to(DiscordPresenceService);

// Canvas / dashboards (project-bluebird). The host-agnostic dashboard services
// live in @posthog/core (bound via canvasCoreModule) and resolve through
Expand Down
47 changes: 0 additions & 47 deletions apps/code/src/main/di/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,50 +121,3 @@ export const WORKSPACE_SERVER_SERVICE = Symbol.for(
export const DISCORD_PRESENCE_SERVICE = Symbol.for(
"posthog.host.main.discord-presence.service",
);

export const MAIN_TOKENS = Object.freeze({
WorkspaceClient: WORKSPACE_CLIENT,

SettingsStore: SETTINGS_STORE,
SecureStoreService: SECURE_STORE_SERVICE,
SecureStoreBackend: SECURE_STORE_BACKEND,
EncryptionService: ENCRYPTION_SERVICE,

AuthPreferenceRepository: AUTH_PREFERENCE_REPOSITORY,
DatabaseService: DATABASE_SERVICE,
AuthSessionRepository: AUTH_SESSION_REPOSITORY,
RepositoryRepository: REPOSITORY_REPOSITORY,
WorkspaceRepository: WORKSPACE_REPOSITORY,
WorktreeRepository: WORKTREE_REPOSITORY,
ArchiveRepository: ARCHIVE_REPOSITORY,
SuspensionRepository: SUSPENSION_REPOSITORY,
DefaultAdditionalDirectoryRepository: DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY,

AuthService: AUTH_SERVICE,
SuspensionService: SUSPENSION_SERVICE,
AppLifecycleService: APP_LIFECYCLE_SERVICE,
CloudTaskService: CLOUD_TASK_SERVICE,
ContextMenuService: CONTEXT_MENU_SERVICE,
DiscordPresenceService: DISCORD_PRESENCE_SERVICE,

ExternalAppsService: EXTERNAL_APPS_SERVICE,
LlmGatewayService: LLM_GATEWAY_SERVICE,
McpAppsService: MCP_APPS_SERVICE,
FileWatcherService: FILE_WATCHER_SERVICE,
FsService: FS_SERVICE,
GitService: GIT_SERVICE,
DeepLinkService: DEEP_LINK_SERVICE,
ProcessTrackingService: PROCESS_TRACKING_SERVICE,
SleepService: SLEEP_SERVICE,
PosthogPluginService: POSTHOG_PLUGIN_SERVICE,
UpdatesService: UPDATES_SERVICE,
TaskLinkService: TASK_LINK_SERVICE,
InboxLinkService: INBOX_LINK_SERVICE,
ScoutLinkService: SCOUT_LINK_SERVICE,
NewTaskLinkService: NEW_TASK_LINK_SERVICE,
ApprovalLinkService: APPROVAL_LINK_SERVICE,
WatcherRegistryService: WATCHER_REGISTRY_SERVICE,
ProvisioningService: PROVISIONING_SERVICE,
WorkspaceService: WORKSPACE_SERVICE,
WorkspaceServerService: WORKSPACE_SERVER_SERVICE,
});
Loading
Loading