@tyvm/knowhow 0.0.109 → 0.0.111
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/autodoc/README.md +324 -0
- package/autodoc/chat-guide.md +268 -365
- package/autodoc/cli-reference.md +399 -473
- package/autodoc/config-reference.md +431 -330
- package/autodoc/embeddings-guide.md +223 -322
- package/autodoc/generate-guide.md +261 -301
- package/autodoc/language-plugin-guide.md +221 -247
- package/autodoc/modules-guide.md +242 -215
- package/autodoc/plugins-guide.md +470 -469
- package/autodoc/quickstart-guide.md +67 -70
- package/autodoc/skills-guide.md +455 -339
- package/autodoc/worker-guide.md +301 -308
- package/package.json +1 -1
- package/scripts/build-for-node.sh +10 -24
- package/src/agents/tools/list.ts +2 -2
- package/src/ai.ts +81 -37
- package/src/auth/browserLogin.ts +129 -3
- package/src/chat/CliChatService.ts +1 -1
- package/src/chat/modules/AgentModule.ts +7 -2
- package/src/chat/modules/SessionsModule.ts +40 -1
- package/src/chat/modules/SystemModule.ts +2 -2
- package/src/clients/anthropic.ts +1 -1
- package/src/clients/index.ts +25 -6
- package/src/clients/openai.ts +8 -5
- package/src/clients/types.ts +29 -6
- package/src/clients/withRetry.ts +89 -0
- package/src/commands/agent.ts +30 -0
- package/src/commands/modules.ts +417 -47
- package/src/config.ts +1 -1
- package/src/fileSync.ts +20 -12
- package/src/hashes.ts +43 -22
- package/src/index.ts +4 -2
- package/src/login.ts +3 -2
- package/src/processors/Base64ImageDetector.ts +73 -0
- package/src/services/Mcp.ts +14 -1
- package/src/services/MediaProcessorService.ts +79 -10
- package/src/services/modules/index.ts +47 -18
- package/src/utils/http.ts +9 -2
- package/tests/processors/Base64ImageDetector.test.ts +160 -0
- package/tests/unit/clients/AIClient.test.ts +446 -0
- package/tests/unit/clients/withRetry.test.ts +319 -0
- package/tests/unit/commands/github-credentials.test.ts +1 -2
- package/ts_build/package.json +1 -1
- package/ts_build/src/agents/tools/list.js +2 -2
- package/ts_build/src/agents/tools/list.js.map +1 -1
- package/ts_build/src/ai.d.ts +3 -3
- package/ts_build/src/ai.js +51 -23
- package/ts_build/src/ai.js.map +1 -1
- package/ts_build/src/auth/browserLogin.d.ts +2 -0
- package/ts_build/src/auth/browserLogin.js +91 -3
- package/ts_build/src/auth/browserLogin.js.map +1 -1
- package/ts_build/src/chat/CliChatService.js +1 -1
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.js +5 -2
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/chat/modules/SessionsModule.js +30 -1
- package/ts_build/src/chat/modules/SessionsModule.js.map +1 -1
- package/ts_build/src/chat/modules/SystemModule.js +2 -2
- package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
- package/ts_build/src/clients/anthropic.js +1 -1
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/clients/index.js +7 -6
- package/ts_build/src/clients/index.js.map +1 -1
- package/ts_build/src/clients/openai.js +4 -4
- package/ts_build/src/clients/openai.js.map +1 -1
- package/ts_build/src/clients/types.d.ts +12 -6
- package/ts_build/src/clients/withRetry.d.ts +2 -0
- package/ts_build/src/clients/withRetry.js +60 -0
- package/ts_build/src/clients/withRetry.js.map +1 -0
- package/ts_build/src/commands/agent.js +25 -0
- package/ts_build/src/commands/agent.js.map +1 -1
- package/ts_build/src/commands/modules.js +359 -32
- package/ts_build/src/commands/modules.js.map +1 -1
- package/ts_build/src/config.js +1 -1
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/fileSync.d.ts +2 -2
- package/ts_build/src/fileSync.js +13 -11
- package/ts_build/src/fileSync.js.map +1 -1
- package/ts_build/src/hashes.d.ts +2 -2
- package/ts_build/src/hashes.js +40 -16
- package/ts_build/src/hashes.js.map +1 -1
- package/ts_build/src/index.js +1 -1
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/login.js +2 -2
- package/ts_build/src/login.js.map +1 -1
- package/ts_build/src/processors/Base64ImageDetector.d.ts +3 -0
- package/ts_build/src/processors/Base64ImageDetector.js +42 -0
- package/ts_build/src/processors/Base64ImageDetector.js.map +1 -1
- package/ts_build/src/services/Mcp.js +9 -1
- package/ts_build/src/services/Mcp.js.map +1 -1
- package/ts_build/src/services/MediaProcessorService.d.ts +5 -4
- package/ts_build/src/services/MediaProcessorService.js +53 -8
- package/ts_build/src/services/MediaProcessorService.js.map +1 -1
- package/ts_build/src/services/modules/index.js +35 -12
- package/ts_build/src/services/modules/index.js.map +1 -1
- package/ts_build/src/utils/http.d.ts +2 -1
- package/ts_build/src/utils/http.js +11 -2
- package/ts_build/src/utils/http.js.map +1 -1
- package/ts_build/tests/processors/Base64ImageDetector.test.js +111 -0
- package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -1
- package/ts_build/tests/unit/clients/AIClient.test.d.ts +1 -0
- package/ts_build/tests/unit/clients/AIClient.test.js +339 -0
- package/ts_build/tests/unit/clients/AIClient.test.js.map +1 -0
- package/ts_build/tests/unit/clients/withRetry.test.d.ts +1 -0
- package/ts_build/tests/unit/clients/withRetry.test.js +225 -0
- package/ts_build/tests/unit/clients/withRetry.test.js.map +1 -0
- package/ts_build/tests/unit/commands/github-credentials.test.js +1 -2
- package/ts_build/tests/unit/commands/github-credentials.test.js.map +1 -1
package/src/clients/types.ts
CHANGED
|
@@ -57,7 +57,30 @@ export interface ToolCall {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export interface
|
|
60
|
+
export interface RetryOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Request timeout in milliseconds per attempt. If the request does not complete
|
|
63
|
+
* within this time it is aborted and retried according to maxRetries.
|
|
64
|
+
*/
|
|
65
|
+
timeout?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Maximum number of retry attempts for retriable errors (5xx, timeout, ECONNRESET, 429).
|
|
68
|
+
* Default: 2. Set to 0 to disable retries.
|
|
69
|
+
*/
|
|
70
|
+
maxRetries?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Base backoff delay in milliseconds for exponential retry backoff.
|
|
73
|
+
* Default: 1000ms. Each retry waits backoffMs * 2^attempt ms.
|
|
74
|
+
*/
|
|
75
|
+
backoffMs?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Optional external AbortSignal. When the signal is aborted the current
|
|
78
|
+
* attempt is cancelled immediately and no further retries are made.
|
|
79
|
+
*/
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface CompletionOptions extends RetryOptions {
|
|
61
84
|
model: string;
|
|
62
85
|
messages: Message[];
|
|
63
86
|
tools?: Tool[];
|
|
@@ -113,7 +136,7 @@ export interface CompletionResponse {
|
|
|
113
136
|
usd_cost?: number;
|
|
114
137
|
}
|
|
115
138
|
|
|
116
|
-
export interface EmbeddingOptions {
|
|
139
|
+
export interface EmbeddingOptions extends RetryOptions {
|
|
117
140
|
input: string;
|
|
118
141
|
model?: string;
|
|
119
142
|
}
|
|
@@ -132,7 +155,7 @@ export interface EmbeddingResponse {
|
|
|
132
155
|
usd_cost?: number;
|
|
133
156
|
}
|
|
134
157
|
|
|
135
|
-
export interface AudioTranscriptionOptions {
|
|
158
|
+
export interface AudioTranscriptionOptions extends RetryOptions {
|
|
136
159
|
file: Blob | File | any; // Support for Node.js ReadStream or web File/Blob
|
|
137
160
|
model?: string;
|
|
138
161
|
language?: string;
|
|
@@ -162,7 +185,7 @@ export interface AudioTranscriptionResponse {
|
|
|
162
185
|
usd_cost?: number;
|
|
163
186
|
}
|
|
164
187
|
|
|
165
|
-
export interface AudioGenerationOptions {
|
|
188
|
+
export interface AudioGenerationOptions extends RetryOptions {
|
|
166
189
|
model: string;
|
|
167
190
|
input: string;
|
|
168
191
|
voice: string; // e.g. "alloy", "echo", "fable", "onyx", "nova", "shimmer" for OpenAI; "Kore", "Puck" etc. for Gemini
|
|
@@ -176,7 +199,7 @@ export interface AudioGenerationResponse {
|
|
|
176
199
|
usd_cost?: number;
|
|
177
200
|
}
|
|
178
201
|
|
|
179
|
-
export interface ImageGenerationOptions {
|
|
202
|
+
export interface ImageGenerationOptions extends RetryOptions {
|
|
180
203
|
model: string;
|
|
181
204
|
prompt: string;
|
|
182
205
|
n?: number;
|
|
@@ -197,7 +220,7 @@ export interface ImageGenerationResponse {
|
|
|
197
220
|
usd_cost?: number;
|
|
198
221
|
}
|
|
199
222
|
|
|
200
|
-
export interface VideoGenerationOptions {
|
|
223
|
+
export interface VideoGenerationOptions extends RetryOptions {
|
|
201
224
|
model: string;
|
|
202
225
|
prompt: string;
|
|
203
226
|
duration?: number; // seconds
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared retry/timeout helper for all AI clients.
|
|
3
|
+
*
|
|
4
|
+
* Executes `fn` with exponential backoff for retriable errors:
|
|
5
|
+
* - Rate limits (429)
|
|
6
|
+
* - Timeouts (AbortError, ETIMEDOUT, ECONNRESET)
|
|
7
|
+
* - Server errors (5xx)
|
|
8
|
+
*
|
|
9
|
+
* @param fn Function to execute. Receives a combined AbortSignal
|
|
10
|
+
* that fires on per-attempt timeout OR external signal abort.
|
|
11
|
+
* @param opts Any object with optional RetryOptions fields (timeout, maxRetries,
|
|
12
|
+
* backoffMs, signal). Extra fields are ignored — so you can pass the
|
|
13
|
+
* full options object from any AI method directly.
|
|
14
|
+
* - timeout: Per-attempt timeout in ms. No timeout if omitted.
|
|
15
|
+
* - maxRetries: Max retry attempts after first failure. Default: 2.
|
|
16
|
+
* - backoffMs: Base backoff delay in ms. Default: 1000.
|
|
17
|
+
* - signal: Optional external AbortSignal. When aborted, the current
|
|
18
|
+
* attempt is cancelled and no further retries are made.
|
|
19
|
+
*/
|
|
20
|
+
import type { RetryOptions } from "./types";
|
|
21
|
+
|
|
22
|
+
export async function withRetry<T>(
|
|
23
|
+
fn: (signal?: AbortSignal) => Promise<T>,
|
|
24
|
+
opts: RetryOptions = {}
|
|
25
|
+
): Promise<T> {
|
|
26
|
+
const maxRetries = opts.maxRetries ?? 2;
|
|
27
|
+
const backoffMs = opts.backoffMs ?? 1000;
|
|
28
|
+
const timeout = opts.timeout;
|
|
29
|
+
const externalSignal = opts.signal;
|
|
30
|
+
|
|
31
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
32
|
+
// If the external signal is already aborted, bail out immediately.
|
|
33
|
+
if (externalSignal?.aborted) {
|
|
34
|
+
throw externalSignal.reason ?? new DOMException("Aborted", "AbortError");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
38
|
+
// Combine per-attempt timeout with the external signal into one controller.
|
|
39
|
+
const controller = timeout || externalSignal ? new AbortController() : undefined;
|
|
40
|
+
|
|
41
|
+
if (controller) {
|
|
42
|
+
if (timeout) {
|
|
43
|
+
timer = setTimeout(() => controller.abort(new DOMException("Request timed out", "TimeoutError")), timeout);
|
|
44
|
+
}
|
|
45
|
+
// Forward external signal abort into our combined controller.
|
|
46
|
+
if (externalSignal) {
|
|
47
|
+
const onExternalAbort = () => controller.abort(externalSignal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
48
|
+
if (externalSignal.aborted) {
|
|
49
|
+
controller.abort(externalSignal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
50
|
+
} else {
|
|
51
|
+
externalSignal.addEventListener("abort", onExternalAbort, { once: true });
|
|
52
|
+
// Clean up the listener after the attempt resolves/rejects.
|
|
53
|
+
controller.signal.addEventListener("abort", () =>
|
|
54
|
+
externalSignal.removeEventListener("abort", onExternalAbort), { once: true }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const result = await fn(controller?.signal);
|
|
62
|
+
return result;
|
|
63
|
+
} catch (err: unknown) {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
// If the external signal was aborted, don't retry — propagate immediately.
|
|
66
|
+
if (externalSignal?.aborted) {
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
const errStr = String(err);
|
|
70
|
+
const isRetriable =
|
|
71
|
+
errStr.includes('429') ||
|
|
72
|
+
errStr.includes('timeout') ||
|
|
73
|
+
errStr.includes('TimeoutError') ||
|
|
74
|
+
errStr.includes('ECONNRESET') ||
|
|
75
|
+
errStr.includes('ETIMEDOUT') ||
|
|
76
|
+
errStr.includes('AbortError') ||
|
|
77
|
+
/5\d\d/.test(errStr);
|
|
78
|
+
if (isRetriable && attempt < maxRetries) {
|
|
79
|
+
const delay = backoffMs * Math.pow(2, attempt);
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
throw err;
|
|
84
|
+
} finally {
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
throw new Error('withRetry: exhausted retries');
|
|
89
|
+
}
|
package/src/commands/agent.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { AskModule } from "../chat/modules/AskModule";
|
|
|
5
5
|
import { SearchModule } from "../chat/modules/SearchModule";
|
|
6
6
|
import { SessionsModule } from "../chat/modules/SessionsModule";
|
|
7
7
|
import { SetupModule } from "../chat/modules/SetupModule";
|
|
8
|
+
import { loadRenderer } from "../chat/renderer/loadRenderer";
|
|
9
|
+
import { getConfig } from "../config";
|
|
8
10
|
|
|
9
11
|
async function readStdin(): Promise<string> {
|
|
10
12
|
return new Promise((resolve) => {
|
|
@@ -25,6 +27,24 @@ async function readStdin(): Promise<string> {
|
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Set up the renderer on the chat service context.
|
|
32
|
+
* Priority: CLI --renderer flag > config.chat.renderer > "basic" (ConsoleRenderer)
|
|
33
|
+
*/
|
|
34
|
+
async function setupRenderer(chatService: any, rendererSpecifier: string): Promise<void> {
|
|
35
|
+
try {
|
|
36
|
+
const renderer = await loadRenderer(rendererSpecifier);
|
|
37
|
+
chatService.setContext({ renderer });
|
|
38
|
+
} catch (err: any) {
|
|
39
|
+
console.warn(`⚠ Could not load renderer "${rendererSpecifier}": ${err.message}`);
|
|
40
|
+
console.warn(" Falling back to basic renderer.");
|
|
41
|
+
try {
|
|
42
|
+
const fallback = await loadRenderer("basic");
|
|
43
|
+
chatService.setContext({ renderer: fallback });
|
|
44
|
+
} catch (_) {}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
export function addAgentCommand(program: Command, getChatService: () => any): void {
|
|
29
49
|
program
|
|
30
50
|
.command("agent")
|
|
@@ -57,11 +77,21 @@ export function addAgentCommand(program: Command, getChatService: () => any): vo
|
|
|
57
77
|
"--resume",
|
|
58
78
|
"Resume a previously started task using the --task-id (local FS or remote)"
|
|
59
79
|
)
|
|
80
|
+
.option(
|
|
81
|
+
"--renderer <name>",
|
|
82
|
+
"Renderer to use: basic, compact, fancy, or a path/package (default: from config or basic)"
|
|
83
|
+
)
|
|
60
84
|
.action(async (options) => {
|
|
61
85
|
try {
|
|
62
86
|
const { setupServices } = await import("./services");
|
|
63
87
|
await setupServices();
|
|
64
88
|
const chatService = getChatService();
|
|
89
|
+
|
|
90
|
+
// Set up renderer: CLI flag > config.chat.renderer > "basic"
|
|
91
|
+
let config: any = {};
|
|
92
|
+
try { config = await getConfig(); } catch (_) {}
|
|
93
|
+
const rendererSpecifier = options.renderer ?? config.chat?.renderer ?? "basic";
|
|
94
|
+
await setupRenderer(chatService, rendererSpecifier);
|
|
65
95
|
const agentModule = new AgentModule();
|
|
66
96
|
|
|
67
97
|
if (options.resume) {
|