@satori-sh/cli 0.0.3 → 0.0.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.
- package/bun.lock +195 -0
- package/dist/index.d.ts +92 -4
- package/dist/index.js +396 -42
- package/package.json +3 -3
- package/tsup.config.js +10 -0
- package/dist/add.d.ts +0 -2
- package/dist/add.d.ts.map +0 -1
- package/dist/add.js +0 -27
- package/dist/add.js.map +0 -1
- package/dist/config.d.ts +0 -3
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -15
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/memory.d.ts +0 -12
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -42
- package/dist/memory.js.map +0 -1
- package/dist/search.d.ts +0 -2
- package/dist/search.d.ts.map +0 -1
- package/dist/search.js +0 -27
- package/dist/search.js.map +0 -1
- package/dist/src/add.d.ts +0 -23
- package/dist/src/add.d.ts.map +0 -1
- package/dist/src/add.js +0 -46
- package/dist/src/add.js.map +0 -1
- package/dist/src/config.d.ts +0 -39
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -165
- package/dist/src/config.js.map +0 -1
- package/dist/src/index.d.ts +0 -15
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -142
- package/dist/src/index.js.map +0 -1
- package/dist/src/memory.d.ts +0 -52
- package/dist/src/memory.d.ts.map +0 -1
- package/dist/src/memory.js +0 -98
- package/dist/src/memory.js.map +0 -1
- package/dist/src/providers.d.ts +0 -34
- package/dist/src/providers.d.ts.map +0 -1
- package/dist/src/providers.js +0 -107
- package/dist/src/providers.js.map +0 -1
- package/dist/src/search.d.ts +0 -14
- package/dist/src/search.d.ts.map +0 -1
- package/dist/src/search.js +0 -39
- package/dist/src/search.js.map +0 -1
- package/dist/src/types.d.ts +0 -51
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -2
- package/dist/src/types.js.map +0 -1
- package/dist/tests/index.test.d.ts +0 -2
- package/dist/tests/index.test.d.ts.map +0 -1
- package/dist/tests/index.test.js +0 -257
- package/dist/tests/index.test.js.map +0 -1
- package/dist/types.d.ts +0 -19
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/src/add.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds a new memory to the Satori server.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} text - The text content to add as a memory
|
|
5
|
-
* @param {object} [options] - Additional options for the memory
|
|
6
|
-
* @param {string} [options.memoryId] - Optional memory ID for scoping
|
|
7
|
-
* @returns {Promise<void>} Logs success or error messages to console
|
|
8
|
-
* @throws {Error} If the text is empty
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```bash
|
|
12
|
-
* satori add "I like pizza"
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* await addMemories("User prefers dark mode", { memoryId: "session-123" });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function addMemories(text: string, options?: {
|
|
21
|
-
memoryId?: string;
|
|
22
|
-
}): Promise<void>;
|
|
23
|
-
//# sourceMappingURL=add.d.ts.map
|
package/dist/src/add.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/add.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BlG"}
|
package/dist/src/add.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { getConfig } from './config.js';
|
|
2
|
-
/**
|
|
3
|
-
* Adds a new memory to the Satori server.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} text - The text content to add as a memory
|
|
6
|
-
* @param {object} [options] - Additional options for the memory
|
|
7
|
-
* @param {string} [options.memoryId] - Optional memory ID for scoping
|
|
8
|
-
* @returns {Promise<void>} Logs success or error messages to console
|
|
9
|
-
* @throws {Error} If the text is empty
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```bash
|
|
13
|
-
* satori add "I like pizza"
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* await addMemories("User prefers dark mode", { memoryId: "session-123" });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export async function addMemories(text, options = {}) {
|
|
22
|
-
if (!text || !text.trim()) {
|
|
23
|
-
console.error('Text cannot be empty');
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const config = await getConfig();
|
|
28
|
-
const response = await fetch(`${config.baseUrl}/memories`, {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
headers: {
|
|
31
|
-
'Content-Type': 'application/json',
|
|
32
|
-
'Authorization': `Bearer ${config.apiKey}`
|
|
33
|
-
},
|
|
34
|
-
body: JSON.stringify({ messages: [{ role: "user", content: text }], ...(options.memoryId && { memory_id: options.memoryId }) })
|
|
35
|
-
});
|
|
36
|
-
if (!response.ok) {
|
|
37
|
-
console.error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
await response.json();
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error(`Error adding memory: ${error instanceof Error ? error.message : error}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=add.js.map
|
package/dist/src/add.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["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1F,CAAC;AACH,CAAC"}
|
package/dist/src/config.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Config } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Checks write access to the config directory by attempting to create, write, and delete a temporary file.
|
|
4
|
-
*
|
|
5
|
-
* @throws {Error} If write access is denied or any operation fails
|
|
6
|
-
*/
|
|
7
|
-
export declare function checkWriteAccess(): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Saves the API key to the config file.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} apiKey - The API key to save
|
|
12
|
-
* @throws {Error} If write access fails or saving fails
|
|
13
|
-
*/
|
|
14
|
-
export declare function saveApiKey(apiKey: string): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Saves the memory ID to the config file.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} memoryId - The memory ID to save
|
|
19
|
-
* @throws {Error} If write access fails or saving fails
|
|
20
|
-
*/
|
|
21
|
-
export declare function saveMemoryId(memoryId: string): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves and validates configuration from file and environment variables.
|
|
24
|
-
* Fetches the memory_id and api_key from the config file in ~/.config/satori/satori.json.
|
|
25
|
-
*
|
|
26
|
-
* If the API key isn't in the config, it looks in SATORI_API_KEY.
|
|
27
|
-
* If there is no API key in either place it will call the API to get a new key.
|
|
28
|
-
*
|
|
29
|
-
* @returns {Promise<Config>} The validated configuration object
|
|
30
|
-
* @throws {Error} If required environment variables are missing or invalid
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const config = await getConfig();
|
|
35
|
-
* console.log(config.apiKey); // API key from ~/.config/satori/satori.json or SATORI_API_KEY env var, or null
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function getConfig(): Promise<Config>;
|
|
39
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAKpC;;;;GAIG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAatD;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9D;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAalE;AAoBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAoEjD"}
|
package/dist/src/config.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { homedir } from 'node:os';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { randomUUID } from 'node:crypto';
|
|
4
|
-
/**
|
|
5
|
-
* Checks write access to the config directory by attempting to create, write, and delete a temporary file.
|
|
6
|
-
*
|
|
7
|
-
* @throws {Error} If write access is denied or any operation fails
|
|
8
|
-
*/
|
|
9
|
-
export async function checkWriteAccess() {
|
|
10
|
-
// Dynamic import used instead of static import at top-level to enable mocking with Bun's mock.module() in tests.
|
|
11
|
-
// Static imports cannot be overridden by module mocks in Bun, so this allows fs operations to be properly mocked.
|
|
12
|
-
const { promises: fs } = await import('node:fs');
|
|
13
|
-
const dir = join(homedir(), '.config', 'satori');
|
|
14
|
-
try {
|
|
15
|
-
await fs.mkdir(dir, { recursive: true });
|
|
16
|
-
const tempFile = join(dir, `temp-${randomUUID()}.txt`);
|
|
17
|
-
await fs.writeFile(tempFile, 'test');
|
|
18
|
-
await fs.unlink(tempFile);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
throw new Error(`Cannot write to config directory: ${error instanceof Error ? error.message : error}`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Saves the API key to the config file.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} apiKey - The API key to save
|
|
28
|
-
* @throws {Error} If write access fails or saving fails
|
|
29
|
-
*/
|
|
30
|
-
export async function saveApiKey(apiKey) {
|
|
31
|
-
// Dynamic import used instead of static import at top-level to enable mocking with Bun's mock.module() in tests.
|
|
32
|
-
// Static imports cannot be overridden by module mocks in Bun, so this allows fs operations to be properly mocked.
|
|
33
|
-
const { promises: fs } = await import('node:fs');
|
|
34
|
-
await checkWriteAccess();
|
|
35
|
-
const configPath = join(homedir(), '.config', 'satori', 'satori.json');
|
|
36
|
-
try {
|
|
37
|
-
const existing = await loadConfigFile();
|
|
38
|
-
const config = { ...existing, api_key: apiKey };
|
|
39
|
-
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
throw new Error(`Failed to save API key: ${error instanceof Error ? error.message : error}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Saves the memory ID to the config file.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} memoryId - The memory ID to save
|
|
49
|
-
* @throws {Error} If write access fails or saving fails
|
|
50
|
-
*/
|
|
51
|
-
export async function saveMemoryId(memoryId) {
|
|
52
|
-
// Dynamic import used instead of static import at top-level to enable mocking with Bun's mock.module() in tests.
|
|
53
|
-
// Static imports cannot be overridden by module mocks in Bun, so this allows fs operations to be properly mocked.
|
|
54
|
-
const { promises: fs } = await import('node:fs');
|
|
55
|
-
await checkWriteAccess();
|
|
56
|
-
const configPath = join(homedir(), '.config', 'satori', 'satori.json');
|
|
57
|
-
try {
|
|
58
|
-
const existing = await loadConfigFile();
|
|
59
|
-
const config = { ...existing, memory_id: memoryId };
|
|
60
|
-
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
throw new Error(`Failed to save memory ID: ${error instanceof Error ? error.message : error}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Loads the config file data.
|
|
68
|
-
*
|
|
69
|
-
* @returns {Promise<Record<string, any>>} The config data
|
|
70
|
-
*/
|
|
71
|
-
async function loadConfigFile() {
|
|
72
|
-
try {
|
|
73
|
-
const configPath = join(homedir(), '.config', 'satori', 'satori.json');
|
|
74
|
-
const configFile = Bun.file(configPath);
|
|
75
|
-
if (await configFile.exists()) {
|
|
76
|
-
return await configFile.json();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
// Ignore errors
|
|
81
|
-
}
|
|
82
|
-
return {};
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Retrieves and validates configuration from file and environment variables.
|
|
86
|
-
* Fetches the memory_id and api_key from the config file in ~/.config/satori/satori.json.
|
|
87
|
-
*
|
|
88
|
-
* If the API key isn't in the config, it looks in SATORI_API_KEY.
|
|
89
|
-
* If there is no API key in either place it will call the API to get a new key.
|
|
90
|
-
*
|
|
91
|
-
* @returns {Promise<Config>} The validated configuration object
|
|
92
|
-
* @throws {Error} If required environment variables are missing or invalid
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* const config = await getConfig();
|
|
97
|
-
* console.log(config.apiKey); // API key from ~/.config/satori/satori.json or SATORI_API_KEY env var, or null
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export async function getConfig() {
|
|
101
|
-
if (process.platform !== 'darwin') {
|
|
102
|
-
throw new Error('We do not currently support Windows yet, email support@satori.sh to request Windows support');
|
|
103
|
-
}
|
|
104
|
-
let apiKey = null;
|
|
105
|
-
let memoryId = undefined;
|
|
106
|
-
try {
|
|
107
|
-
const configPath = join(homedir(), '.config', 'satori', 'satori.json');
|
|
108
|
-
const configFile = Bun.file(configPath);
|
|
109
|
-
if (await configFile.exists()) {
|
|
110
|
-
const data = await configFile.json();
|
|
111
|
-
if (data && typeof data.api_key === 'string') {
|
|
112
|
-
apiKey = data.api_key;
|
|
113
|
-
}
|
|
114
|
-
if (data && typeof data.memory_id === 'string') {
|
|
115
|
-
memoryId = data.memory_id;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
// If file reading or parsing fails, apiKey and memoryId remain default
|
|
121
|
-
}
|
|
122
|
-
// Fallback to environment variable if not set from file
|
|
123
|
-
if (!apiKey) {
|
|
124
|
-
apiKey = process.env.SATORI_API_KEY || null;
|
|
125
|
-
}
|
|
126
|
-
const baseUrl = process.env.SATORI_BASE_URL || 'https://api.satori.sh';
|
|
127
|
-
try {
|
|
128
|
-
new URL(baseUrl);
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
throw new Error('Invalid SATORI_BASE_URL format');
|
|
132
|
-
}
|
|
133
|
-
// Generate new API key if still null
|
|
134
|
-
if (!apiKey) {
|
|
135
|
-
try {
|
|
136
|
-
const response = await fetch(`${baseUrl}/orgs`, {
|
|
137
|
-
method: 'POST',
|
|
138
|
-
});
|
|
139
|
-
if (!response.ok) {
|
|
140
|
-
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
141
|
-
}
|
|
142
|
-
const data = await response.json();
|
|
143
|
-
if (data && typeof data.api_key === 'string') {
|
|
144
|
-
apiKey = data.api_key;
|
|
145
|
-
await saveApiKey(apiKey);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
throw new Error('Invalid response: missing api_key');
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
throw new Error(`Failed to generate API key: ${error instanceof Error ? error.message : error}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const provider = process.env.SATORI_PROVIDER || 'openai';
|
|
156
|
-
const model = process.env.SATORI_MODEL || 'gpt-4o';
|
|
157
|
-
const openaiKey = process.env.OPENAI_API_KEY;
|
|
158
|
-
const anthropicKey = process.env.ANTHROPIC_API_KEY;
|
|
159
|
-
// Fallback to config file memoryId if not set via env
|
|
160
|
-
if (!memoryId) {
|
|
161
|
-
memoryId = process.env.SATORI_MEMORY_ID;
|
|
162
|
-
}
|
|
163
|
-
return { apiKey, baseUrl, provider, model, openaiKey, anthropicKey, memoryId };
|
|
164
|
-
}
|
|
165
|
-
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,iHAAiH;IACjH,kHAAkH;IAClH,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACjD,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,UAAU,EAAE,MAAM,CAAC,CAAC;QACvD,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrC,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,qCAAqC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO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AI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC7C,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;gBACtB,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACnG,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,CAAC;IACzD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,QAAQ,CAAC;IACnD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAEnD,sDAAsD;IACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAC1C,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AACjF,CAAC"}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
export { searchMemories } from './search.js';
|
|
3
|
-
export { addMemories } from './add.js';
|
|
4
|
-
export { enhanceMessagesWithMemory } from './memory.js';
|
|
5
|
-
/**
|
|
6
|
-
* Main entry point for the Satori CLI application.
|
|
7
|
-
*
|
|
8
|
-
* Parses command-line arguments and executes the appropriate command.
|
|
9
|
-
* Sets up the CLI with available commands: search, add, and chat.
|
|
10
|
-
*
|
|
11
|
-
* @returns {Promise<void>}
|
|
12
|
-
* @throws {Error} If configuration validation fails
|
|
13
|
-
*/
|
|
14
|
-
export declare function main(): Promise<void>;
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAGxD;;;;;;;;GAQG;AACH,wBAAsB,IAAI,kBAsIzB"}
|
package/dist/src/index.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { getConfig } from './config.js';
|
|
6
|
-
import { searchMemories } from './search.js';
|
|
7
|
-
import { addMemories } from './add.js';
|
|
8
|
-
import { buildMemoryContext, enhanceMessagesWithMemory } from './memory.js';
|
|
9
|
-
import { _callProviderAPI } from './providers.js';
|
|
10
|
-
// Re-export for external use
|
|
11
|
-
export { searchMemories } from './search.js';
|
|
12
|
-
export { addMemories } from './add.js';
|
|
13
|
-
export { enhanceMessagesWithMemory } from './memory.js';
|
|
14
|
-
/**
|
|
15
|
-
* Main entry point for the Satori CLI application.
|
|
16
|
-
*
|
|
17
|
-
* Parses command-line arguments and executes the appropriate command.
|
|
18
|
-
* Sets up the CLI with available commands: search, add, and chat.
|
|
19
|
-
*
|
|
20
|
-
* @returns {Promise<void>}
|
|
21
|
-
* @throws {Error} If configuration validation fails
|
|
22
|
-
*/
|
|
23
|
-
export async function main() {
|
|
24
|
-
try {
|
|
25
|
-
await getConfig(); // Validate early
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error(error instanceof Error ? error.message : 'Configuration error');
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
// Display Satori logo
|
|
32
|
-
console.log(chalk.cyan(readFileSync('./logo.txt', 'utf8')));
|
|
33
|
-
const program = new Command();
|
|
34
|
-
program
|
|
35
|
-
.name('satori')
|
|
36
|
-
.description('CLI tool for Satori memory server')
|
|
37
|
-
.version('0.0.1');
|
|
38
|
-
program
|
|
39
|
-
.option('--provider <provider>', 'Provider to use (openai or anthropic)', 'openai')
|
|
40
|
-
.option('--model <model>', 'Model to use', 'gpt-4o')
|
|
41
|
-
.option('--memory-id <id>', 'Memory ID for scoping');
|
|
42
|
-
// Helper function to process user input
|
|
43
|
-
const processUserInput = async (input, options, isInteractive = false) => {
|
|
44
|
-
let memoryContext;
|
|
45
|
-
try {
|
|
46
|
-
memoryContext = await buildMemoryContext(input, { memoryId: options.memoryId });
|
|
47
|
-
}
|
|
48
|
-
catch (memoryError) {
|
|
49
|
-
memoryContext = { results: [], memoryId: options.memoryId, instruction: undefined };
|
|
50
|
-
}
|
|
51
|
-
const userMessage = { role: 'user', content: input };
|
|
52
|
-
const enhancedMessages = enhanceMessagesWithMemory([userMessage], { results: memoryContext.results });
|
|
53
|
-
const response = await _callProviderAPI(enhancedMessages, {
|
|
54
|
-
temperature: 0.7,
|
|
55
|
-
maxTokens: 1000
|
|
56
|
-
}, options.provider);
|
|
57
|
-
if (isInteractive) {
|
|
58
|
-
console.log(`Assistant: ${response}`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.log(response);
|
|
62
|
-
}
|
|
63
|
-
if (memoryContext.instruction) {
|
|
64
|
-
console.log(`\n${memoryContext.instruction}`);
|
|
65
|
-
}
|
|
66
|
-
addMemories(input, { memoryId: memoryContext.memoryId }).catch(err => {
|
|
67
|
-
console.error('Failed to save memory:', err);
|
|
68
|
-
});
|
|
69
|
-
return { response, instruction: memoryContext.instruction, memoryId: memoryContext.memoryId };
|
|
70
|
-
};
|
|
71
|
-
program
|
|
72
|
-
.argument('[prompt]', 'initial prompt for chat session (optional)')
|
|
73
|
-
.action(async (initialPrompt, options) => {
|
|
74
|
-
try {
|
|
75
|
-
let memoryId = options.memoryId;
|
|
76
|
-
// If not interactive (e.g., piped input), process initial prompt if provided and exit
|
|
77
|
-
if (!process.stdin.isTTY) {
|
|
78
|
-
if (initialPrompt) {
|
|
79
|
-
await processUserInput(initialPrompt, options, false);
|
|
80
|
-
}
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
// Interactive mode
|
|
84
|
-
if (initialPrompt) {
|
|
85
|
-
const result = await processUserInput(initialPrompt, options, true);
|
|
86
|
-
memoryId = result.memoryId;
|
|
87
|
-
}
|
|
88
|
-
// Enter interactive mode
|
|
89
|
-
const { createInterface } = await import('node:readline');
|
|
90
|
-
const rl = createInterface({
|
|
91
|
-
input: process.stdin,
|
|
92
|
-
output: process.stdout
|
|
93
|
-
});
|
|
94
|
-
const chatLoop = async () => {
|
|
95
|
-
rl.question(chalk.cyan('> '), async (input) => {
|
|
96
|
-
if (input.toLowerCase() === 'exit' || input.toLowerCase() === 'quit') {
|
|
97
|
-
console.log('Goodbye!');
|
|
98
|
-
rl.close();
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (!input.trim()) {
|
|
102
|
-
chatLoop();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const result = await processUserInput(input, { ...options, memoryId }, true);
|
|
107
|
-
memoryId = result.memoryId;
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
console.error('Chat error:', error instanceof Error ? error.message : error);
|
|
111
|
-
}
|
|
112
|
-
chatLoop();
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
console.log('\nEntering interactive mode. Type "exit" or "quit" to end the session.\n');
|
|
116
|
-
chatLoop();
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error('Chat error:', error instanceof Error ? error.message : error);
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
program
|
|
124
|
-
.command('add')
|
|
125
|
-
.description('add a new memory')
|
|
126
|
-
.argument('<text>', 'text to add as memory')
|
|
127
|
-
.action(async (text) => {
|
|
128
|
-
await addMemories(text);
|
|
129
|
-
});
|
|
130
|
-
program
|
|
131
|
-
.command('search')
|
|
132
|
-
.description('search memories')
|
|
133
|
-
.argument('<query>', 'search query for memories')
|
|
134
|
-
.action(async (query) => {
|
|
135
|
-
await searchMemories(query);
|
|
136
|
-
});
|
|
137
|
-
program.parse();
|
|
138
|
-
}
|
|
139
|
-
if (import.meta.main) {
|
|
140
|
-
main();
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,6BAA6B;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;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@ -1,52 +0,0 @@
|
|
|
1
|
-
import { SearchResponse, Message } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Options for memory context building.
|
|
4
|
-
*/
|
|
5
|
-
interface MemoryOptions {
|
|
6
|
-
/** Existing memory ID to use for the search */
|
|
7
|
-
memoryId?: string;
|
|
8
|
-
/** Number of top memories to retrieve */
|
|
9
|
-
topK?: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Builds memory context by searching for relevant memories and generating a memory ID if needed.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} prompt - The user's prompt to search memories for
|
|
15
|
-
* @param {MemoryOptions} [options] - Search options
|
|
16
|
-
* @returns {Promise<{results: SearchResponse['results'], memoryId: string, instruction?: string}>}
|
|
17
|
-
* Object containing search results, the memory ID used/generated, and setup instructions if generated
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const context = await buildMemoryContext("What's my favorite food?", { topK: 3 });
|
|
22
|
-
* console.log(`Found ${context.results.length} relevant memories`);
|
|
23
|
-
* if (context.instruction) console.log(context.instruction);
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function buildMemoryContext(prompt: string, options?: MemoryOptions): Promise<{
|
|
27
|
-
results: SearchResponse['results'];
|
|
28
|
-
memoryId: string;
|
|
29
|
-
instruction?: string;
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* Enhances a message array by prepending relevant memory context as a system message.
|
|
33
|
-
*
|
|
34
|
-
* @param {Message[]} messages - The original message array
|
|
35
|
-
* @param {object} memoryContext - The memory context object
|
|
36
|
-
* @param {SearchResponse['results']} memoryContext.results - Array of memory results
|
|
37
|
-
* @returns {Message[]} The enhanced message array with memory context prepended
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const messages = [{ role: 'user', content: 'Hello' }];
|
|
42
|
-
* const context = { results: [{ id: '1', memory: 'User likes pizza' }] };
|
|
43
|
-
* const enhanced = enhanceMessagesWithMemory(messages, context);
|
|
44
|
-
* // enhanced[0] is system message with memory context
|
|
45
|
-
* // enhanced[1] is the original user message
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export declare function enhanceMessagesWithMemory(messages: Message[], memoryContext: {
|
|
49
|
-
results: SearchResponse['results'];
|
|
50
|
-
}): Message[];
|
|
51
|
-
export {};
|
|
52
|
-
//# sourceMappingURL=memory.d.ts.map
|
package/dist/src/memory.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/memory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrD;;GAEG;AACH,UAAU,aAAa;IACrB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAuD7K;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE;IAAE,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;CAAE,GAAG,OAAO,EAAE,CAc/H"}
|
package/dist/src/memory.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { getConfig, saveMemoryId } from './config.js';
|
|
2
|
-
import { generate } from 'random-words';
|
|
3
|
-
/**
|
|
4
|
-
* Builds memory context by searching for relevant memories and generating a memory ID if needed.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} prompt - The user's prompt to search memories for
|
|
7
|
-
* @param {MemoryOptions} [options] - Search options
|
|
8
|
-
* @returns {Promise<{results: SearchResponse['results'], memoryId: string, instruction?: string}>}
|
|
9
|
-
* Object containing search results, the memory ID used/generated, and setup instructions if generated
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const context = await buildMemoryContext("What's my favorite food?", { topK: 3 });
|
|
14
|
-
* console.log(`Found ${context.results.length} relevant memories`);
|
|
15
|
-
* if (context.instruction) console.log(context.instruction);
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export async function buildMemoryContext(prompt, options = {}) {
|
|
19
|
-
const config = await getConfig();
|
|
20
|
-
let memoryId;
|
|
21
|
-
let generated = false;
|
|
22
|
-
if (options.memoryId) {
|
|
23
|
-
memoryId = options.memoryId;
|
|
24
|
-
}
|
|
25
|
-
else if (process.env.SATORI_MEMORY_ID) {
|
|
26
|
-
memoryId = process.env.SATORI_MEMORY_ID;
|
|
27
|
-
}
|
|
28
|
-
else if (config.memoryId) {
|
|
29
|
-
memoryId = config.memoryId;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const words = generate({ exactly: 3 });
|
|
33
|
-
memoryId = words.join('-');
|
|
34
|
-
generated = true;
|
|
35
|
-
}
|
|
36
|
-
const topK = options.topK || 5;
|
|
37
|
-
const url = `${config.baseUrl}/search`;
|
|
38
|
-
const headers = {
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
'Authorization': `Bearer ${config.apiKey}`
|
|
41
|
-
};
|
|
42
|
-
const body = JSON.stringify({
|
|
43
|
-
query: prompt,
|
|
44
|
-
memory_id: memoryId,
|
|
45
|
-
top_k: topK
|
|
46
|
-
});
|
|
47
|
-
const response = await fetch(url, {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers,
|
|
50
|
-
body
|
|
51
|
-
});
|
|
52
|
-
if (!response.ok) {
|
|
53
|
-
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
54
|
-
}
|
|
55
|
-
const data = await response.json();
|
|
56
|
-
const instruction = generated ? `Memory session id: ${memoryId}.` : undefined;
|
|
57
|
-
// Save memory ID to config if generated
|
|
58
|
-
if (generated) {
|
|
59
|
-
saveMemoryId(memoryId).catch(err => {
|
|
60
|
-
console.error('Failed to save memory ID:', err);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
results: data.results,
|
|
65
|
-
memoryId,
|
|
66
|
-
instruction
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Enhances a message array by prepending relevant memory context as a system message.
|
|
71
|
-
*
|
|
72
|
-
* @param {Message[]} messages - The original message array
|
|
73
|
-
* @param {object} memoryContext - The memory context object
|
|
74
|
-
* @param {SearchResponse['results']} memoryContext.results - Array of memory results
|
|
75
|
-
* @returns {Message[]} The enhanced message array with memory context prepended
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* const messages = [{ role: 'user', content: 'Hello' }];
|
|
80
|
-
* const context = { results: [{ id: '1', memory: 'User likes pizza' }] };
|
|
81
|
-
* const enhanced = enhanceMessagesWithMemory(messages, context);
|
|
82
|
-
* // enhanced[0] is system message with memory context
|
|
83
|
-
* // enhanced[1] is the original user message
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
export function enhanceMessagesWithMemory(messages, memoryContext) {
|
|
87
|
-
const validResults = memoryContext.results.filter(r => r.memory && r.memory.trim() !== '' && r.memory !== 'undefined');
|
|
88
|
-
if (validResults.length === 0) {
|
|
89
|
-
return messages;
|
|
90
|
-
}
|
|
91
|
-
const memoryText = validResults.map(r => r.memory).join('\n');
|
|
92
|
-
const systemMessage = {
|
|
93
|
-
role: 'system',
|
|
94
|
-
content: `Relevant context from memory:\n${memoryText}`,
|
|
95
|
-
};
|
|
96
|
-
return [systemMessage, ...messages];
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=memory.js.map
|
package/dist/src/memory.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAYxC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAc,EAAE,UAAyB,EAAE;IACjF,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IAEjC,IAAI,QAAgB,CAAC;IACrB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC9B,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACxC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAC1C,CAAC;SAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC3B,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC7B,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAa,CAAC;QACnD,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B,SAAS,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG;QACd,cAAc,EAAE,kBAAkB;QAClC,eAAe,EAAE,UAAU,MAAM,CAAC,MAAM,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