-
Notifications
You must be signed in to change notification settings - Fork 15
feat(toolbox-adk): add protocol #122
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
078f0f1
feat: add for toolbox-adk protocol
twishabansal bd08c46
fix package deps
twishabansal 301c0d0
fix config
twishabansal 3e31029
lint
twishabansal 2350ece
ci: add linter workflow for toolbox-adk
twishabansal 45e6dd8
Merge branch 'twishabansal-patch-3' into adk-protocol
twishabansal f8cf048
Rename lint-toolbox-adk to lint-toolbox-adk.yaml
twishabansal a1548bb
Rename lint-toolbox-adk to lint-toolbox-adk.yaml
twishabansal 4c65205
Merge branch 'twishabansal-patch-3' into adk-protocol
twishabansal 69f5174
Update test.protocol.ts
twishabansal 97b873f
basic monorepo setup
twishabansal 1714120
fix lint workflow
twishabansal 1603b52
fix integration test workflow
twishabansal a63c833
ignore header checker for lock file
twishabansal e7cfcab
add lock file
twishabansal 62900c5
fix adk files
twishabansal 0139bb2
fix package file
twishabansal c6d2f6a
fix file
twishabansal 24b6af1
add empty index file
twishabansal 2cfb402
update lock file
twishabansal d1adf5e
Merge branch 'main' into monorepo-config-final
twishabansal f9e0cba
fix adk lint
twishabansal 58ce458
Merge branch 'main' into adk-protocol
twishabansal 0cae93f
Merge branch 'monorepo-config-final' into adk-protocol
twishabansal ae3619c
Update integration.cloudbuild.yaml
twishabansal fe2d29f
Update package.json
twishabansal 9f9c947
fix package.json
twishabansal 4a9ddcf
update deps
twishabansal f9a0eba
remove package lock files
twishabansal 4de004b
remove package lock files
twishabansal 7c4284a
Merge branch 'monorepo-config-final' into adk-protocol
twishabansal b213094
Merge branch 'main' into adk-protocol
twishabansal a56e145
comment out integration tests
twishabansal 6929a8b
Merge branch 'main' into adk-protocol
twishabansal 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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| steps: | ||
| - id: Install dependencies | ||
| name: 'node:${_VERSION}' | ||
| entrypoint: /bin/bash | ||
| args: | ||
| - -c | ||
| - corepack enable && pnpm install --frozen-lockfile | ||
|
|
||
| - id: Run unit tests | ||
| name: 'node:${_VERSION}' | ||
| entrypoint: /bin/bash | ||
| waitFor: ['Install dependencies'] | ||
| args: | ||
| - '-c' | ||
| - corepack enable && pnpm --filter @toolbox-sdk/adk run test:unit | ||
|
|
||
| # - id: Run integration tests | ||
| # name: 'node:${_VERSION}' | ||
| # entrypoint: /bin/bash | ||
| # waitFor: ['Install dependencies'] | ||
| # env: | ||
| # - TOOLBOX_URL=$_TOOLBOX_URL | ||
| # - TOOLBOX_VERSION=$_TOOLBOX_VERSION | ||
| # - GOOGLE_CLOUD_PROJECT=$PROJECT_ID | ||
| # - TOOLBOX_MANIFEST_VERSION=$_TOOLBOX_MANIFEST_VERSION | ||
| # args: | ||
| # - '-c' | ||
| # - corepack enable && pnpm --filter @toolbox-sdk/adk run test:e2e | ||
|
|
||
| options: | ||
| logging: CLOUD_LOGGING_ONLY | ||
| substitutions: | ||
| _VERSION: '22.16.0' | ||
| _TOOLBOX_VERSION: '0.17.0' | ||
| _TOOLBOX_MANIFEST_VERSION: '34' |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import type {FunctionDeclaration, Schema} from '@google/genai'; | ||
| import {Type} from '@google/genai'; | ||
| import {z, ZodObject, ZodRawShape, ZodTypeAny} from 'zod'; | ||
|
|
||
| /** | ||
| * Safely determines the JSON Schema type enum from a Zod type object. | ||
| * | ||
| * @param zodType The Zod type instance to inspect. | ||
| * @returns A value from the `Type` enum. | ||
| */ | ||
| function getJsonSchemaTypeFromZod(zodType: ZodTypeAny): Type { | ||
| // Handle optional and nullable types by recursively unwrapping them | ||
| if (zodType instanceof z.ZodOptional || zodType instanceof z.ZodNullable) { | ||
| return getJsonSchemaTypeFromZod(zodType.unwrap()); | ||
| } | ||
|
|
||
| // Handle specific base types | ||
| if (zodType instanceof z.ZodNull) { | ||
| return Type.NULL; | ||
| } | ||
|
|
||
| if (zodType instanceof z.ZodString || zodType instanceof z.ZodEnum) { | ||
| return Type.STRING; | ||
| } | ||
|
|
||
| if (zodType instanceof z.ZodNumber) { | ||
| const isInteger = zodType._def.checks.some(check => check.kind === 'int'); | ||
| return isInteger ? Type.INTEGER : Type.NUMBER; | ||
| } | ||
|
|
||
| if (zodType instanceof z.ZodBoolean) { | ||
| return Type.BOOLEAN; | ||
| } | ||
| if (zodType instanceof z.ZodArray) { | ||
| return Type.ARRAY; | ||
| } | ||
| if (zodType instanceof z.ZodObject) { | ||
| return Type.OBJECT; | ||
| } | ||
| // Fallback for unhandled types | ||
| return Type.TYPE_UNSPECIFIED; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a ZodObject schema into a FunctionDeclaration for the Google ADK. | ||
| * | ||
| * @param name The name of the function/tool. | ||
| * @param description The description of the function/tool. | ||
| * @param zodSchema The Zod schema for the tool's parameters. | ||
| * @returns A FunctionDeclaration object for the Google Genai API. | ||
| */ | ||
| export function ConvertZodToFunctionDeclaration( | ||
| name: string, | ||
| description: string, | ||
| zodSchema: ZodObject<ZodRawShape>, | ||
| ): FunctionDeclaration { | ||
| const properties: Record<string, Schema> = {}; | ||
| const required: string[] = []; | ||
|
|
||
| if (!zodSchema?.shape) { | ||
| return { | ||
| name, | ||
| description, | ||
| parameters: {type: Type.OBJECT, properties, required}, | ||
| }; | ||
| } | ||
|
|
||
| for (const [key, zodType] of Object.entries(zodSchema.shape)) { | ||
| properties[key] = { | ||
| type: getJsonSchemaTypeFromZod(zodType), | ||
| description: zodType.description || '', | ||
| }; | ||
|
|
||
| if (!zodType.isOptional()) { | ||
| required.push(key); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| name, | ||
| description, | ||
| parameters: { | ||
| type: Type.OBJECT, | ||
| properties, | ||
| required, | ||
| }, | ||
| }; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.