claude-flow-novice 2.2.4 → 2.2.5

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.
Files changed (288) hide show
  1. package/package.json +9 -8
  2. package/scripts/.claude-flow/metrics/agent-metrics.json +1 -0
  3. package/scripts/.claude-flow/metrics/performance.json +9 -0
  4. package/scripts/.claude-flow/metrics/task-metrics.json +10 -0
  5. package/scripts/CLEANUP_OPTIMIZATION_REPORT.json +312 -0
  6. package/scripts/CLEANUP_PERFORMANCE_OPTIMIZATION.md +387 -0
  7. package/scripts/CLEANUP_QUICK_START.md +268 -0
  8. package/scripts/CLEANUP_TEST_RESULTS.md +205 -0
  9. package/scripts/README.md +339 -0
  10. package/scripts/ace-query.sh +384 -0
  11. package/scripts/agent-token-analysis.js +430 -0
  12. package/scripts/auto-setup.js +332 -0
  13. package/scripts/build/README.md +167 -0
  14. package/scripts/build/build-config.js +27 -0
  15. package/scripts/build/build-prompt-copier.sh +30 -0
  16. package/scripts/build/performance-monitor.js +869 -0
  17. package/scripts/build/prepare-publish.js +150 -0
  18. package/scripts/build/typescript-fixer.js +621 -0
  19. package/scripts/build/unified-builder.sh +428 -0
  20. package/scripts/build/update-bin-version.js +32 -0
  21. package/scripts/build/validate-agents.js +238 -0
  22. package/scripts/build-index.js +43 -0
  23. package/scripts/build-orchestrator.js +320 -0
  24. package/scripts/check-routing-stats.cjs +122 -0
  25. package/scripts/ci-validation.js +375 -0
  26. package/scripts/cleanup-blocking-coordination.sh +420 -0
  27. package/scripts/cleanup-idle-sessions.sh +59 -0
  28. package/scripts/collect-build-metrics.js +65 -0
  29. package/scripts/demo/README.md +79 -0
  30. package/scripts/demo/autoscaling-demo-simplified.js +963 -0
  31. package/scripts/demo/comprehensive-dashboard-test.js +693 -0
  32. package/scripts/demo/confidence-log.js +87 -0
  33. package/scripts/demo/confidence-report.js +82 -0
  34. package/scripts/demo/demo-multi-swarm-coordination.js +325 -0
  35. package/scripts/demo/demo-production-deployment.js +399 -0
  36. package/scripts/demo/demo-visualization-system.js +149 -0
  37. package/scripts/demo/performance-analysis.cjs +71 -0
  38. package/scripts/demo/performance-analysis.js +71 -0
  39. package/scripts/demo/test-autoscaling-demo.js +314 -0
  40. package/scripts/dependency-optimizer.js +349 -0
  41. package/scripts/dependency-security-assessment.js +331 -0
  42. package/scripts/deploy-sdk.sh +176 -0
  43. package/scripts/deployment-readiness-report.json +179 -0
  44. package/scripts/dev/README.md +264 -0
  45. package/scripts/dev/claude-flow-wrapper.sh +35 -0
  46. package/scripts/dev/claude-monitor.py +419 -0
  47. package/scripts/dev/claude-sparc.sh +562 -0
  48. package/scripts/dev/claude-wrapper.sh +17 -0
  49. package/scripts/dev/demo-phase3-compliance.js +172 -0
  50. package/scripts/dev/demo-task-system.ts +224 -0
  51. package/scripts/dev/deployment-validator.js +315 -0
  52. package/scripts/dev/spawn-claude-terminal.sh +32 -0
  53. package/scripts/dev/start-portal.sh +506 -0
  54. package/scripts/dev/start-web-ui.js +15 -0
  55. package/scripts/dev/stop-portal.sh +311 -0
  56. package/scripts/dev/validate-examples.ts +288 -0
  57. package/scripts/dev/validate-phase2.cjs +451 -0
  58. package/scripts/dev/validate-phase2.js +785 -0
  59. package/scripts/dev/validate-phase3.cjs +208 -0
  60. package/scripts/dev/validate-security-remediation.js +1 -0
  61. package/scripts/ecosystem.config.cjs +90 -0
  62. package/scripts/fix-js-extensions.js +167 -0
  63. package/scripts/generate-basic-types.js +73 -0
  64. package/scripts/generate-changelog.js +318 -0
  65. package/scripts/git-hooks/pre-commit.sh +143 -0
  66. package/scripts/health-checks.js +634 -0
  67. package/scripts/hook-wrapper.sh +54 -0
  68. package/scripts/install/README.md +375 -0
  69. package/scripts/install/REDIS_SETUP_VALIDATION.json +245 -0
  70. package/scripts/install/check-prerequisites.js +303 -0
  71. package/scripts/install/config-wizard.js +606 -0
  72. package/scripts/install/dependency-checker.js +385 -0
  73. package/scripts/install/health-check.js +765 -0
  74. package/scripts/install/install.js +256 -0
  75. package/scripts/install/installation-benchmark.js +461 -0
  76. package/scripts/install/quick-install.js +720 -0
  77. package/scripts/install/quick-start-wizard.js +295 -0
  78. package/scripts/install/redis-cli.js +289 -0
  79. package/scripts/install/redis-install-guides.md +407 -0
  80. package/scripts/install/redis-setup.js +559 -0
  81. package/scripts/install/redis-test.js +278 -0
  82. package/scripts/install/service-manager.js +672 -0
  83. package/scripts/install/setup.js +832 -0
  84. package/scripts/install/uninstall.js +526 -0
  85. package/scripts/install/update.js +461 -0
  86. package/scripts/install-pre-commit-hook.sh +127 -0
  87. package/scripts/legacy/README.md +272 -0
  88. package/scripts/legacy/batch-fix-ts.sh +54 -0
  89. package/scripts/legacy/build-migration.sh +105 -0
  90. package/scripts/legacy/build-monitor.js +209 -0
  91. package/scripts/legacy/build-with-filter.sh +84 -0
  92. package/scripts/legacy/build-workaround.sh +71 -0
  93. package/scripts/legacy/fix-ts-advanced.js +358 -0
  94. package/scripts/legacy/fix-ts-final.sh +50 -0
  95. package/scripts/legacy/fix-ts-targeted.sh +49 -0
  96. package/scripts/legacy/fix-typescript-errors.js +305 -0
  97. package/scripts/legacy/force-build.sh +63 -0
  98. package/scripts/legacy/optimize-performance.js +400 -0
  99. package/scripts/legacy/performance-monitor.js +263 -0
  100. package/scripts/legacy/performance-monitoring.js +532 -0
  101. package/scripts/legacy/performance-test-runner.js +645 -0
  102. package/scripts/legacy/quick-fix-ts.js +281 -0
  103. package/scripts/legacy/safe-build.sh +63 -0
  104. package/scripts/memory-monitor-coordinator.js +322 -0
  105. package/scripts/migrate-to-sdk.sh +520 -0
  106. package/scripts/migration/QUICK-START.md +189 -0
  107. package/scripts/migration/QUICK-START.md.backup-1760135091363 +189 -0
  108. package/scripts/migration/README.md +464 -0
  109. package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md +500 -0
  110. package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md.backup-1760135091348 +500 -0
  111. package/scripts/migration/UPDATE-PATHS-README.md +464 -0
  112. package/scripts/migration/UPDATE-PATHS-README.md.backup-1760135091337 +464 -0
  113. package/scripts/migration/example-patterns.json +19 -0
  114. package/scripts/migration/install-arm64.js +78 -0
  115. package/scripts/migration/install.js +83 -0
  116. package/scripts/migration/migrate-hooks.js +173 -0
  117. package/scripts/migration/migration-examples.ts +318 -0
  118. package/scripts/migration/reorganize-workspace.js +504 -0
  119. package/scripts/migration/test-update-paths.js +359 -0
  120. package/scripts/migration/update-paths.js +664 -0
  121. package/scripts/migration/validate-migration.js +647 -0
  122. package/scripts/monitor-loop.sh +65 -0
  123. package/scripts/monitor-memory.sh +47 -0
  124. package/scripts/monitor-migration.js +339 -0
  125. package/scripts/monitor.py +43 -0
  126. package/scripts/monitoring/README.md +178 -0
  127. package/scripts/monitoring/alert-monitor.sh +220 -0
  128. package/scripts/monitoring/analyze-resources.sh +199 -0
  129. package/scripts/monitoring/dashboards/rate-limiting-dashboard.json +211 -0
  130. package/scripts/monitoring/dynamic-monitor.sh +85 -0
  131. package/scripts/monitoring/launch-stability-test.sh +184 -0
  132. package/scripts/monitoring/monitor-test.sh +93 -0
  133. package/scripts/monitoring/pre-test-validation.sh +208 -0
  134. package/scripts/monitoring/quick-test-alerting.sh +118 -0
  135. package/scripts/monitoring/quick-test-rate-limiting.sh +206 -0
  136. package/scripts/monitoring/rate-limiting-monitor.sh +380 -0
  137. package/scripts/monitoring/resource-monitor.sh +126 -0
  138. package/scripts/monitoring/stability-monitor.js +429 -0
  139. package/scripts/monitoring/test-monitor-quick.sh +54 -0
  140. package/scripts/monitoring/view-alerts.sh +307 -0
  141. package/scripts/npm-metrics-collector.js +482 -0
  142. package/scripts/npm-package-validation.cjs +299 -0
  143. package/scripts/optimization/build-optimizer.js +438 -0
  144. package/scripts/optimization/config-validator.js +761 -0
  145. package/scripts/optimization/test-optimization.js +432 -0
  146. package/scripts/optimization/unified-activation.js +839 -0
  147. package/scripts/optimize-package-swarm.js +54 -0
  148. package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
  149. package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
  150. package/scripts/performance/test-enhanced-backend.sh +504 -0
  151. package/scripts/performance-monitor.js +644 -0
  152. package/scripts/performance-test-runner.js +698 -0
  153. package/scripts/post-deployment-monitoring.js +350 -0
  154. package/scripts/post-edit-pipeline.js +2091 -0
  155. package/scripts/post-install-claude-md.js +78 -0
  156. package/scripts/postinstall.js +79 -0
  157. package/scripts/pre-publish-validation.cjs +212 -0
  158. package/scripts/pre-publish-validation.js +429 -0
  159. package/scripts/redis-lua/cleanup-blocking-coordination.lua +198 -0
  160. package/scripts/release-announcement.js +425 -0
  161. package/scripts/release-notification.js +248 -0
  162. package/scripts/release-rollback.js +376 -0
  163. package/scripts/release-validation.js +460 -0
  164. package/scripts/rollback-sdk.sh +66 -0
  165. package/scripts/run-production-validation.ts +590 -0
  166. package/scripts/run-stability-validation.sh +687 -0
  167. package/scripts/security/README.md +339 -0
  168. package/scripts/security/deployment-validation.cjs +279 -0
  169. package/scripts/security/envelope-encryption-confidence-report.cjs +422 -0
  170. package/scripts/security/install-git-hooks.sh +132 -0
  171. package/scripts/security/install-git-secrets.sh +295 -0
  172. package/scripts/security/rotate-api-keys.js +469 -0
  173. package/scripts/security/ruv-swarm-safe.js +74 -0
  174. package/scripts/security/security-audit.cjs +538 -0
  175. package/scripts/security/setup-redis-auth.sh +397 -0
  176. package/scripts/security/validate-envelope-encryption.cjs +340 -0
  177. package/scripts/security-scan.js +492 -0
  178. package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
  179. package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
  180. package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
  181. package/scripts/switch-api.sh +158 -0
  182. package/scripts/sync-agents.js +290 -0
  183. package/scripts/test/50-agent-test.js +625 -0
  184. package/scripts/test/NEW_STABILITY_TEST_GUIDE.md +407 -0
  185. package/scripts/test/README.md +236 -0
  186. package/scripts/test/STABILITY_TEST_EXAMPLE.md +347 -0
  187. package/scripts/test/STABILITY_TEST_README.md +480 -0
  188. package/scripts/test/agent-worker.js +309 -0
  189. package/scripts/test/ai-coordination-test.js +650 -0
  190. package/scripts/test/ai-mesh-coordination-test.js +416 -0
  191. package/scripts/test/check-links.ts +274 -0
  192. package/scripts/test/check-performance-regression.ts +168 -0
  193. package/scripts/test/cli-agent-coordination-test.js +313 -0
  194. package/scripts/test/coordinator-multilingual-test.js +396 -0
  195. package/scripts/test/coordinator-transparency-demo.js +585 -0
  196. package/scripts/test/coverage-report.ts +692 -0
  197. package/scripts/test/generate-swarm-tests.js +633 -0
  198. package/scripts/test/integration-test-validation.cjs +253 -0
  199. package/scripts/test/load-test-swarm.js +576 -0
  200. package/scripts/test/mesh-coordination-zero-overlap-test.js +740 -0
  201. package/scripts/test/multilingual-hello-world-test.js +390 -0
  202. package/scripts/test/quick-multilingual-demo.js +464 -0
  203. package/scripts/test/real-agent-test.js +312 -0
  204. package/scripts/test/run-phase3-compliance-tests.js +427 -0
  205. package/scripts/test/run-stability-test-examples.sh +292 -0
  206. package/scripts/test/stability-results/stability-metrics.jsonl +83 -0
  207. package/scripts/test/stability-results/stability-test-report.json +128 -0
  208. package/scripts/test/stability-results/stability-test.log +1827 -0
  209. package/scripts/test/stability-test-50-agents.js +734 -0
  210. package/scripts/test/test-batch-tasks.ts +29 -0
  211. package/scripts/test/test-byzantine-resolution.js +246 -0
  212. package/scripts/test/test-claude-spawn-options.sh +63 -0
  213. package/scripts/test/test-cli-wizard.js +331 -0
  214. package/scripts/test/test-comprehensive.js +401 -0
  215. package/scripts/test/test-coordination-features.ts +238 -0
  216. package/scripts/test/test-fallback-systems.js +276 -0
  217. package/scripts/test/test-init-command.ts +302 -0
  218. package/scripts/test/test-mcp.ts +251 -0
  219. package/scripts/test/test-runner.ts +568 -0
  220. package/scripts/test/test-swarm-integration.sh +92 -0
  221. package/scripts/test/test-swarm.ts +142 -0
  222. package/scripts/test/validation-summary.ts +408 -0
  223. package/scripts/test-cleanup-performance.sh +416 -0
  224. package/scripts/test-dashboard-auth.cjs +203 -0
  225. package/scripts/test-docker-deployment.sh +207 -0
  226. package/scripts/test-npm-package.cjs +167 -0
  227. package/scripts/test-provider-routing.cjs +226 -0
  228. package/scripts/test-routing-telemetry.cjs +147 -0
  229. package/scripts/test-runner.cjs +154 -0
  230. package/scripts/test-zai-10k.cjs +81 -0
  231. package/scripts/test-zai-api.cjs +191 -0
  232. package/scripts/test-zai-diagnostic.cjs +151 -0
  233. package/scripts/test-zai-final.cjs +128 -0
  234. package/scripts/test-zai-with-env.cjs +85 -0
  235. package/scripts/utils/README.md +261 -0
  236. package/scripts/utils/clean-build-artifacts.sh +94 -0
  237. package/scripts/utils/cleanup-root.sh +69 -0
  238. package/scripts/utils/fix-cliffy-imports.js +307 -0
  239. package/scripts/utils/fix-duplicate-imports.js +114 -0
  240. package/scripts/utils/fix-error-handling.cjs +70 -0
  241. package/scripts/utils/fix-import-paths.js +104 -0
  242. package/scripts/utils/fix-imports.js +116 -0
  243. package/scripts/utils/fix-shebang.js +78 -0
  244. package/scripts/utils/fix-test-modules.js +27 -0
  245. package/scripts/utils/fix-timezone-issue-246.js +200 -0
  246. package/scripts/utils/fix-ts-comprehensive.py +182 -0
  247. package/scripts/utils/fix-ts-targeted-batch.js +250 -0
  248. package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
  249. package/scripts/utils/simple-test-fixer.js +190 -0
  250. package/scripts/utils/validate-metrics-structure.cjs +144 -0
  251. package/scripts/validate-agent-hooks.js +506 -0
  252. package/scripts/validate-changelog.js +241 -0
  253. package/scripts/validate-coordination-cli.js +69 -0
  254. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  255. package/scripts/validate-docker-infrastructure.sh +502 -0
  256. package/scripts/validate-entry-points.js +300 -0
  257. package/scripts/validate-stage3-performance.ts +377 -0
  258. package/scripts/validate-template-bundling.js +180 -0
  259. package/scripts/validation/README.md +33 -0
  260. package/scripts/validation/acl-security-validation.cjs +214 -0
  261. package/scripts/validation/acl-security-validation.js +402 -0
  262. package/scripts/validation/byzantine-verification.js +407 -0
  263. package/scripts/validation/final-phase-2-consensus.cjs +219 -0
  264. package/scripts/validation/final-security-validation.js +791 -0
  265. package/scripts/validation/final-wasm-validation.cjs +840 -0
  266. package/scripts/validation/integration-test-analysis.js +105 -0
  267. package/scripts/validation/phase-0-comprehensive-validation.js +474 -0
  268. package/scripts/validation/phase-0-consensus-report.js +139 -0
  269. package/scripts/validation/phase-0-final-report.js +112 -0
  270. package/scripts/validation/phase-0-redis-consensus-report.js +129 -0
  271. package/scripts/validation/phase-0-validation-improved.js +490 -0
  272. package/scripts/validation/phase-0-validation-test.js +65 -0
  273. package/scripts/validation/phase-1-consensus-report.cjs +342 -0
  274. package/scripts/validation/phase-1-consensus-validation.cjs +551 -0
  275. package/scripts/validation/phase-1-consensus-validation.js +551 -0
  276. package/scripts/validation/phase-2-consensus-report.cjs +186 -0
  277. package/scripts/validation/phase-2-validation.cjs +171 -0
  278. package/scripts/validation/phase-2-validation.js +171 -0
  279. package/scripts/validation/phase-4-consensus-report.js +181 -0
  280. package/scripts/validation/phase-4-final-validation.js +351 -0
  281. package/scripts/validation/phase-5-consensus-report.cjs +113 -0
  282. package/scripts/validation/phase-5-consensus-report.js +113 -0
  283. package/scripts/validation/security-analysis.js +49 -0
  284. package/scripts/validation/security-validation.js +492 -0
  285. package/scripts/validation/simple-security-validation.js +464 -0
  286. package/scripts/verify-installation.js +112 -0
  287. package/scripts/verify-mcp-server.js +86 -0
  288. package/scripts/verify-sdk-phase1.cjs +293 -0
