tibiaway-ai 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.
@@ -0,0 +1,84 @@
1
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
2
+ import { homedir } from 'os';
3
+ import { join } from 'path';
4
+
5
+ const CONFIG_DIR = join(homedir(), '.tibiaway');
6
+ const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
7
+
8
+ const DEFAULT_CONFIG = {
9
+ character: null,
10
+ anthropic_api_key: null,
11
+ language: 'español',
12
+ diary: [],
13
+ last_sync: null,
14
+ };
15
+
16
+ export function ensureConfigDir() {
17
+ if (!existsSync(CONFIG_DIR)) {
18
+ mkdirSync(CONFIG_DIR, { recursive: true });
19
+ }
20
+ }
21
+
22
+ export function readConfig() {
23
+ ensureConfigDir();
24
+ if (!existsSync(CONFIG_FILE)) {
25
+ return { ...DEFAULT_CONFIG };
26
+ }
27
+ try {
28
+ const raw = readFileSync(CONFIG_FILE, 'utf-8');
29
+ return JSON.parse(raw);
30
+ } catch {
31
+ return { ...DEFAULT_CONFIG };
32
+ }
33
+ }
34
+
35
+ export function writeConfig(config) {
36
+ ensureConfigDir();
37
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
38
+ }
39
+
40
+ export function getCharacter() {
41
+ const config = readConfig();
42
+ return config.character || null;
43
+ }
44
+
45
+ export function setCharacter(characterData) {
46
+ const config = readConfig();
47
+ config.character = characterData;
48
+ config.last_sync = new Date().toISOString();
49
+ writeConfig(config);
50
+ }
51
+
52
+ export function getApiKey() {
53
+ return process.env.ANTHROPIC_API_KEY || readConfig().anthropic_api_key || null;
54
+ }
55
+
56
+ export function setApiKey(key) {
57
+ const config = readConfig();
58
+ config.anthropic_api_key = key;
59
+ writeConfig(config);
60
+ }
61
+
62
+ export function addDiaryEntry(entry) {
63
+ const config = readConfig();
64
+ if (!Array.isArray(config.diary)) config.diary = [];
65
+ config.diary.push({
66
+ date: new Date().toISOString(),
67
+ ...entry,
68
+ });
69
+ writeConfig(config);
70
+ }
71
+
72
+ export function getDiary() {
73
+ const config = readConfig();
74
+ return Array.isArray(config.diary) ? config.diary : [];
75
+ }
76
+
77
+ export function isConfigured() {
78
+ const config = readConfig();
79
+ return !!(config.character && (config.anthropic_api_key || process.env.ANTHROPIC_API_KEY));
80
+ }
81
+
82
+ export function getConfigPath() {
83
+ return CONFIG_FILE;
84
+ }