feat(sdk): implement runtime hooks support in GeminiCliAgent

- Introduced a new Hook type and hook() helper for strongly-typed SDK hooks.
- Integrated runtime hooks into GeminiCliSession lifecycle (startup, close, and tool execution).
- Added hooks option to GeminiCliAgentOptions.
- Exported executeToolWithHooks from core to facilitate SDK integration.
- Updated SDK_DESIGN.md to reflect implemented features and remaining tasks.
- Added and re-recorded SDK integration tests for hooks.
This commit is contained in:
Michael Bleigh
2026-02-25 13:44:16 -08:00
parent 4aec3cdb24
commit c7866e6a92
19 changed files with 564 additions and 82 deletions
@@ -1,2 +1,10 @@
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BAN"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10103,"totalTokenCount":10103,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10103}]}},{"candidates":[{"content":{"parts":[{"text":"ANA\n"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7168,"candidatesTokenCount":3,"totalTokenCount":7171,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7168}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA\n"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10124,"totalTokenCount":10124,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10124}]}},{"candidates":[{"content":{"parts":[{"text":""}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7187,"candidatesTokenCount":3,"totalTokenCount":7190,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7187}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BAN"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10019,"totalTokenCount":10019,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10019}]}},{"candidates":[{"content":{"parts":[{"text":"ANA\n"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7184,"candidatesTokenCount":3,"totalTokenCount":7187,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7184}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"The word is BAN"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10030,"totalTokenCount":10030,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10030}]}},{"candidates":[{"content":{"parts":[{"text":"ANA.\n"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7195,"candidatesTokenCount":7,"totalTokenCount":7202,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7195}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":7}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"The"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10157,"totalTokenCount":10157,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10157}]}},{"candidates":[{"content":{"parts":[{"text":" word is BANANA.\n"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7306,"candidatesTokenCount":7,"totalTokenCount":7313,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7306}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":7}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA\n"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10030,"totalTokenCount":10030,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10030}]}},{"candidates":[{"content":{"parts":[{"text":""}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7195,"candidatesTokenCount":3,"totalTokenCount":7198,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7195}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA\n"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10030,"totalTokenCount":10030,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10030}]}},{"candidates":[{"content":{"parts":[{"text":""}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7195,"candidatesTokenCount":3,"totalTokenCount":7198,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7195}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BAN"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10030,"totalTokenCount":10030,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10030}]}},{"candidates":[{"content":{"parts":[{"text":"ANA\n"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7195,"candidatesTokenCount":3,"totalTokenCount":7198,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7195}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA\n"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10030,"totalTokenCount":10030,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10030}]}},{"candidates":[{"content":{"parts":[{"text":""}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7195,"candidatesTokenCount":3,"totalTokenCount":7198,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7195}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA\n"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10040,"totalTokenCount":10040,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10040}]}},{"candidates":[{"content":{"parts":[{"text":""}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7203,"candidatesTokenCount":3,"totalTokenCount":7206,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7203}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA\n"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10030,"totalTokenCount":10030,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10030}]}},{"candidates":[{"content":{"parts":[{"text":""}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7195,"candidatesTokenCount":3,"totalTokenCount":7198,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7195}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":3}]}}]}
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"BANANA"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7203,"candidatesTokenCount":2,"totalTokenCount":7205,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7203}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":2}]}}]}