@@ -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,261 @@
1
+ # Utility Scripts
2
+
3
+ This directory contains general utility scripts for maintenance, fixes, and system operations.
4
+
5
+ ## Scripts
6
+
7
+ ### Code Fixing Utilities
8
+
9
+ #### Import & Module Fixes
10
+ - **`fix-import-paths.js`** - Fixes import path issues across the codebase
11
+ - **`fix-imports.js`** - General import statement fixes and optimizations
12
+ - **`fix-duplicate-imports.js`** - Removes duplicate import statements
13
+ - **`fix-cliffy-imports.js`** - Fixes specific Cliffy CLI library import issues
14
+
15
+ #### TypeScript Fixes
16
+ - **`fix-ts-comprehensive.py`** - Comprehensive TypeScript error resolution
17
+ - **`fix-ts-targeted-batch.js`** - Targeted TypeScript fixes in batches
18
+ - **`fix-test-modules.js`** - Fixes test module imports and configurations
19
+
20
+ #### General Code Fixes
21
+ - **`fix-shebang.js`** - Fixes shebang lines in script files
22
+ - **`fix-error-handling.cjs`** - Improves error handling patterns
23
+ - **`fix-timezone-issue-246.js`** - Fixes specific timezone handling issue
24
+ - **`simple-test-fixer.js`** - Simple test file fixes and corrections
25
+
26
+ ### Cleanup & Maintenance
27
+
28
+ #### Build Cleanup
29
+ - **`clean-build-artifacts.sh`** - Removes build artifacts and temporary files
30
+ - **`cleanup-root.sh`** - Cleans up root directory of unnecessary files
31
+ - **`remove-benchmark-conflicts.sh`** - Resolves benchmark file conflicts
32
+
33
+ ## Usage
34
+
35
+ ### Import Fixes
36
+ ```bash
37
+ # Fix import paths
38
+ node scripts/utils/fix-import-paths.js
39
+
40
+ # Remove duplicate imports
41
+ node scripts/utils/fix-duplicate-imports.js
42
+
43
+ # Fix Cliffy imports specifically
44
+ node scripts/utils/fix-cliffy-imports.js
45
+
46
+ # General import optimization
47
+ node scripts/utils/fix-imports.js
48
+ ```
49
+
50
+ ### TypeScript Fixes
51
+ ```bash
52
+ # Comprehensive TypeScript fixes
53
+ python scripts/utils/fix-ts-comprehensive.py
54
+
55
+ # Targeted batch fixes
56
+ node scripts/utils/fix-ts-targeted-batch.js
57
+
58
+ # Test module fixes
59
+ node scripts/utils/fix-test-modules.js
60
+ ```
61
+
62
+ ### System Maintenance
63
+ ```bash
64
+ # Clean build artifacts
65
+ bash scripts/utils/clean-build-artifacts.sh
66
+
67
+ # Clean root directory
68
+ bash scripts/utils/cleanup-root.sh
69
+
70
+ # Remove benchmark conflicts
71
+ bash scripts/utils/remove-benchmark-conflicts.sh
72
+ ```
73
+
74
+ ### Code Quality
75
+ ```bash
76
+ # Fix shebang lines
77
+ node scripts/utils/fix-shebang.js
78
+
79
+ # Improve error handling
80
+ node scripts/utils/fix-error-handling.cjs
81
+
82
+ # Fix timezone issues
83
+ node scripts/utils/fix-timezone-issue-246.js
84
+
85
+ # Simple test fixes
86
+ node scripts/utils/simple-test-fixer.js
87
+ ```
88
+
89
+ ## Script Categories
90
+
91
+ ### 1. Import & Module Management
92
+ Scripts that handle import statements, module resolution, and dependency management.
93
+
94
+ **Common Use Cases:**
95
+ - Fixing broken import paths after file moves
96
+ - Removing duplicate imports
97
+ - Updating import statements for library changes
98
+ - Resolving module resolution issues
99
+
100
+ ### 2. TypeScript Error Resolution
101
+ Scripts specifically designed to fix TypeScript compilation errors.
102
+
103
+ **Common Use Cases:**
104
+ - Type annotation fixes
105
+ - Interface compliance fixes
106
+ - Generic type resolution
107
+ - Module declaration fixes
108
+
109
+ ### 3. Test Infrastructure Fixes
110
+ Scripts that maintain and fix test-related code.
111
+
112
+ **Common Use Cases:**
113
+ - Test import fixes
114
+ - Test configuration updates
115
+ - Mock and fixture repairs
116
+ - Test runner compatibility
117
+
118
+ ### 4. Build System Maintenance
119
+ Scripts that clean up and maintain the build system.
120
+
121
+ **Common Use Cases:**
122
+ - Artifact cleanup
123
+ - Temporary file removal
124
+ - Build cache management
125
+ - Dependency cleanup
126
+
127
+ ### 5. Code Quality & Standards
128
+ Scripts that enforce and fix code quality issues.
129
+
130
+ **Common Use Cases:**
131
+ - Shebang line standardization
132
+ - Error handling improvements
133
+ - Code style fixes
134
+ - Lint error resolution
135
+
136
+ ## Integration with Build Process
137
+
138
+ Many utility scripts are integrated into the build process:
139
+
140
+ ```json
141
+ {
142
+ "scripts": {
143
+ "prebuild": "scripts/utils/clean-build-artifacts.sh",
144
+ "postbuild": "scripts/utils/fix-imports.js",
145
+ "fix:imports": "node scripts/utils/fix-import-paths.js",
146
+ "fix:duplicates": "node scripts/utils/fix-duplicate-imports.js",
147
+ "clean": "rm -rf dist .crdt-data .demo-crdt-data && scripts/utils/cleanup-root.sh"
148
+ }
149
+ }
150
+ ```
151
+
152
+ ## Automation Features
153
+
154
+ ### Batch Processing
155
+ Most scripts support batch processing for efficiency:
156
+ ```bash
157
+ # Process multiple files
158
+ node scripts/utils/fix-import-paths.js --batch src/**/*.ts
159
+
160
+ # Dry run mode
161
+ node scripts/utils/fix-ts-targeted-batch.js --dry-run
162
+
163
+ # Verbose output
164
+ python scripts/utils/fix-ts-comprehensive.py --verbose
165
+ ```
166
+
167
+ ### Safety Features
168
+ - **Dry run mode** - Preview changes before applying
169
+ - **Backup creation** - Automatic backups before modifications
170
+ - **Rollback capability** - Ability to revert changes
171
+ - **Validation checks** - Verify fixes don't break functionality
172
+
173
+ ### Integration with Version Control
174
+ ```bash
175
+ # Check for uncommitted changes before running
176
+ if git diff-index --quiet HEAD --; then
177
+ node scripts/utils/fix-import-paths.js
178
+ else
179
+ echo "Uncommitted changes detected. Commit first."
180
+ fi
181
+ ```
182
+
183
+ ## Best Practices
184
+
185
+ ### Before Running Utilities
186
+ 1. **Commit current changes** to version control
187
+ 2. **Run tests** to establish baseline
188
+ 3. **Create backup** if not automated
189
+ 4. **Use dry-run mode** to preview changes
190
+
191
+ ### After Running Utilities
192
+ 1. **Verify fixes** don't break functionality
193
+ 2. **Run tests** to ensure no regressions
194
+ 3. **Review changes** in version control
195
+ 4. **Commit fixes** with descriptive messages
196
+
197
+ ### Safe Usage Patterns
198
+ ```bash
199
+ # Safe fix pattern
200
+ git add -A && git commit -m "Pre-fix checkpoint"
201
+ node scripts/utils/fix-import-paths.js --dry-run
202
+ node scripts/utils/fix-import-paths.js
203
+ npm test
204
+ git add -A && git commit -m "Fix: Import path corrections"
205
+ ```
206
+
207
+ ## Troubleshooting
208
+
209
+ ### Script Execution Issues
210
+ ```bash
211
+ # Check Node.js version
212
+ node --version
213
+
214
+ # Install dependencies
215
+ npm install
216
+
217
+ # Check file permissions
218
+ chmod +x scripts/utils/*.sh
219
+ ```
220
+
221
+ ### Fix Script Failures
222
+ ```bash
223
+ # Run with verbose logging
224
+ node scripts/utils/fix-import-paths.js --verbose
225
+
226
+ # Check for syntax errors
227
+ node --check scripts/utils/fix-import-paths.js
228
+
229
+ # Use alternative Python version
230
+ python3 scripts/utils/fix-ts-comprehensive.py
231
+ ```
232
+
233
+ ### Recovery from Bad Fixes
234
+ ```bash
235
+ # Revert to last commit
236
+ git reset --hard HEAD
237
+
238
+ # Revert specific files
239
+ git checkout HEAD -- path/to/file.ts
240
+
241
+ # Use backup files (if created)
242
+ cp file.ts.backup file.ts
243
+ ```
244
+
245
+ ## Contributing New Utilities
246
+
247
+ When adding new utility scripts:
248
+
249
+ 1. **Follow naming convention** - `fix-[issue-type]-[specific-name].js`
250
+ 2. **Include safety features** - dry-run, backup, validation
251
+ 3. **Add comprehensive logging** - progress, errors, results
252
+ 4. **Write documentation** - usage, examples, troubleshooting
253
+ 5. **Test thoroughly** - various file types, edge cases
254
+ 6. **Update this README** - add script description and usage
255
+
256
+ ## Related Directories
257
+
258
+ - `../build/` - Build-specific utilities
259
+ - `../test/` - Test-specific utilities
260
+ - `../dev/` - Development utilities
261
+ - `../legacy/` - Superseded utility scripts