CloudShareService.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import type { SettingsService, ShareResponse, ShareVisibility } from "@roo-code/types"
  2. import { importVscode } from "./importVscode.js"
  3. import type { CloudAPI } from "./CloudAPI.js"
  4. export class CloudShareService {
  5. private cloudAPI: CloudAPI
  6. private settingsService: SettingsService
  7. private log: (...args: unknown[]) => void
  8. constructor(cloudAPI: CloudAPI, settingsService: SettingsService, log?: (...args: unknown[]) => void) {
  9. this.cloudAPI = cloudAPI
  10. this.settingsService = settingsService
  11. this.log = log || console.log
  12. }
  13. async shareTask(taskId: string, visibility: ShareVisibility = "organization"): Promise<ShareResponse> {
  14. try {
  15. const response = await this.cloudAPI.shareTask(taskId, visibility)
  16. if (response.success && response.shareUrl) {
  17. const vscode = await importVscode()
  18. if (vscode?.env?.clipboard?.writeText) {
  19. try {
  20. await vscode.env.clipboard.writeText(response.shareUrl)
  21. } catch (copyErr) {
  22. this.log("[ShareService] Clipboard write failed (non-fatal):", copyErr)
  23. }
  24. } else {
  25. this.log("[ShareService] VS Code clipboard unavailable; running outside extension host.")
  26. }
  27. }
  28. return response
  29. } catch (error) {
  30. this.log("[ShareService] Error sharing task:", error)
  31. throw error
  32. }
  33. }
  34. async canShareTask(): Promise<boolean> {
  35. try {
  36. return !!this.settingsService.getSettings()?.cloudSettings?.enableTaskSharing
  37. } catch (error) {
  38. this.log("[ShareService] Error checking if task can be shared:", error)
  39. return false
  40. }
  41. }
  42. }