Repository navigation
[ENG-3850] Use a member's custom connections on their cloud turns #777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tino097
wants to merge
28
commits into
staging
Choose a base branch
from
tino097/eng-3850-use-a-members-custom-connector-on-their
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,455
−101
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
01442b4
Read the custom API block of a cloud turn
tino097 1aa3961
Fetch custom connection fields with the turn key
tino097 cacaced
Prove a custom connection's values reach no log, prompt or output
tino097 c2ae61b
Hide every custom field but its address on turns, whatever the templa…
tino097 68f5d16
Keep every field auth marks secure hidden on turns too
tino097 b3c49c7
Never start a custom connection fetch still queued at the deadline
tino097 530a87e
Leave a short config value auth did not mark secure readable on turns
tino097 ecbc434
Hide a short custom value on turns too, whatever the template flagged
tino097 8959f7a
Require a check when Anton builds a connector template
tino097 8914494
Tell Anton what to do when a check cannot place the key
tino097 434e661
Test the key-in-URL check refusal by its path
tino097 14984de
Merge staging into the custom API block branch
tino097 d9cba33
Write the usage-notes example as a helper call, with the query apart …
tino097 0782d74
Stop fetching a custom connection's fields into the pod
tino097 319acd2
Hand the turn's custom API connections to the scratchpad by id and ve…
tino097 7d69a6b
Tell the model about its custom API connections, with their notes kep…
tino097 c8b39af
Add call_minds_api, the turn-key-bound custom API helper
tino097 6e79422
Keep every malformed gateway answer inside the helper's closed codes,…
tino097 2ee98cf
Merge staging
tino097 a61bb1e
Merge staging
tino097 ef276f5
Merge staging
tino097 12860fe
Let a template mark its key optional and give a public check path
tino097 bebb774
Align the optional key tool text with the parser and tighten stored B…
tino097 4906797
Merge staging
tino097 1055772
Move the optional key support to its own change
tino097 4f5a86d
Let a template mark its key optional and give a public check path
tino097 ede4e0d
Align the optional key tool text with the parser and tighten stored B…
tino097 fa559f4
Merge pull request #809 from mindsdb/tino097/eng-3850-optional-custom…
tino097 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,13 @@ | |
| TURN_PROTOCOL_VERSION = 1 | ||
| DATASOURCE_PROTOCOL_VERSION = 1 | ||
| MAX_DATASOURCE_CONNECTIONS = 100 | ||
| #: The most custom API connections one turn carries; cowork-server holds the | ||
| #: same cap. | ||
| MAX_CUSTOM_API_CONNECTIONS = 25 | ||
| #: The connector id rule anton's draft parser applies, and auth's longest | ||
| #: connection name: a block outside them did not come from those writers. | ||
| _CUSTOM_CONNECTOR_ID = re.compile(r"[a-z][a-z0-9_]{1,40}") | ||
| _CUSTOM_NAME_MAX = 128 | ||
| _REQUIRED_REF_KEYS = frozenset({"connection_id", "credential_version"}) | ||
| # Names only, for the prompt. cowork-server's queue check allows the same two. | ||
| _OPTIONAL_REF_KEYS = frozenset({"label", "engine"}) | ||
|
|
@@ -286,6 +293,70 @@ def _parse_datasource_block(value: object) -> DatasourceBlockV1 | None: | |
| return DatasourceBlockV1(DATASOURCE_PROTOCOL_VERSION, tuple(refs)) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class CustomApiConnectionRefV1: | ||
| """One custom API connection the turn may call: auth's id and the member's own names, never a value.""" | ||
|
|
||
| connection_id: int | ||
| connector_id: str | ||
| name: str | ||
| credential_version: int | ||
|
|
||
|
|
||
| @dataclass(frozen=True, repr=False) | ||
| class CustomApiBlockV1: | ||
| """The member's custom API connections and the turn key their grants are bound to. | ||
|
|
||
| ``repr=False`` keeps the key out of any traceback that prints the request. | ||
| """ | ||
|
|
||
| turn_key: str | ||
| connections: tuple[CustomApiConnectionRefV1, ...] | ||
|
|
||
|
|
||
| def _positive_int(value: object) -> bool: | ||
| """Whether ``value`` is an int of 1 or more, booleans excluded.""" | ||
| return not isinstance(value, bool) and isinstance(value, int) and value >= 1 | ||
|
|
||
|
|
||
| def _parse_custom_api_block(value: object) -> CustomApiBlockV1 | None: | ||
| """Parse the optional ``custom_api`` block exactly, or refuse the request.""" | ||
| if value is None: | ||
| return None | ||
| if not isinstance(value, dict) or set(value) != {"turn_key", "connections"}: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The block has no |
||
| raise ValueError("custom_api must carry exactly turn_key and connections") | ||
| turn_key = value["turn_key"] | ||
| if not isinstance(turn_key, str) or not turn_key: | ||
| raise ValueError("custom_api turn key is missing") | ||
| connections = value["connections"] | ||
| if not isinstance(connections, list) or not connections or len(connections) > MAX_CUSTOM_API_CONNECTIONS: | ||
| raise ValueError("custom_api connections are invalid") | ||
| refs: list[CustomApiConnectionRefV1] = [] | ||
| seen: set[int] = set() | ||
| for connection in connections: | ||
| if not isinstance(connection, dict) or set(connection) != { | ||
| "connection_id", "connector_id", "name", "credential_version", | ||
| }: | ||
| raise ValueError("custom_api connection reference is invalid") | ||
| connection_id = connection["connection_id"] | ||
| if ( | ||
| not _positive_int(connection_id) | ||
| or not _positive_int(connection["credential_version"]) | ||
| or not isinstance(connection["connector_id"], str) | ||
| or not _CUSTOM_CONNECTOR_ID.fullmatch(connection["connector_id"]) | ||
| or not isinstance(connection["name"], str) | ||
| or not connection["name"] | ||
| or len(connection["name"]) > _CUSTOM_NAME_MAX | ||
| or connection_id in seen | ||
| ): | ||
| raise ValueError("custom_api connection reference is invalid") | ||
| seen.add(connection_id) | ||
| refs.append(CustomApiConnectionRefV1( | ||
| connection_id, connection["connector_id"], connection["name"], connection["credential_version"], | ||
| )) | ||
| return CustomApiBlockV1(turn_key, tuple(refs)) | ||
|
|
||
|
|
||
| def _usable_label(value: object) -> str | None: | ||
| """The connection's name as one clean prompt line, or ``None`` when nothing usable is left. | ||
|
|
||
|
|
@@ -486,6 +557,9 @@ class TurnRequestV1: | |
| #: id), which only the prompt reads. No capability or password crosses; the | ||
| #: gateway is on the `llm` base URL's host. | ||
| datasource: DatasourceBlockV1 | None = None | ||
| #: Optional custom API connections of the member, by auth id, with the turn | ||
| #: key their grants are bound to (this turn only). No value. | ||
| custom_api: CustomApiBlockV1 | None = None | ||
| #: Optional ISO 8601 creation time of the conversation, as cowork-server | ||
| #: resolved it. The pod is new every turn and cannot derive this: history | ||
| #: rows carry no timestamps. Without it the session dates the conversation | ||
|
|
@@ -522,7 +596,8 @@ class TurnRequestV1: | |
| preview_checks: bool = False | ||
| #: Per-engine connector data cowork-server resolved for this turn: | ||
| #: {engine: {"usage_notes": str}}. Rendered only for engines the turn's | ||
| #: vault connects. Absent when no connected engine has notes. | ||
| #: vault connects and, apart and as data, for the connector ids of the | ||
| #: ``custom_api`` block. Absent when no connected engine has notes. | ||
| connectors: dict | None = None | ||
| #: Whether this turn may build connector templates with | ||
| #: `create_connector_draft`, sent back on the `connector` event. Anything | ||
|
|
@@ -574,6 +649,7 @@ def from_json(raw: str) -> "TurnRequestV1": | |
| # Same defensive isinstance check as trace, for the same reason. | ||
| oauth=d.get("oauth") if isinstance(d.get("oauth"), dict) else None, | ||
| datasource=_parse_datasource_block(d.get("datasource")), | ||
| custom_api=_parse_custom_api_block(d.get("custom_api")), | ||
| # The controller always sends the key and sends None when | ||
| # cowork-server could not resolve it, so the guard does real work. | ||
| started_at=( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TurnRequestV1is a plain dataclass whose repr still shows the turn key throughllmandoauth, so this does not keep the key out of a printed request. Also,turn_keyhere must equalllm.api_keyand the helper never reads it, so it could be dropped.