@mzhub/cortex 0.1.0 → 0.1.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/README.md +0 -0
- package/dist/{BaseAdapter-WunbfD_n.d.ts → BaseAdapter-BcNZrPzG.d.ts} +1 -1
- package/dist/{BaseAdapter-Bjj4JG_S.d.mts → BaseAdapter-CH2Gg9xO.d.mts} +1 -1
- package/dist/BaseProvider-8dmLKPhr.d.mts +61 -0
- package/dist/BaseProvider-DgYEmkh_.d.ts +61 -0
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +9 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +9 -1
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/{index-DnOyj7gs.d.ts → index-BHvGS1BY.d.mts} +14 -10
- package/dist/{index-C_w3EJQT.d.mts → index-CA79C0tz.d.ts} +14 -10
- package/dist/index.d.mts +16 -13
- package/dist/index.d.ts +16 -13
- package/dist/index.js +277 -135
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +277 -135
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/index.d.mts +4 -4
- package/dist/middleware/index.d.ts +4 -4
- package/dist/middleware/index.js +0 -0
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +0 -0
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +2 -2
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +72 -17
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +72 -17
- package/dist/providers/index.mjs.map +1 -1
- package/dist/{types-DybcUhEZ.d.mts → types-DUn4u5hk.d.mts} +1 -1
- package/dist/{types-DybcUhEZ.d.ts → types-DUn4u5hk.d.ts} +1 -1
- package/logo.png +0 -0
- package/package.json +20 -19
- package/dist/BaseProvider-B8x1pJXP.d.mts +0 -34
- package/dist/BaseProvider-BIkJVjtg.d.ts +0 -34
package/README.md
CHANGED
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from './types-
|
|
1
|
+
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from './types-DUn4u5hk.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Abstract base class for storage adapters.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from './types-
|
|
1
|
+
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from './types-DUn4u5hk.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Abstract base class for storage adapters.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { a as CompletionOptions, b as CompletionResult } from './types-DUn4u5hk.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for provider retry and timeout behavior
|
|
5
|
+
*/
|
|
6
|
+
interface ProviderRetryConfig {
|
|
7
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
/** Maximum retry attempts (default: 3) */
|
|
10
|
+
maxRetries?: number;
|
|
11
|
+
/** Initial retry delay in milliseconds (default: 1000) */
|
|
12
|
+
retryDelayMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Abstract base class for LLM providers.
|
|
16
|
+
* All provider implementations must extend this class.
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class BaseProvider {
|
|
19
|
+
protected apiKey: string;
|
|
20
|
+
protected model: string;
|
|
21
|
+
protected baseUrl?: string;
|
|
22
|
+
protected timeoutMs: number;
|
|
23
|
+
protected maxRetries: number;
|
|
24
|
+
protected retryDelayMs: number;
|
|
25
|
+
constructor(config: {
|
|
26
|
+
apiKey: string;
|
|
27
|
+
model?: string;
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
retry?: ProviderRetryConfig;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Get the default model for this provider
|
|
33
|
+
*/
|
|
34
|
+
abstract getDefaultModel(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get the provider name
|
|
37
|
+
*/
|
|
38
|
+
abstract getName(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a completion from the LLM
|
|
41
|
+
*/
|
|
42
|
+
abstract complete(options: CompletionOptions): Promise<CompletionResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Check if the provider SDK is available
|
|
45
|
+
*/
|
|
46
|
+
static isAvailable(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a fetch request with timeout and retry logic
|
|
49
|
+
*/
|
|
50
|
+
protected fetchWithRetry(url: string, init: RequestInit): Promise<Response>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if an HTTP status code is retryable
|
|
53
|
+
*/
|
|
54
|
+
private isRetryableStatus;
|
|
55
|
+
/**
|
|
56
|
+
* Sleep for a given number of milliseconds
|
|
57
|
+
*/
|
|
58
|
+
protected sleep(ms: number): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { BaseProvider as B };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { a as CompletionOptions, b as CompletionResult } from './types-DUn4u5hk.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for provider retry and timeout behavior
|
|
5
|
+
*/
|
|
6
|
+
interface ProviderRetryConfig {
|
|
7
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
/** Maximum retry attempts (default: 3) */
|
|
10
|
+
maxRetries?: number;
|
|
11
|
+
/** Initial retry delay in milliseconds (default: 1000) */
|
|
12
|
+
retryDelayMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Abstract base class for LLM providers.
|
|
16
|
+
* All provider implementations must extend this class.
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class BaseProvider {
|
|
19
|
+
protected apiKey: string;
|
|
20
|
+
protected model: string;
|
|
21
|
+
protected baseUrl?: string;
|
|
22
|
+
protected timeoutMs: number;
|
|
23
|
+
protected maxRetries: number;
|
|
24
|
+
protected retryDelayMs: number;
|
|
25
|
+
constructor(config: {
|
|
26
|
+
apiKey: string;
|
|
27
|
+
model?: string;
|
|
28
|
+
baseUrl?: string;
|
|
29
|
+
retry?: ProviderRetryConfig;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Get the default model for this provider
|
|
33
|
+
*/
|
|
34
|
+
abstract getDefaultModel(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get the provider name
|
|
37
|
+
*/
|
|
38
|
+
abstract getName(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Generate a completion from the LLM
|
|
41
|
+
*/
|
|
42
|
+
abstract complete(options: CompletionOptions): Promise<CompletionResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Check if the provider SDK is available
|
|
45
|
+
*/
|
|
46
|
+
static isAvailable(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a fetch request with timeout and retry logic
|
|
49
|
+
*/
|
|
50
|
+
protected fetchWithRetry(url: string, init: RequestInit): Promise<Response>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if an HTTP status code is retryable
|
|
53
|
+
*/
|
|
54
|
+
private isRetryableStatus;
|
|
55
|
+
/**
|
|
56
|
+
* Sleep for a given number of milliseconds
|
|
57
|
+
*/
|
|
58
|
+
protected sleep(ms: number): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { BaseProvider as B };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BaseAdapter } from '../BaseAdapter-
|
|
2
|
-
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from '../types-
|
|
1
|
+
import { B as BaseAdapter } from '../BaseAdapter-CH2Gg9xO.mjs';
|
|
2
|
+
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from '../types-DUn4u5hk.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* In-memory storage adapter for development and testing.
|
|
@@ -54,7 +54,7 @@ interface JSONUserData {
|
|
|
54
54
|
sessions: Session[];
|
|
55
55
|
}
|
|
56
56
|
interface JSONFileAdapterConfig {
|
|
57
|
-
/** Base path for storing JSON files (default: ./.
|
|
57
|
+
/** Base path for storing JSON files (default: ./.cortex) */
|
|
58
58
|
path?: string;
|
|
59
59
|
/** Pretty print JSON files (default: true in dev, false in prod) */
|
|
60
60
|
prettyPrint?: boolean;
|
|
@@ -64,7 +64,7 @@ interface JSONFileAdapterConfig {
|
|
|
64
64
|
* Stores each user's data in separate JSON files for portability.
|
|
65
65
|
*
|
|
66
66
|
* Directory structure:
|
|
67
|
-
* .
|
|
67
|
+
* .cortex/
|
|
68
68
|
* ├── users/
|
|
69
69
|
* │ ├── {userId}/
|
|
70
70
|
* │ │ ├── facts.json
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BaseAdapter } from '../BaseAdapter-
|
|
2
|
-
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from '../types-
|
|
1
|
+
import { B as BaseAdapter } from '../BaseAdapter-BcNZrPzG.js';
|
|
2
|
+
import { F as FactFilter, M as MemoryFact, C as ConversationExchange, S as Session } from '../types-DUn4u5hk.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* In-memory storage adapter for development and testing.
|
|
@@ -54,7 +54,7 @@ interface JSONUserData {
|
|
|
54
54
|
sessions: Session[];
|
|
55
55
|
}
|
|
56
56
|
interface JSONFileAdapterConfig {
|
|
57
|
-
/** Base path for storing JSON files (default: ./.
|
|
57
|
+
/** Base path for storing JSON files (default: ./.cortex) */
|
|
58
58
|
path?: string;
|
|
59
59
|
/** Pretty print JSON files (default: true in dev, false in prod) */
|
|
60
60
|
prettyPrint?: boolean;
|
|
@@ -64,7 +64,7 @@ interface JSONFileAdapterConfig {
|
|
|
64
64
|
* Stores each user's data in separate JSON files for portability.
|
|
65
65
|
*
|
|
66
66
|
* Directory structure:
|
|
67
|
-
* .
|
|
67
|
+
* .cortex/
|
|
68
68
|
* ├── users/
|
|
69
69
|
* │ ├── {userId}/
|
|
70
70
|
* │ │ ├── facts.json
|
package/dist/adapters/index.js
CHANGED
|
@@ -287,7 +287,7 @@ var JSONFileAdapter = class extends BaseAdapter {
|
|
|
287
287
|
prettyPrint;
|
|
288
288
|
constructor(config = {}) {
|
|
289
289
|
super();
|
|
290
|
-
this.basePath = config.path || "./.
|
|
290
|
+
this.basePath = config.path || "./.cortex";
|
|
291
291
|
this.prettyPrint = config.prettyPrint ?? process.env.NODE_ENV !== "production";
|
|
292
292
|
}
|
|
293
293
|
async initialize() {
|
|
@@ -906,6 +906,14 @@ var PostgresAdapter = class extends BaseAdapter {
|
|
|
906
906
|
CREATE INDEX IF NOT EXISTS idx_facts_user_valid
|
|
907
907
|
ON ${this.schema}.facts (user_id, invalidated_at)
|
|
908
908
|
`);
|
|
909
|
+
await this.query(
|
|
910
|
+
`
|
|
911
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_facts_unique_active_triple
|
|
912
|
+
ON ${this.schema}.facts (user_id, subject, predicate)
|
|
913
|
+
WHERE invalidated_at IS NULL
|
|
914
|
+
`
|
|
915
|
+
).catch(() => {
|
|
916
|
+
});
|
|
909
917
|
await this.query(`
|
|
910
918
|
CREATE TABLE IF NOT EXISTS ${this.schema}.conversations (
|
|
911
919
|
id UUID PRIMARY KEY,
|