claude-flow-novice 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/cfn-loop/product-owner.md +54 -4
- package/.claude/commands/cfn-claude-sync.md +303 -0
- package/.claude/commands/cfn-loop-epic.md +290 -0
- package/.claude/commands/cfn-loop-single.md +168 -0
- package/.claude/commands/cfn-loop-sprints.md +384 -0
- package/.claude/commands/cfn-loop.md +180 -0
- package/.claude/commands/metrics-summary.md +58 -0
- package/.claude/commands/parse-epic.md +357 -0
- package/.claude/settings.json +4 -4
- package/.claude/settings.local.json +9 -2
- package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
- package/.claude-flow-novice/dist/mcp/server.js +21 -2
- package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
- package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
- package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
- package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
- package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
- package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
- package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
- package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
- package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
- package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
- package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
- package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
- package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
- package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
- package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
- package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
- package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
- package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
- package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
- package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
- package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
- package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
- package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
- package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
- package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
- package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
- package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
- package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
- package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
- package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
- package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
- package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
- package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
- package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
- package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
- package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
- package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
- package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
- package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
- package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
- package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
- package/.claude-flow-novice/metrics.db +0 -0
- package/.claude-flow-novice/metrics.db-shm +0 -0
- package/.claude-flow-novice/metrics.db-wal +0 -0
- package/CLAUDE.md +29 -0
- package/README.md +27 -0
- package/config/hooks/post-edit-pipeline.js +36 -2
- package/examples/metrics-counter-demo.ts +106 -0
- package/examples/persistent-metrics-demo.ts +83 -0
- package/examples/phase-5-multi-level-control.ts +282 -0
- package/examples/session-pool-optimizer-example.ts +311 -0
- package/package.json +15 -3
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/test-provider-routing.cjs +228 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
- package/src/observability/metrics-counter.ts +347 -0
- package/src/observability/metrics-storage.ts +356 -0
- package/src/observability/telemetry.ts +658 -0
- package/src/slash-commands/cfn-claude-sync.js +533 -0
- package/src/slash-commands/index.js +5 -0
- package/src/slash-commands/metrics-summary-class.js +74 -0
- package/src/slash-commands/metrics-summary.js +335 -0
- package/src/slash-commands/register-all-commands.js +12 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Direct Z.ai API Test
|
|
5
|
+
* Tests Z.ai API connectivity and response
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const http = require('http');
|
|
10
|
+
|
|
11
|
+
const API_KEY = process.env.Z_AI_API_KEY || process.env.ZAI_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
12
|
+
const BASE_URL = 'https://api.z.ai/api/anthropic';
|
|
13
|
+
const DEFAULT_MODEL = 'claude-3-5-sonnet-20241022';
|
|
14
|
+
|
|
15
|
+
function makeRequest(options, data) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const protocol = options.protocol === 'https:' ? https : http;
|
|
18
|
+
|
|
19
|
+
const req = protocol.request(options, (res) => {
|
|
20
|
+
let body = '';
|
|
21
|
+
|
|
22
|
+
res.on('data', (chunk) => {
|
|
23
|
+
body += chunk;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
res.on('end', () => {
|
|
27
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
28
|
+
try {
|
|
29
|
+
resolve({
|
|
30
|
+
statusCode: res.statusCode,
|
|
31
|
+
headers: res.headers,
|
|
32
|
+
body: JSON.parse(body)
|
|
33
|
+
});
|
|
34
|
+
} catch (e) {
|
|
35
|
+
resolve({
|
|
36
|
+
statusCode: res.statusCode,
|
|
37
|
+
headers: res.headers,
|
|
38
|
+
body: body
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
reject(new Error(`HTTP ${res.statusCode}: ${body}`));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
req.on('error', (error) => {
|
|
48
|
+
reject(error);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
req.setTimeout(30000, () => {
|
|
52
|
+
req.destroy();
|
|
53
|
+
reject(new Error('Request timeout after 30s'));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (data) {
|
|
57
|
+
req.write(data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
req.end();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function testZaiAPI() {
|
|
65
|
+
console.log('\n🧪 Z.ai API Direct Test\n');
|
|
66
|
+
console.log('='.repeat(80) + '\n');
|
|
67
|
+
|
|
68
|
+
// Check API key
|
|
69
|
+
if (!API_KEY) {
|
|
70
|
+
console.error('❌ ERROR: Z_AI_API_KEY or ZAI_API_KEY environment variable not set');
|
|
71
|
+
console.log('\nPlease set your Z.ai API key:');
|
|
72
|
+
console.log(' export ZAI_API_KEY="your-api-key-here"');
|
|
73
|
+
console.log(' or');
|
|
74
|
+
console.log(' ZAI_API_KEY="your-api-key-here" node scripts/test-zai-api.cjs\n');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('✓ API Key found:', API_KEY.substring(0, 10) + '...' + API_KEY.substring(API_KEY.length - 4));
|
|
79
|
+
console.log('✓ Base URL:', BASE_URL);
|
|
80
|
+
console.log('✓ Model:', DEFAULT_MODEL);
|
|
81
|
+
console.log('\n' + '-'.repeat(80) + '\n');
|
|
82
|
+
|
|
83
|
+
// Test payload (Anthropic Messages API format)
|
|
84
|
+
const payload = {
|
|
85
|
+
model: DEFAULT_MODEL,
|
|
86
|
+
max_tokens: 50,
|
|
87
|
+
messages: [
|
|
88
|
+
{
|
|
89
|
+
role: 'user',
|
|
90
|
+
content: 'Say "Hello from Z.ai!" and nothing else.'
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
console.log('📤 Sending request...\n');
|
|
96
|
+
console.log('Request payload:');
|
|
97
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
98
|
+
console.log('\n' + '-'.repeat(80) + '\n');
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const url = new URL(`${BASE_URL}/v1/messages`);
|
|
102
|
+
|
|
103
|
+
const options = {
|
|
104
|
+
hostname: url.hostname,
|
|
105
|
+
port: url.port || 443,
|
|
106
|
+
path: url.pathname,
|
|
107
|
+
method: 'POST',
|
|
108
|
+
protocol: url.protocol,
|
|
109
|
+
headers: {
|
|
110
|
+
'Content-Type': 'application/json',
|
|
111
|
+
'x-api-key': API_KEY,
|
|
112
|
+
'anthropic-version': '2023-06-01'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const startTime = Date.now();
|
|
117
|
+
const response = await makeRequest(options, JSON.stringify(payload));
|
|
118
|
+
const duration = Date.now() - startTime;
|
|
119
|
+
|
|
120
|
+
console.log('📥 Response received!\n');
|
|
121
|
+
console.log(`⏱️ Duration: ${duration}ms`);
|
|
122
|
+
console.log(`📊 Status: ${response.statusCode}`);
|
|
123
|
+
console.log('\n' + '-'.repeat(80) + '\n');
|
|
124
|
+
|
|
125
|
+
if (response.body.content && response.body.content.length > 0) {
|
|
126
|
+
console.log('✅ SUCCESS!\n');
|
|
127
|
+
console.log('Response content:');
|
|
128
|
+
console.log(' ' + response.body.content[0].text);
|
|
129
|
+
console.log('\nModel:', response.body.model);
|
|
130
|
+
console.log('Stop reason:', response.body.stop_reason);
|
|
131
|
+
|
|
132
|
+
if (response.body.usage) {
|
|
133
|
+
console.log('\nToken usage:');
|
|
134
|
+
console.log(' Input tokens: ', response.body.usage.input_tokens);
|
|
135
|
+
console.log(' Output tokens: ', response.body.usage.output_tokens);
|
|
136
|
+
|
|
137
|
+
// Calculate cost (Z.ai pricing: $0.003 per 1K prompt, $0.015 per 1K completion)
|
|
138
|
+
const promptCost = (response.body.usage.input_tokens / 1000) * 0.003;
|
|
139
|
+
const completionCost = (response.body.usage.output_tokens / 1000) * 0.015;
|
|
140
|
+
const totalCost = promptCost + completionCost;
|
|
141
|
+
|
|
142
|
+
console.log('\nEstimated cost:');
|
|
143
|
+
console.log(` Input: $${promptCost.toFixed(6)}`);
|
|
144
|
+
console.log(` Output: $${completionCost.toFixed(6)}`);
|
|
145
|
+
console.log(` Total: $${totalCost.toFixed(6)}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
console.log('\n' + '='.repeat(80));
|
|
149
|
+
console.log('\n✅ Z.ai API is working correctly!\n');
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
success: true,
|
|
153
|
+
response: response.body,
|
|
154
|
+
duration
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
console.log('⚠️ Warning: Unexpected response format');
|
|
158
|
+
console.log('\nFull response:');
|
|
159
|
+
console.log(JSON.stringify(response.body, null, 2));
|
|
160
|
+
console.log('\n' + '='.repeat(80) + '\n');
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: 'Unexpected response format',
|
|
165
|
+
response: response.body
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error('❌ ERROR:\n');
|
|
170
|
+
console.error(error.message);
|
|
171
|
+
|
|
172
|
+
if (error.message.includes('401')) {
|
|
173
|
+
console.log('\n💡 Tip: Check that your Z_AI_API_KEY is valid');
|
|
174
|
+
} else if (error.message.includes('429')) {
|
|
175
|
+
console.log('\n💡 Tip: Rate limit exceeded. Wait a moment and try again');
|
|
176
|
+
} else if (error.message.includes('ENOTFOUND') || error.message.includes('ECONNREFUSED')) {
|
|
177
|
+
console.log('\n💡 Tip: Check your internet connection');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
console.log('\n' + '='.repeat(80) + '\n');
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Run test
|
|
186
|
+
testZaiAPI()
|
|
187
|
+
.then(() => process.exit(0))
|
|
188
|
+
.catch((error) => {
|
|
189
|
+
console.error('\n❌ Unhandled error:', error);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Z.ai API Diagnostic Test
|
|
5
|
+
* Tests multiple endpoint variations
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
// Load .env
|
|
13
|
+
function loadEnv() {
|
|
14
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
15
|
+
if (!fs.existsSync(envPath)) return false;
|
|
16
|
+
|
|
17
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
18
|
+
envContent.split('\n').forEach(line => {
|
|
19
|
+
const trimmed = line.trim();
|
|
20
|
+
if (!trimmed || trimmed.startsWith('#')) return;
|
|
21
|
+
|
|
22
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
23
|
+
if (match) {
|
|
24
|
+
const key = match[1].trim();
|
|
25
|
+
let value = match[2].trim();
|
|
26
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
27
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
28
|
+
value = value.slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
process.env[key] = value;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
loadEnv();
|
|
37
|
+
|
|
38
|
+
const API_KEY = process.env.ZAI_API_KEY || process.env.Z_AI_API_KEY;
|
|
39
|
+
|
|
40
|
+
if (!API_KEY) {
|
|
41
|
+
console.error('❌ No API key found');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log('\n🔍 Z.ai API Diagnostic Test\n');
|
|
46
|
+
console.log('='.repeat(80));
|
|
47
|
+
console.log('\n✓ API Key:', API_KEY.substring(0, 15) + '...' + API_KEY.substring(API_KEY.length - 4));
|
|
48
|
+
|
|
49
|
+
// Test different endpoints and models
|
|
50
|
+
const tests = [
|
|
51
|
+
{
|
|
52
|
+
name: 'GLM-4.6 via /v1/chat/completions',
|
|
53
|
+
url: 'https://api.z.ai/v1/chat/completions',
|
|
54
|
+
model: 'glm-4.6'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'GLM-4-Flash via /v1/chat/completions',
|
|
58
|
+
url: 'https://api.z.ai/v1/chat/completions',
|
|
59
|
+
model: 'glm-4-flash'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'Claude via /v1/chat/completions',
|
|
63
|
+
url: 'https://api.z.ai/v1/chat/completions',
|
|
64
|
+
model: 'claude-3-5-sonnet-20241022'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Check /v1/models endpoint',
|
|
68
|
+
url: 'https://api.z.ai/v1/models',
|
|
69
|
+
method: 'GET'
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
function testEndpoint(test) {
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
const url = new URL(test.url);
|
|
76
|
+
|
|
77
|
+
const options = {
|
|
78
|
+
hostname: url.hostname,
|
|
79
|
+
port: 443,
|
|
80
|
+
path: url.pathname,
|
|
81
|
+
method: test.method || 'POST',
|
|
82
|
+
headers: {
|
|
83
|
+
'Authorization': `Bearer ${API_KEY}`,
|
|
84
|
+
'Content-Type': 'application/json'
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let data = null;
|
|
89
|
+
if (test.method !== 'GET') {
|
|
90
|
+
data = JSON.stringify({
|
|
91
|
+
model: test.model,
|
|
92
|
+
messages: [{ role: 'user', content: 'Hi' }],
|
|
93
|
+
max_tokens: 10
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const req = https.request(options, (res) => {
|
|
98
|
+
let body = '';
|
|
99
|
+
res.on('data', chunk => body += chunk);
|
|
100
|
+
res.on('end', () => {
|
|
101
|
+
resolve({
|
|
102
|
+
status: res.statusCode,
|
|
103
|
+
body: body.substring(0, 500)
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
req.on('error', (error) => {
|
|
109
|
+
resolve({ status: 'ERROR', error: error.message });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
req.setTimeout(15000, () => {
|
|
113
|
+
req.destroy();
|
|
114
|
+
resolve({ status: 'TIMEOUT' });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (data) req.write(data);
|
|
118
|
+
req.end();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function runDiagnostics() {
|
|
123
|
+
for (const test of tests) {
|
|
124
|
+
console.log(`\n${'─'.repeat(80)}`);
|
|
125
|
+
console.log(`\n📍 ${test.name}`);
|
|
126
|
+
console.log(` URL: ${test.url}`);
|
|
127
|
+
if (test.model) console.log(` Model: ${test.model}`);
|
|
128
|
+
|
|
129
|
+
const result = await testEndpoint(test);
|
|
130
|
+
|
|
131
|
+
if (result.status === 'ERROR') {
|
|
132
|
+
console.log(` ❌ Error: ${result.error}`);
|
|
133
|
+
} else if (result.status === 'TIMEOUT') {
|
|
134
|
+
console.log(` ⏱️ Timeout`);
|
|
135
|
+
} else if (result.status === 200 || result.status === 201) {
|
|
136
|
+
console.log(` ✅ Success (${result.status})`);
|
|
137
|
+
console.log(` Response: ${result.body.substring(0, 200)}...`);
|
|
138
|
+
} else {
|
|
139
|
+
console.log(` ⚠️ Status: ${result.status}`);
|
|
140
|
+
console.log(` Response: ${result.body.substring(0, 200)}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
console.log('\n' + '='.repeat(80));
|
|
145
|
+
console.log('\n💡 Recommendations:');
|
|
146
|
+
console.log(' - Check Z.ai documentation for correct endpoint structure');
|
|
147
|
+
console.log(' - Verify API key permissions');
|
|
148
|
+
console.log(' - Confirm supported models list\n');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
runDiagnostics().catch(console.error);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Final Z.ai API Verification Test
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const https = require('https');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
// Load .env
|
|
12
|
+
function loadEnv() {
|
|
13
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
14
|
+
if (!fs.existsSync(envPath)) return false;
|
|
15
|
+
|
|
16
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
17
|
+
envContent.split('\n').forEach(line => {
|
|
18
|
+
const trimmed = line.trim();
|
|
19
|
+
if (!trimmed || trimmed.startsWith('#')) return;
|
|
20
|
+
|
|
21
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
22
|
+
if (match) {
|
|
23
|
+
const key = match[1].trim();
|
|
24
|
+
let value = match[2].trim();
|
|
25
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
26
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
27
|
+
value = value.slice(1, -1);
|
|
28
|
+
}
|
|
29
|
+
process.env[key] = value;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
loadEnv();
|
|
36
|
+
|
|
37
|
+
const API_KEY = process.env.ZAI_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
38
|
+
|
|
39
|
+
function makeRequest(url, payload) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const urlObj = new URL(url);
|
|
42
|
+
|
|
43
|
+
const options = {
|
|
44
|
+
hostname: urlObj.hostname,
|
|
45
|
+
port: 443,
|
|
46
|
+
path: urlObj.pathname,
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'x-api-key': API_KEY,
|
|
51
|
+
'anthropic-version': '2023-06-01'
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const req = https.request(options, (res) => {
|
|
56
|
+
let body = '';
|
|
57
|
+
res.on('data', chunk => body += chunk);
|
|
58
|
+
res.on('end', () => {
|
|
59
|
+
try {
|
|
60
|
+
resolve({ status: res.statusCode, body: JSON.parse(body) });
|
|
61
|
+
} catch (e) {
|
|
62
|
+
resolve({ status: res.statusCode, body });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
req.on('error', reject);
|
|
68
|
+
req.setTimeout(30000, () => {
|
|
69
|
+
req.destroy();
|
|
70
|
+
reject(new Error('Timeout'));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
req.write(JSON.stringify(payload));
|
|
74
|
+
req.end();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function test() {
|
|
79
|
+
console.log('\n🎯 Z.ai API Final Verification\n');
|
|
80
|
+
console.log('='.repeat(80) + '\n');
|
|
81
|
+
|
|
82
|
+
const tests = [
|
|
83
|
+
{
|
|
84
|
+
name: 'Test 1: Simple greeting (10K tokens)',
|
|
85
|
+
payload: {
|
|
86
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
87
|
+
max_tokens: 10000,
|
|
88
|
+
messages: [{ role: 'user', content: 'Reply with exactly: "Hello from Z.ai GLM-4.6!"' }]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'Test 2: Code generation (10K tokens)',
|
|
93
|
+
payload: {
|
|
94
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
95
|
+
max_tokens: 10000,
|
|
96
|
+
messages: [{ role: 'user', content: 'Write a complete JavaScript class for managing a todo list with add, remove, and list methods. Include comments.' }]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
for (const test of tests) {
|
|
102
|
+
console.log(`📋 ${test.name}`);
|
|
103
|
+
console.log('-'.repeat(80));
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const result = await makeRequest('https://api.z.ai/api/anthropic/v1/messages', test.payload);
|
|
107
|
+
|
|
108
|
+
if (result.status === 200) {
|
|
109
|
+
console.log('✅ Success!');
|
|
110
|
+
console.log('Response:', result.body.content?.[0]?.text || result.body.content || 'Empty response');
|
|
111
|
+
console.log('Model:', result.body.model);
|
|
112
|
+
console.log('Tokens:', `${result.body.usage?.input_tokens || 0} in, ${result.body.usage?.output_tokens || 0} out`);
|
|
113
|
+
} else {
|
|
114
|
+
console.log('⚠️ Status:', result.status);
|
|
115
|
+
console.log('Body:', JSON.stringify(result.body, null, 2).substring(0, 200));
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.log('❌ Error:', error.message);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log('');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log('='.repeat(80));
|
|
125
|
+
console.log('\n✅ Z.ai API verification complete!\n');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
test();
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Z.ai API Test with .env loading
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
// Load .env file
|
|
11
|
+
function loadEnv() {
|
|
12
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(envPath)) {
|
|
15
|
+
console.error('❌ .env file not found in:', process.cwd());
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
21
|
+
const lines = envContent.split('\n');
|
|
22
|
+
|
|
23
|
+
for (const line of lines) {
|
|
24
|
+
const trimmed = line.trim();
|
|
25
|
+
|
|
26
|
+
// Skip comments and empty lines
|
|
27
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
28
|
+
|
|
29
|
+
// Parse KEY=VALUE
|
|
30
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
31
|
+
if (match) {
|
|
32
|
+
const key = match[1].trim();
|
|
33
|
+
let value = match[2].trim();
|
|
34
|
+
|
|
35
|
+
// Remove quotes if present
|
|
36
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
37
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
38
|
+
value = value.slice(1, -1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
process.env[key] = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('❌ Error loading .env:', error.message);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Load environment
|
|
53
|
+
console.log('📁 Loading .env file...');
|
|
54
|
+
if (!loadEnv()) {
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Check for Z_AI_API_KEY or ZAI_API_KEY
|
|
59
|
+
if (process.env.Z_AI_API_KEY || process.env.ZAI_API_KEY) {
|
|
60
|
+
const key = process.env.Z_AI_API_KEY || process.env.ZAI_API_KEY;
|
|
61
|
+
const keyName = process.env.Z_AI_API_KEY ? 'Z_AI_API_KEY' : 'ZAI_API_KEY';
|
|
62
|
+
console.log(`✓ ${keyName} loaded from .env`);
|
|
63
|
+
console.log(' Key preview:', key.substring(0, 10) + '...\n');
|
|
64
|
+
} else {
|
|
65
|
+
console.error('❌ Z_AI_API_KEY or ZAI_API_KEY not found in .env file');
|
|
66
|
+
console.log('\nSearching for Z.ai related keys in .env...');
|
|
67
|
+
|
|
68
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
69
|
+
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
70
|
+
const zaiKeys = envContent.split('\n').filter(line =>
|
|
71
|
+
line.toLowerCase().includes('z_ai') || line.toLowerCase().includes('zai')
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (zaiKeys.length > 0) {
|
|
75
|
+
console.log('Found:', zaiKeys.join('\n'));
|
|
76
|
+
} else {
|
|
77
|
+
console.log('No Z.ai related keys found');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Now run the actual test
|
|
84
|
+
console.log('🚀 Starting Z.ai API test...\n');
|
|
85
|
+
require('./test-zai-api.cjs');
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Validation script for coordination version CLI integration
|
|
4
|
+
* Phase 11: V1/V2 Toggle - CLI Integration
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Test 1: Default to v2
|
|
8
|
+
console.log('Test 1: Default to v2');
|
|
9
|
+
delete process.env.COORDINATION_VERSION;
|
|
10
|
+
const test1 = (undefined || process.env.COORDINATION_VERSION || 'v2').toLowerCase();
|
|
11
|
+
console.assert(test1 === 'v2', `Expected 'v2', got '${test1}'`);
|
|
12
|
+
console.log('✅ PASS: Defaults to v2\n');
|
|
13
|
+
|
|
14
|
+
// Test 2: CLI flag takes precedence
|
|
15
|
+
console.log('Test 2: CLI flag takes precedence');
|
|
16
|
+
process.env.COORDINATION_VERSION = 'v1';
|
|
17
|
+
const cliFlag = 'v2';
|
|
18
|
+
const test2 = (cliFlag || process.env.COORDINATION_VERSION || 'v2').toLowerCase();
|
|
19
|
+
console.assert(test2 === 'v2', `Expected 'v2', got '${test2}'`);
|
|
20
|
+
console.log('✅ PASS: CLI flag overrides env var\n');
|
|
21
|
+
|
|
22
|
+
// Test 3: Environment variable fallback
|
|
23
|
+
console.log('Test 3: Environment variable fallback');
|
|
24
|
+
process.env.COORDINATION_VERSION = 'v1';
|
|
25
|
+
const test3 = (undefined || process.env.COORDINATION_VERSION || 'v2').toLowerCase();
|
|
26
|
+
console.assert(test3 === 'v1', `Expected 'v1', got '${test3}'`);
|
|
27
|
+
console.log('✅ PASS: Uses env var when no CLI flag\n');
|
|
28
|
+
|
|
29
|
+
// Test 4: Case insensitive
|
|
30
|
+
console.log('Test 4: Case insensitive');
|
|
31
|
+
const test4 = 'V1'.toLowerCase();
|
|
32
|
+
console.assert(test4 === 'v1', `Expected 'v1', got '${test4}'`);
|
|
33
|
+
console.log('✅ PASS: Handles uppercase input\n');
|
|
34
|
+
|
|
35
|
+
// Test 5: Validation logic
|
|
36
|
+
console.log('Test 5: Version validation');
|
|
37
|
+
const validVersions = ['v1', 'v2'];
|
|
38
|
+
const test5a = validVersions.includes('v1');
|
|
39
|
+
const test5b = validVersions.includes('v2');
|
|
40
|
+
const test5c = validVersions.includes('v3');
|
|
41
|
+
console.assert(test5a === true, 'v1 should be valid');
|
|
42
|
+
console.assert(test5b === true, 'v2 should be valid');
|
|
43
|
+
console.assert(test5c === false, 'v3 should be invalid');
|
|
44
|
+
console.log('✅ PASS: Validation logic correct\n');
|
|
45
|
+
|
|
46
|
+
// Test 6: Options object structure
|
|
47
|
+
console.log('Test 6: Options object structure');
|
|
48
|
+
const coordinationVersion = 'v2';
|
|
49
|
+
const options = {
|
|
50
|
+
strategy: 'auto',
|
|
51
|
+
maxAgents: 5,
|
|
52
|
+
coordinationVersion: coordinationVersion,
|
|
53
|
+
};
|
|
54
|
+
console.assert(options.coordinationVersion === 'v2', `Expected 'v2', got '${options.coordinationVersion}'`);
|
|
55
|
+
console.assert(options.hasOwnProperty('coordinationVersion'), 'Options should have coordinationVersion property');
|
|
56
|
+
console.log('✅ PASS: Options object includes coordinationVersion\n');
|
|
57
|
+
|
|
58
|
+
console.log('================================================');
|
|
59
|
+
console.log('✅ ALL TESTS PASSED');
|
|
60
|
+
console.log('================================================');
|
|
61
|
+
console.log('\nCLI Integration Summary:');
|
|
62
|
+
console.log('- ✅ --coordination-version flag support added');
|
|
63
|
+
console.log('- ✅ COORDINATION_VERSION env var support added');
|
|
64
|
+
console.log('- ✅ Default to v2 when neither is provided');
|
|
65
|
+
console.log('- ✅ CLI flag takes precedence over env var');
|
|
66
|
+
console.log('- ✅ Case-insensitive input handling');
|
|
67
|
+
console.log('- ✅ Input validation (v1 or v2 only)');
|
|
68
|
+
console.log('- ✅ coordinationVersion included in options object');
|
|
69
|
+
console.log('\nReady for Phase 11 CoordinationToggle integration!');
|