Connector framework: registry + connectorClient (#86, step 2) - #104
Merged
Conversation
Add the connector framework (step 2 of the connector/tool registry epic, building on the unified ToolDef from #85): - lib/connectors/registry.ts: `Connector {id,label,auth,scopes,grantModel, tokenEnv?,tools}` + `CONNECTORS` (github/meta/tmux). `connectorTools()` flattens `CONNECTORS.flatMap(c=>c.tools)` stamping connector/tier/scope; the tool REGISTRY is built from it plus first-party tools — same registry behaviour. - lib/connectors/client.ts: `connectorClient(env,provider,{userId,instanceId})` → {token(opts?), requireGrant(resourceId), fetch(url,init)}. token() dispatches by Connector.auth (app→installationTokenForOwner, oauth→refresh+generalized mintAccessToken, token→platform env or user_api_keys, none→no auth). Rejects write scope on read-only connectors; instance-resource grants gate token() via requireConnectorGrant (fail-closed 403). - tool-registry.ts: threads connectorClient into RegistryToolCtx (injected in runRegistryTool) + rejects write-scoped tools on read-only connectors. - Refactor github + meta handlers onto ctx.connectorClient(...) — behaviour identical (same tokens, requests, outputs). - Widen ConnectorProvider to string so resource types beyond drive/workdrive work. Tests: +27 (connectorClient dispatch/scope/grant, registry, github+meta behaviour-identity). Full api suite green (761, was 734); tsc --noEmit clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #86 (step 2 of the connector/tool-registry foundation, epic #84 / no-code pipelines #94). Builds on #85 (unified ToolDef).
Adds the connector registry + a
connectorClientthat centralizes token-minting + grant/scope enforcement; refactors GitHub + Meta onto it behaviour-identically.New
lib/connectors/registry.ts—Connector {id,label,auth,scopes,grantModel,tokenEnv?,tools}+CONNECTORS(github·app, meta·token, tmux·none) +connectorTools(). REGISTRY = connectorTools() + first-party slot.lib/connectors/client.ts—connectorClient(env,provider,{userId,instanceId})→token()/requireGrant()/fetch(). Dispatch: app→installationTokenForOwner · oauth→readConnectorRefreshToken+refresh · token→tokenEnv|user_api_keys · none. Central enforcement: write-on-read-only → 403, instance-resource grant fail-closed → 403.tool-registry.ts— threadsconnectorClientintoRegistryToolCtx; rejects write-on-read-only before dispatch.Refactor (behaviour-identical)
connectors/github.ts— token viactx.connectorClient("github").token({resourceId:repo})(sameinstallationTokenForOwner, same errors).connectors/meta.ts— viaconnectorClient("meta")(tokenEnv META_ACCESS_TOKEN).connector-grants.ts—ConnectorProviderwidened tostring.Verify
tsc --noEmitclean (repo-wide) · 761 api tests pass (+27 new, 0 regressions) · biome cleanNo new migrations (0044 grants + 0051 consent already generic).
🤖 Generated with Claude Code