hyntx 0.0.1 → 1.0.0
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/README.md +2 -2
- package/dist/index.d.ts +7 -53
- package/dist/index.js +344 -36
- package/dist/index.js.map +1 -1
- package/package.json +26 -5
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/hyntx)
|
|
6
6
|
[](LICENSE)
|
|
7
|
-
[](https://nodejs.org/)
|
|
8
8
|
|
|
9
9
|
> **🚧 NOT READY FOR USE**: Hyntx is currently **under active development** and **not yet ready for production use**. The tool is not functional at this time. This README describes the planned features and functionality. For the current development status, implementation progress, and what's actually working, please see the [ROADMAP.md](ROADMAP.md).
|
|
10
10
|
|
|
@@ -317,7 +317,7 @@ Hyntx takes your privacy seriously:
|
|
|
317
317
|
|
|
318
318
|
## Requirements
|
|
319
319
|
|
|
320
|
-
- **Node.js**:
|
|
320
|
+
- **Node.js**: 22.0.0 or higher
|
|
321
321
|
- **Claude Code**: Must have Claude Code installed and used
|
|
322
322
|
- **AI Provider**: Ollama (local) or Anthropic/Google API key
|
|
323
323
|
|
package/dist/index.d.ts
CHANGED
|
@@ -50,55 +50,6 @@ type AnalysisProvider = {
|
|
|
50
50
|
isAvailable(): Promise<boolean>;
|
|
51
51
|
analyze(prompts: readonly string[], date: string): Promise<AnalysisResult>;
|
|
52
52
|
};
|
|
53
|
-
/**
|
|
54
|
-
* Ollama provider configuration.
|
|
55
|
-
*/
|
|
56
|
-
type OllamaConfig = {
|
|
57
|
-
readonly model: string;
|
|
58
|
-
readonly host: string;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Ollama AI provider implementation.
|
|
63
|
-
*
|
|
64
|
-
* This module provides integration with local Ollama instances for prompt analysis.
|
|
65
|
-
* Features include:
|
|
66
|
-
* - Availability checking with timeout and model verification
|
|
67
|
-
* - Retry logic with exponential backoff for network errors
|
|
68
|
-
* - Support for both raw JSON and markdown-wrapped responses
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Ollama provider for local AI analysis.
|
|
73
|
-
* Implements the AnalysisProvider interface for Ollama instances.
|
|
74
|
-
*/
|
|
75
|
-
declare class OllamaProvider implements AnalysisProvider {
|
|
76
|
-
readonly name = "Ollama";
|
|
77
|
-
private readonly config;
|
|
78
|
-
/**
|
|
79
|
-
* Creates a new OllamaProvider instance.
|
|
80
|
-
*
|
|
81
|
-
* @param config - Ollama configuration with model and host
|
|
82
|
-
*/
|
|
83
|
-
constructor(config: OllamaConfig);
|
|
84
|
-
/**
|
|
85
|
-
* Checks if the Ollama service is available and has the required model.
|
|
86
|
-
* Uses a 3-second timeout to avoid hanging on unreachable services.
|
|
87
|
-
*
|
|
88
|
-
* @returns Promise that resolves to true if available, false otherwise
|
|
89
|
-
*/
|
|
90
|
-
isAvailable(): Promise<boolean>;
|
|
91
|
-
/**
|
|
92
|
-
* Analyzes prompts using the Ollama service.
|
|
93
|
-
* Implements retry logic with exponential backoff for network errors.
|
|
94
|
-
*
|
|
95
|
-
* @param prompts - Array of prompt strings to analyze
|
|
96
|
-
* @param date - Date context for the analysis
|
|
97
|
-
* @returns Promise resolving to AnalysisResult
|
|
98
|
-
* @throws Error if analysis fails after retries or if response is invalid
|
|
99
|
-
*/
|
|
100
|
-
analyze(prompts: readonly string[], date: string): Promise<AnalysisResult>;
|
|
101
|
-
}
|
|
102
53
|
|
|
103
54
|
/**
|
|
104
55
|
* Hyntx - CLI Entry Point
|
|
@@ -142,11 +93,14 @@ declare function checkAndRunSetup(): Promise<void>;
|
|
|
142
93
|
*/
|
|
143
94
|
declare function readLogsWithSpinner(date: string): Promise<readonly string[]>;
|
|
144
95
|
/**
|
|
145
|
-
* Connects to
|
|
96
|
+
* Connects to an available provider with automatic fallback.
|
|
97
|
+
*
|
|
98
|
+
* Uses the multi-provider factory to get the first available provider
|
|
99
|
+
* from the configured services list, with fallback support.
|
|
146
100
|
*
|
|
147
|
-
* @returns
|
|
101
|
+
* @returns Available provider instance
|
|
148
102
|
*/
|
|
149
|
-
declare function connectProviderWithSpinner(): Promise<
|
|
103
|
+
declare function connectProviderWithSpinner(): Promise<AnalysisProvider>;
|
|
150
104
|
/**
|
|
151
105
|
* Analyzes prompts with progress tracking.
|
|
152
106
|
*
|
|
@@ -155,7 +109,7 @@ declare function connectProviderWithSpinner(): Promise<OllamaProvider>;
|
|
|
155
109
|
* @param date - Date context
|
|
156
110
|
* @returns Analysis result
|
|
157
111
|
*/
|
|
158
|
-
declare function analyzeWithProgress(provider:
|
|
112
|
+
declare function analyzeWithProgress(provider: AnalysisProvider, prompts: readonly string[], date: string): Promise<AnalysisResult>;
|
|
159
113
|
/**
|
|
160
114
|
* Displays analysis results.
|
|
161
115
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync, chmodSync } from 'fs';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
4
|
import { join, dirname, basename } from 'path';
|
|
5
5
|
import { parseArgs } from 'util';
|
|
@@ -131,6 +131,10 @@ ${configBlock}${after}`.trim() + "\n";
|
|
|
131
131
|
} catch {
|
|
132
132
|
}
|
|
133
133
|
writeFileSync(configFile, content, "utf-8");
|
|
134
|
+
try {
|
|
135
|
+
chmodSync(configFile, 384);
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
134
138
|
return {
|
|
135
139
|
success: true,
|
|
136
140
|
shellFile: configFile,
|
|
@@ -822,7 +826,12 @@ function redactUKNINO(text) {
|
|
|
822
826
|
);
|
|
823
827
|
}
|
|
824
828
|
function redactChileanRUN(text) {
|
|
825
|
-
return text.replace(
|
|
829
|
+
return text.replace(
|
|
830
|
+
/\b(?:RUN|RUT)[\s:]*([0-9]{7,8}-[0-9K]|[0-9]{8}[0-9K])\b/gi,
|
|
831
|
+
(match, run) => {
|
|
832
|
+
return match.replace(run, "[REDACTED_CHILEAN_RUN]");
|
|
833
|
+
}
|
|
834
|
+
);
|
|
826
835
|
}
|
|
827
836
|
function redactArgentineDNI(text) {
|
|
828
837
|
return text.replace(
|
|
@@ -913,9 +922,9 @@ function sanitize(text) {
|
|
|
913
922
|
sanitized = redactURLCredentials(sanitized);
|
|
914
923
|
sanitized = redactPEMKeys(sanitized);
|
|
915
924
|
sanitized = redactEmails(sanitized);
|
|
916
|
-
sanitized = redactPhoneNumbers(sanitized);
|
|
917
925
|
sanitized = redactCreditCards(sanitized);
|
|
918
|
-
sanitized =
|
|
926
|
+
sanitized = redactPassportNumbers(sanitized);
|
|
927
|
+
sanitized = redactDriverLicenseNumbers(sanitized);
|
|
919
928
|
sanitized = redactSpanishDNI(sanitized);
|
|
920
929
|
sanitized = redactSpanishNIE(sanitized);
|
|
921
930
|
sanitized = redactMexicanCURP(sanitized);
|
|
@@ -923,14 +932,14 @@ function sanitize(text) {
|
|
|
923
932
|
sanitized = redactUKNINO(sanitized);
|
|
924
933
|
sanitized = redactChileanRUN(sanitized);
|
|
925
934
|
sanitized = redactArgentineDNI(sanitized);
|
|
926
|
-
sanitized = redactIPv4(sanitized);
|
|
927
|
-
sanitized = redactIPv6(sanitized);
|
|
928
|
-
sanitized = redactMACAddresses(sanitized);
|
|
929
|
-
sanitized = redactPassportNumbers(sanitized);
|
|
930
|
-
sanitized = redactDriverLicenseNumbers(sanitized);
|
|
931
935
|
sanitized = redactAddresses(sanitized);
|
|
932
936
|
sanitized = redactBirthDates(sanitized);
|
|
933
937
|
sanitized = redactNames(sanitized);
|
|
938
|
+
sanitized = redactSSN(sanitized);
|
|
939
|
+
sanitized = redactPhoneNumbers(sanitized);
|
|
940
|
+
sanitized = redactIPv4(sanitized);
|
|
941
|
+
sanitized = redactIPv6(sanitized);
|
|
942
|
+
sanitized = redactMACAddresses(sanitized);
|
|
934
943
|
const redacted = countRedactions(text, sanitized);
|
|
935
944
|
return {
|
|
936
945
|
text: sanitized,
|
|
@@ -1572,6 +1581,314 @@ function sleep(ms) {
|
|
|
1572
1581
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1573
1582
|
}
|
|
1574
1583
|
|
|
1584
|
+
// src/providers/anthropic.ts
|
|
1585
|
+
var MAX_RETRIES2 = 2;
|
|
1586
|
+
var AVAILABILITY_TIMEOUT_MS2 = 5e3;
|
|
1587
|
+
var ANALYSIS_TIMEOUT_MS2 = 6e4;
|
|
1588
|
+
var BASE_RETRY_DELAY_MS2 = 1e3;
|
|
1589
|
+
var API_BASE_URL = "https://api.anthropic.com";
|
|
1590
|
+
var API_VERSION = "2023-06-01";
|
|
1591
|
+
var MAX_TOKENS = 4096;
|
|
1592
|
+
var AnthropicProvider = class {
|
|
1593
|
+
name = "Anthropic";
|
|
1594
|
+
config;
|
|
1595
|
+
/**
|
|
1596
|
+
* Creates a new AnthropicProvider instance.
|
|
1597
|
+
*
|
|
1598
|
+
* @param config - Anthropic configuration with model and API key
|
|
1599
|
+
*/
|
|
1600
|
+
constructor(config) {
|
|
1601
|
+
this.config = config;
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Checks if the Anthropic API is available by validating the API key.
|
|
1605
|
+
* Makes a minimal request to verify the key is valid.
|
|
1606
|
+
*
|
|
1607
|
+
* @returns Promise that resolves to true if available, false otherwise
|
|
1608
|
+
*/
|
|
1609
|
+
async isAvailable() {
|
|
1610
|
+
if (!this.config.apiKey) {
|
|
1611
|
+
return false;
|
|
1612
|
+
}
|
|
1613
|
+
try {
|
|
1614
|
+
const controller = new AbortController();
|
|
1615
|
+
const timeoutId = setTimeout(() => {
|
|
1616
|
+
controller.abort();
|
|
1617
|
+
}, AVAILABILITY_TIMEOUT_MS2);
|
|
1618
|
+
const response = await fetch(`${API_BASE_URL}/v1/messages`, {
|
|
1619
|
+
method: "POST",
|
|
1620
|
+
headers: {
|
|
1621
|
+
"Content-Type": "application/json",
|
|
1622
|
+
"x-api-key": this.config.apiKey,
|
|
1623
|
+
"anthropic-version": API_VERSION
|
|
1624
|
+
},
|
|
1625
|
+
body: JSON.stringify({
|
|
1626
|
+
model: this.config.model,
|
|
1627
|
+
max_tokens: 1,
|
|
1628
|
+
messages: [{ role: "user", content: "Hi" }]
|
|
1629
|
+
}),
|
|
1630
|
+
signal: controller.signal
|
|
1631
|
+
});
|
|
1632
|
+
clearTimeout(timeoutId);
|
|
1633
|
+
return response.ok || response.status === 429 || response.status === 400;
|
|
1634
|
+
} catch {
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Analyzes prompts using the Anthropic Claude API.
|
|
1640
|
+
* Implements retry logic with exponential backoff for network errors.
|
|
1641
|
+
*
|
|
1642
|
+
* @param prompts - Array of prompt strings to analyze
|
|
1643
|
+
* @param date - Date context for the analysis
|
|
1644
|
+
* @returns Promise resolving to AnalysisResult
|
|
1645
|
+
* @throws Error if analysis fails after retries or if response is invalid
|
|
1646
|
+
*/
|
|
1647
|
+
async analyze(prompts2, date) {
|
|
1648
|
+
if (prompts2.length === 0) {
|
|
1649
|
+
throw new Error("Cannot analyze empty prompts array");
|
|
1650
|
+
}
|
|
1651
|
+
const userPrompt = buildUserPrompt(prompts2, date);
|
|
1652
|
+
let lastError;
|
|
1653
|
+
for (let attempt = 0; attempt <= MAX_RETRIES2; attempt++) {
|
|
1654
|
+
try {
|
|
1655
|
+
const controller = new AbortController();
|
|
1656
|
+
const timeoutId = setTimeout(() => {
|
|
1657
|
+
controller.abort();
|
|
1658
|
+
}, ANALYSIS_TIMEOUT_MS2);
|
|
1659
|
+
const response = await fetch(`${API_BASE_URL}/v1/messages`, {
|
|
1660
|
+
method: "POST",
|
|
1661
|
+
headers: {
|
|
1662
|
+
"Content-Type": "application/json",
|
|
1663
|
+
"x-api-key": this.config.apiKey,
|
|
1664
|
+
"anthropic-version": API_VERSION
|
|
1665
|
+
},
|
|
1666
|
+
body: JSON.stringify({
|
|
1667
|
+
model: this.config.model,
|
|
1668
|
+
max_tokens: MAX_TOKENS,
|
|
1669
|
+
system: SYSTEM_PROMPT,
|
|
1670
|
+
messages: [{ role: "user", content: userPrompt }]
|
|
1671
|
+
}),
|
|
1672
|
+
signal: controller.signal
|
|
1673
|
+
});
|
|
1674
|
+
clearTimeout(timeoutId);
|
|
1675
|
+
if (!response.ok) {
|
|
1676
|
+
const status = String(response.status);
|
|
1677
|
+
const errorBody = await response.text();
|
|
1678
|
+
throw new Error(
|
|
1679
|
+
`Anthropic API request failed: ${status} ${response.statusText} - ${errorBody}`
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
const data = await response.json();
|
|
1683
|
+
const textContent = data.content?.find(
|
|
1684
|
+
(block) => block.type === "text"
|
|
1685
|
+
);
|
|
1686
|
+
if (!textContent?.text) {
|
|
1687
|
+
throw new Error("Invalid response format from Anthropic API");
|
|
1688
|
+
}
|
|
1689
|
+
return parseResponse(textContent.text, date);
|
|
1690
|
+
} catch (error) {
|
|
1691
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1692
|
+
if (lastError.message.includes("parse") || lastError.message.includes("schema")) {
|
|
1693
|
+
throw lastError;
|
|
1694
|
+
}
|
|
1695
|
+
if (lastError.message.includes("401") || lastError.message.includes("403")) {
|
|
1696
|
+
throw lastError;
|
|
1697
|
+
}
|
|
1698
|
+
if (attempt === MAX_RETRIES2) {
|
|
1699
|
+
break;
|
|
1700
|
+
}
|
|
1701
|
+
const delay = BASE_RETRY_DELAY_MS2 * Math.pow(2, attempt);
|
|
1702
|
+
await sleep2(delay);
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
const attempts = String(MAX_RETRIES2 + 1);
|
|
1706
|
+
throw new Error(
|
|
1707
|
+
`Anthropic analysis failed after ${attempts} attempts: ${lastError?.message ?? "Unknown error"}`
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
function sleep2(ms) {
|
|
1712
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
// src/providers/google.ts
|
|
1716
|
+
var MAX_RETRIES3 = 2;
|
|
1717
|
+
var AVAILABILITY_TIMEOUT_MS3 = 5e3;
|
|
1718
|
+
var ANALYSIS_TIMEOUT_MS3 = 6e4;
|
|
1719
|
+
var BASE_RETRY_DELAY_MS3 = 1e3;
|
|
1720
|
+
var API_BASE_URL2 = "https://generativelanguage.googleapis.com/v1beta";
|
|
1721
|
+
var GoogleProvider = class {
|
|
1722
|
+
name = "Google";
|
|
1723
|
+
config;
|
|
1724
|
+
/**
|
|
1725
|
+
* Creates a new GoogleProvider instance.
|
|
1726
|
+
*
|
|
1727
|
+
* @param config - Google configuration with model and API key
|
|
1728
|
+
*/
|
|
1729
|
+
constructor(config) {
|
|
1730
|
+
this.config = config;
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* Checks if the Google Gemini API is available by validating the API key.
|
|
1734
|
+
* Makes a minimal request to verify the key is valid.
|
|
1735
|
+
*
|
|
1736
|
+
* @returns Promise that resolves to true if available, false otherwise
|
|
1737
|
+
*/
|
|
1738
|
+
async isAvailable() {
|
|
1739
|
+
if (!this.config.apiKey) {
|
|
1740
|
+
return false;
|
|
1741
|
+
}
|
|
1742
|
+
try {
|
|
1743
|
+
const controller = new AbortController();
|
|
1744
|
+
const timeoutId = setTimeout(() => {
|
|
1745
|
+
controller.abort();
|
|
1746
|
+
}, AVAILABILITY_TIMEOUT_MS3);
|
|
1747
|
+
const url = `${API_BASE_URL2}/models/${this.config.model}:generateContent?key=${this.config.apiKey}`;
|
|
1748
|
+
const response = await fetch(url, {
|
|
1749
|
+
method: "POST",
|
|
1750
|
+
headers: {
|
|
1751
|
+
"Content-Type": "application/json"
|
|
1752
|
+
},
|
|
1753
|
+
body: JSON.stringify({
|
|
1754
|
+
contents: [
|
|
1755
|
+
{
|
|
1756
|
+
role: "user",
|
|
1757
|
+
parts: [{ text: "Hi" }]
|
|
1758
|
+
}
|
|
1759
|
+
],
|
|
1760
|
+
generationConfig: {
|
|
1761
|
+
maxOutputTokens: 1
|
|
1762
|
+
}
|
|
1763
|
+
}),
|
|
1764
|
+
signal: controller.signal
|
|
1765
|
+
});
|
|
1766
|
+
clearTimeout(timeoutId);
|
|
1767
|
+
return response.ok || response.status === 429 || response.status === 400;
|
|
1768
|
+
} catch {
|
|
1769
|
+
return false;
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Analyzes prompts using the Google Gemini API.
|
|
1774
|
+
* Implements retry logic with exponential backoff for network errors.
|
|
1775
|
+
*
|
|
1776
|
+
* @param prompts - Array of prompt strings to analyze
|
|
1777
|
+
* @param date - Date context for the analysis
|
|
1778
|
+
* @returns Promise resolving to AnalysisResult
|
|
1779
|
+
* @throws Error if analysis fails after retries or if response is invalid
|
|
1780
|
+
*/
|
|
1781
|
+
async analyze(prompts2, date) {
|
|
1782
|
+
if (prompts2.length === 0) {
|
|
1783
|
+
throw new Error("Cannot analyze empty prompts array");
|
|
1784
|
+
}
|
|
1785
|
+
const userPrompt = buildUserPrompt(prompts2, date);
|
|
1786
|
+
let lastError;
|
|
1787
|
+
for (let attempt = 0; attempt <= MAX_RETRIES3; attempt++) {
|
|
1788
|
+
try {
|
|
1789
|
+
const controller = new AbortController();
|
|
1790
|
+
const timeoutId = setTimeout(() => {
|
|
1791
|
+
controller.abort();
|
|
1792
|
+
}, ANALYSIS_TIMEOUT_MS3);
|
|
1793
|
+
const url = `${API_BASE_URL2}/models/${this.config.model}:generateContent?key=${this.config.apiKey}`;
|
|
1794
|
+
const response = await fetch(url, {
|
|
1795
|
+
method: "POST",
|
|
1796
|
+
headers: {
|
|
1797
|
+
"Content-Type": "application/json"
|
|
1798
|
+
},
|
|
1799
|
+
body: JSON.stringify({
|
|
1800
|
+
contents: [
|
|
1801
|
+
{
|
|
1802
|
+
role: "user",
|
|
1803
|
+
parts: [{ text: userPrompt }]
|
|
1804
|
+
}
|
|
1805
|
+
],
|
|
1806
|
+
systemInstruction: {
|
|
1807
|
+
parts: [{ text: SYSTEM_PROMPT }]
|
|
1808
|
+
},
|
|
1809
|
+
generationConfig: {
|
|
1810
|
+
responseMimeType: "application/json"
|
|
1811
|
+
}
|
|
1812
|
+
}),
|
|
1813
|
+
signal: controller.signal
|
|
1814
|
+
});
|
|
1815
|
+
clearTimeout(timeoutId);
|
|
1816
|
+
if (!response.ok) {
|
|
1817
|
+
const status = String(response.status);
|
|
1818
|
+
const errorBody = await response.text();
|
|
1819
|
+
throw new Error(
|
|
1820
|
+
`Google API request failed: ${status} ${response.statusText} - ${errorBody}`
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
const data = await response.json();
|
|
1824
|
+
const textContent = data.candidates?.[0]?.content?.parts?.[0]?.text;
|
|
1825
|
+
if (!textContent) {
|
|
1826
|
+
throw new Error("Invalid response format from Google API");
|
|
1827
|
+
}
|
|
1828
|
+
return parseResponse(textContent, date);
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1831
|
+
if (lastError.message.includes("parse") || lastError.message.includes("schema")) {
|
|
1832
|
+
throw lastError;
|
|
1833
|
+
}
|
|
1834
|
+
if (lastError.message.includes("401") || lastError.message.includes("403")) {
|
|
1835
|
+
throw lastError;
|
|
1836
|
+
}
|
|
1837
|
+
if (attempt === MAX_RETRIES3) {
|
|
1838
|
+
break;
|
|
1839
|
+
}
|
|
1840
|
+
const delay = BASE_RETRY_DELAY_MS3 * Math.pow(2, attempt);
|
|
1841
|
+
await sleep3(delay);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
const attempts = String(MAX_RETRIES3 + 1);
|
|
1845
|
+
throw new Error(
|
|
1846
|
+
`Google analysis failed after ${attempts} attempts: ${lastError?.message ?? "Unknown error"}`
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
};
|
|
1850
|
+
function sleep3(ms) {
|
|
1851
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
// src/providers/index.ts
|
|
1855
|
+
function createProvider(type, config) {
|
|
1856
|
+
switch (type) {
|
|
1857
|
+
case "ollama":
|
|
1858
|
+
return new OllamaProvider(config.ollama);
|
|
1859
|
+
case "anthropic":
|
|
1860
|
+
return new AnthropicProvider(config.anthropic);
|
|
1861
|
+
case "google":
|
|
1862
|
+
return new GoogleProvider(config.google);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
async function getAvailableProvider(config, onFallback) {
|
|
1866
|
+
if (config.services.length === 0) {
|
|
1867
|
+
throw new Error(
|
|
1868
|
+
"No providers configured. Please run hyntx setup to configure providers."
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1871
|
+
let firstProvider;
|
|
1872
|
+
for (const type of config.services) {
|
|
1873
|
+
const provider = createProvider(type, config);
|
|
1874
|
+
firstProvider ??= provider;
|
|
1875
|
+
try {
|
|
1876
|
+
const isAvailable = await provider.isAvailable();
|
|
1877
|
+
if (isAvailable) {
|
|
1878
|
+
if (onFallback && provider !== firstProvider) {
|
|
1879
|
+
onFallback(firstProvider.name, provider.name);
|
|
1880
|
+
}
|
|
1881
|
+
return provider;
|
|
1882
|
+
}
|
|
1883
|
+
} catch {
|
|
1884
|
+
continue;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
throw new Error(
|
|
1888
|
+
"No providers are currently available. Please check your provider configurations."
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1575
1892
|
// src/index.ts
|
|
1576
1893
|
var currentDir = dirname(fileURLToPath(import.meta.url));
|
|
1577
1894
|
var packageJson = JSON.parse(
|
|
@@ -1683,40 +2000,31 @@ async function readLogsWithSpinner(date) {
|
|
|
1683
2000
|
}
|
|
1684
2001
|
async function connectProviderWithSpinner() {
|
|
1685
2002
|
const config = getEnvConfig();
|
|
1686
|
-
if (
|
|
1687
|
-
console.error(chalk3.red("Error:
|
|
1688
|
-
console.error(
|
|
1689
|
-
chalk3.dim("\nRun setup again to configure Ollama as a provider.")
|
|
1690
|
-
);
|
|
2003
|
+
if (config.services.length === 0) {
|
|
2004
|
+
console.error(chalk3.red("Error: No providers configured"));
|
|
2005
|
+
console.error(chalk3.dim("\nRun setup to configure at least one provider."));
|
|
1691
2006
|
process.exit(EXIT_CODES.PROVIDER_UNAVAILABLE);
|
|
1692
2007
|
}
|
|
1693
|
-
const spinner = ora("Connecting to
|
|
2008
|
+
const spinner = ora("Connecting to provider...").start();
|
|
1694
2009
|
try {
|
|
1695
|
-
const provider =
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
spinner.fail(chalk3.red("Ollama service not available"));
|
|
1699
|
-
console.error(
|
|
1700
|
-
chalk3.dim(
|
|
1701
|
-
`
|
|
1702
|
-
Make sure Ollama is running: ${chalk3.bold("ollama serve")}`
|
|
1703
|
-
)
|
|
1704
|
-
);
|
|
1705
|
-
console.error(
|
|
1706
|
-
chalk3.dim(
|
|
1707
|
-
`And the model "${config.ollama.model}" is installed: ${chalk3.bold(`ollama pull ${config.ollama.model}`)}`
|
|
1708
|
-
)
|
|
2010
|
+
const provider = await getAvailableProvider(config, (from, to) => {
|
|
2011
|
+
spinner.text = chalk3.yellow(
|
|
2012
|
+
`Primary provider ${from} unavailable, falling back to ${to}...`
|
|
1709
2013
|
);
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1712
|
-
spinner.succeed(
|
|
1713
|
-
chalk3.green(`Connected to Ollama (${config.ollama.model})`)
|
|
1714
|
-
);
|
|
2014
|
+
});
|
|
2015
|
+
spinner.succeed(chalk3.green(`Connected to ${provider.name}`));
|
|
1715
2016
|
return provider;
|
|
1716
2017
|
} catch (error) {
|
|
1717
2018
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1718
|
-
spinner.fail(chalk3.red(
|
|
1719
|
-
|
|
2019
|
+
spinner.fail(chalk3.red("No providers available"));
|
|
2020
|
+
console.error(chalk3.dim(`
|
|
2021
|
+
${errorMessage}`));
|
|
2022
|
+
console.error(
|
|
2023
|
+
chalk3.dim(
|
|
2024
|
+
"\nCheck your provider configuration and ensure at least one provider is running."
|
|
2025
|
+
)
|
|
2026
|
+
);
|
|
2027
|
+
process.exit(EXIT_CODES.PROVIDER_UNAVAILABLE);
|
|
1720
2028
|
}
|
|
1721
2029
|
}
|
|
1722
2030
|
async function analyzeWithProgress(provider, prompts2, date) {
|