Commit Graph

12 Commits

Author SHA1 Message Date
Kurtis Van Gent
1c9ad5ea24 refactor: implement dynamic source registration (#614)
This commit refactors the source configuration and loading mechanism to
use a dynamic registration pattern. Each source package now registers
itself with a central registry via its init() function.

The server configuration code uses this registry to decode and
initialize sources, decoupling it from specific source implementations
and simplifying the addition of new sources.

Key changes:
- Introduced `sources.Register()` and `newConfig()` constructor in each
source package.
- Moved source package imports to `cmd/root.go` as blank imports to
trigger `init()` functions for self-registration.
- Removed direct imports of specific source packages from
`internal/server/config.go`.
- Renamed `SourceKind` constants to `Kind` within each source package.
- Updated tests to use the new `Kind` constants and reflect registration
changes.

---------

Co-authored-by: Yuan Teoh <yuanteoh@google.com>
2025-06-04 14:23:57 -07:00
Yuan
dced46ad88 chore: cleanup go context (#457) 2025-04-21 20:16:05 +00:00
Wenxin Du
be85b82078 feat: add IAM AuthN to Cloud SQL Sources (#414)
Add IAM support for Cloud SQL source connection using Go language
connector:
https://pkg.go.dev/cloud.google.com/go/cloudsqlconn#section-readme
2025-04-08 16:26:00 -04:00
Yuan
2b6bb99daa chore: throw an error fail to retrieve user agent (#304)
User agent will be set as "genai-toolbox/" + versionString.

Instead of a panic, Toolbox will throw an error if the source fail to
retrieve `user agent`.

This will also be consistent with setting and getting logger from
context.
2025-03-11 13:46:44 -07:00
Yuan
a0ac5334d1 chore: return error for untested fields in tools.yaml (#239)
This only checks within `SourceConfig`, `ToolConfig`, and
`AuthSourceConfig`.

Error when an unknown field is provided:
`2025-01-27T22:43:46.988401-08:00 ERROR "unable to parse tool file at
\"tools.yaml\": unable to parse as \"cloud-sql-postgres\": [2:1] unknown
field \"extra\"\n 1 | database: test_database\n> 2 | extra: here\n ^\n 3
| instance: toolbox-cloudsql\n 4 | kind: cloud-sql-postgres\n 5 |
password: postgres\n 6 | "`

Error when a required field is not provided:
`2025-01-27T17:49:47.584846-08:00 ERROR "unable to parse tool file at
\"tools.yaml\": validation failed: Key: 'Config.Region' Error:Field
validation for 'Region' failed on the 'required' tag"`

---------

Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
2025-02-03 15:30:27 -08:00
Yuan
8452f8eb44 feat: add user agent to cloud databases (#244)
Add user agent to cloud databases that provides us anonymized data
request count, number of users, number of projects, and other
environment settings.

User agent is using the format: `genai-toolbox/$version+metadata`
2025-01-29 17:19:52 -08:00
Wenxin Du
e069520bb7 feat!: replace Source field ip_type with ipType for consistency (#197)
Replace `ip_type` with `ipType` to match the camel-case of the other
fields.
Update docs since we support both private and public IP connections.
2025-01-14 10:56:06 +08:00
Yuan
1fcc20a846 feat: add support for OpenTelemetry (#205)
Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com>
2025-01-13 15:38:38 -08:00
Yuan
6479c1dbe2 feat(source/cloudsql-pg): add configuration for public and private IP (#114)
Allow user to set if their database uses private or public ip. The
reason we add this is because the dialer require different
initialization with private and public ip.

By default, toolbox will use public ip.
2024-12-06 00:08:15 +00:00
Kurtis Van Gent
52ebb431b7 fix: correct source type validation for postgres-sql tool (#47)
Fixes a bug introduced in #43 where postgres-tool didn't think any of
the sources were valid.

The root cause of the bug was inconsistent usage of pointer/value in the
receiver functions. The fix updates everything to consistently use a
pointer receiver function.
2024-11-05 12:25:21 -07:00
Kurtis Van Gent
f630965937 feat!: consolidate "x-postgres-generic" tools to "postgres-sql" tool (#43)
This PR introduces the following breaking change: The
`alloydb-pg-generic`, `cloud-sql-pg-generic`, and
`postgres-generic-tool` have been replaced by the `postgres-sql` tool,
which works with all 3 Postgres sources.

If you were using of the the previous tools, you will need to update it
as follows:
```diff
example_tool:
-    kind: cloud-sql-pg-generic
+    kind: postgres-sql
     source: my-cloud-sql-pg-instance
     description: some description
        statement: |
            SELECT * FROM SQL_STATEMENT;
        parameters:
        - name: country
          type: string
          description: some description
```

I'm proposing this change for the following reasons:
1. It provides greater flexibility between postgres-compatible sources
-- you can change between "postgres" and "alloydb-postgres" without
issue
2. The name "postgres-sql" is more clear that "postgres-generic" -- it
indicates it's a tool that runs SQL on the source
3. It's easier for us to maintain feature compatibility across a single
"postgres-sql" tool
2024-11-01 16:17:18 -07:00
Kurtis Van Gent
efe9e8bc97 chore: refactor sources/tools each into their own package (#42)
Moves all of the "source" and "tool" implementations into their own
packages. This layout makes it a bit more clear where the
implementations are, and seems likely to scale more cleanly as more
sources and tools are added.
2024-11-01 16:44:13 -06:00