feat(models): add Z.AI (GLM) credential integration and setup flow

Implement first-class Z.AI credential storage and authentication:

- New auth provider: src/auth/zai.ts for Z.AI API key management
- New CLI command: flynn zai-auth to store Z.AI API keys
- New TUI command: /login zai for interactive credential entry
- Modified src/auth/index.ts to register zai provider
- Modified src/cli/index.ts to register zai-auth command
- Modified src/cli/setup/providers.ts to include Z.AI in setup wizard
- Modified src/daemon/models.ts to support zhipuai use_oauth flag
- Modified src/daemon/clientFactory.test.ts to add Z.AI tests
- Modified src/frontends/tui/commands.ts to add login command
- Modified src/frontends/tui/minimal.ts to support credential prompts

This allows users to authenticate with Z.AI (GLM models) without
embedding secrets in config files. Credentials are stored securely in
~/.config/flynn/auth.json and resolved at runtime.

Updated state.json with new feature entry documenting the integration.
This commit is contained in:
William Valentin
2026-02-13 16:23:49 -08:00
parent 8a6cd7f559
commit 7df0569a39
10 changed files with 271 additions and 4 deletions
+20
View File
@@ -105,6 +105,26 @@ describe('createClientFromConfig', () => {
expect(client).toBeInstanceOf(OpenAIClient);
});
it('creates OpenAIClient for zhipuai when use_oauth is enabled and ZAI_API_KEY is set', () => {
const prev = process.env.ZAI_API_KEY;
process.env.ZAI_API_KEY = 'zai-api-key';
try {
const client = createClientFromConfig({
provider: 'zhipuai',
model: 'glm-4.7',
use_oauth: true,
});
expect(client).toBeInstanceOf(OpenAIClient);
} finally {
if (prev === undefined) {
delete process.env.ZAI_API_KEY;
} else {
process.env.ZAI_API_KEY = prev;
}
}
});
it('creates OpenAIClient for zhipuai using ZHIPUAI_AUTH_TOKEN env var', () => {
const prev = process.env.ZHIPUAI_AUTH_TOKEN;
process.env.ZHIPUAI_AUTH_TOKEN = 'oauth-access-token';