Skip to content

gdrive connector with google picker api#178

Merged
martyna-mindsdb merged 8 commits into
stagingfrom
google_picker_api
Jul 15, 2026
Merged

gdrive connector with google picker api#178
martyna-mindsdb merged 8 commits into
stagingfrom
google_picker_api

Conversation

@martyna-mindsdb

@martyna-mindsdb martyna-mindsdb commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Linear ticket: https://linear.app/mindsdb/issue/ENG-687/google-drive-google-picker-api


Demo video: https://www.loom.com/share/6c689e3708664779aa13900ae20e4e49


Adds the server-side infrastructure for the Google Drive Picker, including endpoints to persist, query, and untag picked-file grants on a connection record, per-project scoping so the agent only sees files relevant to the current project, and delivery of the Google Picker API key required by the desktop app.

This PR also includes several reliability improvements from code review: a shared per-connection lock to eliminate read-modify-write races, preservation of picked files and custom connection labels across OAuth reconnects and token refreshes, and consolidation of duplicated connection-loading logic.

File What & why
cowork/schemas/connectors.py Added PickedFile (including project tags) and PatchPickedFilesBody request models.
cowork/common/settings/app_settings.py Added the google_picker_api_key (GOOGLE_PICKER_API_KEY) setting used by the browser-based Google Picker widget.
cowork/services/connectors/oauth/config.py Added a uses_picker flag to GoogleServiceConfig so the credentials endpoint determines whether to include the Picker API key from configuration instead of relying on a hardcoded engine-name check.
cowork/api/v1/endpoints/connectors/oauth.py Updated the /credentials response to include picker_api_key when uses_picker is enabled.
cowork/api/v1/endpoints/connectors/connections.py Added PATCH .../picked-files to merge Picker selections and DELETE .../picked-files/{file_id}?project=... to remove a file's association with a single project.
cowork/services/connectors/connections.py Implemented the core picked-file logic. merge_picked_files unions project tags instead of overwriting them, while remove_picked_file only removes a project association and never revokes the underlying grant. Added a shared per-(engine, name) lock around all read-modify-write operations (merge_picked_files, remove_picked_file, patch_token) to eliminate concurrent update races. Extracted shared _read_record and _load_picked_files helpers to remove duplicated logic, and renamed the vault field to _picked_files so it is treated as an internal field rather than an agent-visible credential.
cowork/services/connectors/oauth/google.py Preserved _picked_files and _label across OAuth reconnects and token refreshes instead of overwriting them. Wrapped updates in the shared connection lock to prevent races with concurrent Picker operations.
cowork/services/connectors/persist.py Updated persist_connection to preserve _picked_files during full-record saves, wrapped it in the shared lock, and also synchronized set_connection_label for consistency.
cowork/services/connectors/vault_lock.py Added a shared per-(engine, name) lock registry used by all connection write paths to serialize concurrent operations. Includes cleanup when connections are deleted to prevent the registry from growing indefinitely.
cowork/harnesses/anton_harness/harness.py Injected project-scoped picked-file guidance into the agent's system prompt. Files are only exposed when tagged to the current project, while connection-wide files remain visible everywhere. Also merged two vault-scan loops into one to reduce directory I/O on every chat turn.
uv.lock Lockfile bump.

@martyna-mindsdb martyna-mindsdb self-assigned this Jul 8, 2026
@martyna-mindsdb
martyna-mindsdb marked this pull request as ready for review July 10, 2026 15:50
data_vault.inject_env(conn["engine"], conn["name"])

# TODO: Add guidance for integrations
# Google Drive's google_drive connector uses the drive.file OAuth

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the Google Drive logic out of the harness and into the connector service. (the harness parses _picked_files JSON, checks engine != "google_drive", and applies project-scoping rules itself. This is connector logic, not agent logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I moved this from harness to connections and tested the entire flow successfully. Done.

@martyna-mindsdb
martyna-mindsdb merged commit 802aca6 into staging Jul 15, 2026
6 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants