fawn-memory 0.0.3 → 0.0.4
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.
|
@@ -1,17 +1,67 @@
|
|
|
1
|
-
import type { TypeChatLanguageModel } from 'typechat';
|
|
2
|
-
|
|
1
|
+
import type { TypeChatLanguageModel, PromptSection, Result } from 'typechat';
|
|
2
|
+
import { success, error } from 'typechat';
|
|
3
|
+
export type { TypeChatLanguageModel, PromptSection, Result };
|
|
4
|
+
export { success, error };
|
|
5
|
+
/**
|
|
6
|
+
* Built-in provider types. Custom providers can use any string.
|
|
7
|
+
*/
|
|
8
|
+
export type BuiltInLLMProviderType = 'openai' | 'claude';
|
|
3
9
|
export interface LLMProviderConfig {
|
|
4
|
-
provider:
|
|
5
|
-
apiKey
|
|
10
|
+
provider: string;
|
|
11
|
+
apiKey?: string;
|
|
6
12
|
model?: string;
|
|
7
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* LLM Provider interface.
|
|
16
|
+
* Implement this interface to create custom LLM providers.
|
|
17
|
+
*/
|
|
8
18
|
export interface LLMProvider {
|
|
9
|
-
readonly name:
|
|
19
|
+
readonly name: string;
|
|
10
20
|
readonly model: string;
|
|
11
21
|
getLanguageModel(): TypeChatLanguageModel;
|
|
12
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates an OpenAI LLM provider.
|
|
25
|
+
*/
|
|
13
26
|
export declare function createOpenAIProvider(apiKey: string, model?: string): LLMProvider;
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to extract string content from a PromptSection.
|
|
29
|
+
* Useful for custom provider implementations.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getContentAsString(content: PromptSection['content']): string;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a Claude/Anthropic LLM provider.
|
|
34
|
+
*/
|
|
14
35
|
export declare function createClaudeProvider(apiKey: string, model?: string): LLMProvider;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a built-in LLM provider based on configuration.
|
|
38
|
+
* For custom providers, implement the LLMProvider interface directly.
|
|
39
|
+
*/
|
|
15
40
|
export declare function createLLMProvider(config: LLMProviderConfig): LLMProvider;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a built-in LLM provider from environment variables.
|
|
43
|
+
* For custom providers, implement the LLMProvider interface directly.
|
|
44
|
+
*
|
|
45
|
+
* Environment variables:
|
|
46
|
+
* LLM_PROVIDER: 'openai' | 'claude' (default: 'openai')
|
|
47
|
+
* LLM_MODEL: Model name override (optional)
|
|
48
|
+
*
|
|
49
|
+
* For OpenAI:
|
|
50
|
+
* OPENAI_API_KEY or OPENAI_SDK_KEY: API key
|
|
51
|
+
*
|
|
52
|
+
* For Claude:
|
|
53
|
+
* ANTHROPIC_API_KEY: API key
|
|
54
|
+
*/
|
|
16
55
|
export declare function createLLMProviderFromEnv(): LLMProvider;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a custom TypeChatLanguageModel with default retry settings.
|
|
58
|
+
* Use this helper when implementing custom LLM providers.
|
|
59
|
+
*
|
|
60
|
+
* @param completeFn - The completion function that calls your LLM
|
|
61
|
+
* @param options - Optional retry configuration
|
|
62
|
+
*/
|
|
63
|
+
export declare function createCustomLanguageModel(completeFn: (prompt: string | PromptSection[]) => Promise<Result<string>>, options?: {
|
|
64
|
+
retryMaxAttempts?: number;
|
|
65
|
+
retryPauseMs?: number;
|
|
66
|
+
}): TypeChatLanguageModel;
|
|
17
67
|
//# sourceMappingURL=llmProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmProvider.d.ts","sourceRoot":"","sources":["../../src/knowpro/llmProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"llmProvider.d.ts","sourceRoot":"","sources":["../../src/knowpro/llmProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAA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AAM,CAAC;CACvB,GACA,qBAAqB,CAMvB"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
2
|
import { createOpenAILanguageModel, success, error } from 'typechat';
|
|
3
|
+
export { success, error };
|
|
4
|
+
/**
|
|
5
|
+
* Creates an OpenAI LLM provider.
|
|
6
|
+
*/
|
|
3
7
|
export function createOpenAIProvider(apiKey, model = 'gpt-4o') {
|
|
4
8
|
const languageModel = createOpenAILanguageModel(apiKey, model);
|
|
5
9
|
return {
|
|
@@ -8,7 +12,11 @@ export function createOpenAIProvider(apiKey, model = 'gpt-4o') {
|
|
|
8
12
|
getLanguageModel: () => languageModel
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Helper function to extract string content from a PromptSection.
|
|
17
|
+
* Useful for custom provider implementations.
|
|
18
|
+
*/
|
|
19
|
+
export function getContentAsString(content) {
|
|
12
20
|
if (typeof content === 'string') {
|
|
13
21
|
return content;
|
|
14
22
|
}
|
|
@@ -22,6 +30,9 @@ function getContentAsString(content) {
|
|
|
22
30
|
return '';
|
|
23
31
|
}).join('');
|
|
24
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a Claude/Anthropic LLM provider.
|
|
35
|
+
*/
|
|
25
36
|
export function createClaudeProvider(apiKey, model = 'claude-sonnet-4-20250514') {
|
|
26
37
|
const client = new Anthropic({ apiKey });
|
|
27
38
|
const languageModel = {
|
|
@@ -77,18 +88,43 @@ export function createClaudeProvider(apiKey, model = 'claude-sonnet-4-20250514')
|
|
|
77
88
|
getLanguageModel: () => languageModel
|
|
78
89
|
};
|
|
79
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Creates a built-in LLM provider based on configuration.
|
|
93
|
+
* For custom providers, implement the LLMProvider interface directly.
|
|
94
|
+
*/
|
|
80
95
|
export function createLLMProvider(config) {
|
|
81
96
|
switch (config.provider) {
|
|
82
97
|
case 'openai':
|
|
98
|
+
if (!config.apiKey) {
|
|
99
|
+
throw new Error('OpenAI provider requires apiKey');
|
|
100
|
+
}
|
|
83
101
|
return createOpenAIProvider(config.apiKey, config.model);
|
|
84
102
|
case 'claude':
|
|
103
|
+
if (!config.apiKey) {
|
|
104
|
+
throw new Error('Claude provider requires apiKey');
|
|
105
|
+
}
|
|
85
106
|
return createClaudeProvider(config.apiKey, config.model);
|
|
86
107
|
default:
|
|
87
|
-
throw new Error(`Unknown provider: ${config.provider}
|
|
108
|
+
throw new Error(`Unknown built-in provider: ${config.provider}. For custom providers, implement LLMProvider directly.`);
|
|
88
109
|
}
|
|
89
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates a built-in LLM provider from environment variables.
|
|
113
|
+
* For custom providers, implement the LLMProvider interface directly.
|
|
114
|
+
*
|
|
115
|
+
* Environment variables:
|
|
116
|
+
* LLM_PROVIDER: 'openai' | 'claude' (default: 'openai')
|
|
117
|
+
* LLM_MODEL: Model name override (optional)
|
|
118
|
+
*
|
|
119
|
+
* For OpenAI:
|
|
120
|
+
* OPENAI_API_KEY or OPENAI_SDK_KEY: API key
|
|
121
|
+
*
|
|
122
|
+
* For Claude:
|
|
123
|
+
* ANTHROPIC_API_KEY: API key
|
|
124
|
+
*/
|
|
90
125
|
export function createLLMProviderFromEnv() {
|
|
91
126
|
const provider = (process.env.LLM_PROVIDER || 'openai');
|
|
127
|
+
const model = process.env.LLM_MODEL;
|
|
92
128
|
let apiKey;
|
|
93
129
|
if (provider === 'claude') {
|
|
94
130
|
apiKey = process.env.ANTHROPIC_API_KEY;
|
|
@@ -96,10 +132,23 @@ export function createLLMProviderFromEnv() {
|
|
|
96
132
|
else {
|
|
97
133
|
apiKey = process.env.OPENAI_API_KEY || process.env.OPENAI_SDK_KEY;
|
|
98
134
|
}
|
|
99
|
-
const model = process.env.LLM_MODEL;
|
|
100
135
|
if (!apiKey) {
|
|
101
136
|
throw new Error(`Missing API key for provider: ${provider}`);
|
|
102
137
|
}
|
|
103
138
|
return createLLMProvider({ provider, apiKey, model });
|
|
104
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Creates a custom TypeChatLanguageModel with default retry settings.
|
|
142
|
+
* Use this helper when implementing custom LLM providers.
|
|
143
|
+
*
|
|
144
|
+
* @param completeFn - The completion function that calls your LLM
|
|
145
|
+
* @param options - Optional retry configuration
|
|
146
|
+
*/
|
|
147
|
+
export function createCustomLanguageModel(completeFn, options) {
|
|
148
|
+
return {
|
|
149
|
+
retryMaxAttempts: options?.retryMaxAttempts ?? 3,
|
|
150
|
+
retryPauseMs: options?.retryPauseMs ?? 1000,
|
|
151
|
+
complete: completeFn,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
105
154
|
//# sourceMappingURL=llmProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmProvider.js","sourceRoot":"","sources":["../../src/knowpro/llmProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"llmProvider.js","sourceRoot":"","sources":["../../src/knowpro/llmProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIrE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAuB1B;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,QAAgB,QAAQ;IAExB,MAAM,aAAa,GAAG,yBAAyB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK;QACL,gBAAgB,EAAE,GAAG,EAAE,CAAC,aAAa;KACtC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kB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