myceliumail-mcp 1.0.4 → 1.0.6
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/dist/lib/config.js +18 -7
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/storage.js +43 -30
- package/dist/lib/storage.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/config.ts +18 -7
- package/src/lib/storage.ts +50 -34
package/dist/lib/config.js
CHANGED
|
@@ -26,18 +26,29 @@ function loadFileConfig() {
|
|
|
26
26
|
return {};
|
|
27
27
|
}
|
|
28
28
|
export function getAgentId() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const fromEnv = process.env.MYCELIUMAIL_AGENT_ID || process.env.MYCELIUMAIL_AGENT;
|
|
30
|
+
const fromFile = loadFileConfig().agent_id;
|
|
31
|
+
const final = fromEnv || fromFile || 'anonymous';
|
|
32
|
+
// console.error(`[Debug] Agent ID: ${final} (Env: ${fromEnv}, File: ${fromFile})`);
|
|
33
|
+
return final;
|
|
33
34
|
}
|
|
34
35
|
export function getSupabaseUrl() {
|
|
35
|
-
|
|
36
|
+
const url = process.env.SUPABASE_URL || loadFileConfig().supabase_url;
|
|
37
|
+
// console.error(`[Debug] Supabase URL: ${url ? 'Found' : 'Missing'}`);
|
|
38
|
+
return url;
|
|
36
39
|
}
|
|
37
40
|
export function getSupabaseKey() {
|
|
38
|
-
|
|
41
|
+
const key = process.env.SUPABASE_ANON_KEY || loadFileConfig().supabase_key;
|
|
42
|
+
// console.error(`[Debug] Supabase Key: ${key ? 'Found' : 'Missing'}`);
|
|
43
|
+
return key;
|
|
39
44
|
}
|
|
40
45
|
export function hasSupabase() {
|
|
41
|
-
|
|
46
|
+
const has = !!(getSupabaseUrl() && getSupabaseKey());
|
|
47
|
+
console.error(`[Debug] hasSupabase: ${has}`);
|
|
48
|
+
if (!has) {
|
|
49
|
+
console.error(`[Debug] Env URL: ${!!process.env.SUPABASE_URL}, Key: ${!!process.env.SUPABASE_ANON_KEY}`);
|
|
50
|
+
console.error(`[Debug] File URL: ${!!loadFileConfig().supabase_url}, Key: ${!!loadFileConfig().supabase_key}`);
|
|
51
|
+
}
|
|
52
|
+
return has;
|
|
42
53
|
}
|
|
43
54
|
//# sourceMappingURL=config.js.map
|
package/dist/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAQnE,IAAI,gBAAgB,GAAsB,IAAI,CAAC;AAE/C,SAAS,cAAc;IACnB,IAAI,gBAAgB;QAAE,OAAO,gBAAgB,CAAC;IAE9C,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YAC/C,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnC,OAAO,gBAAiB,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACL,sBAAsB;QAC1B,CAAC;IACL,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC;AAED,MAAM,UAAU,UAAU;IACtB,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC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AACf,CAAC;AAED,MAAM,UAAU,WAAW;IACvB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,cAAc,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC;IACrD,OAAO,CAAC,KAAK,CAAC,wBAAwB,GAAG,EAAE,CAAC,CAAC;IAC7C,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,UAAU,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACzG,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,cAAc,EAAE,CAAC,YAAY,UAAU,CAAC,CAAC,cAAc,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;IACnH,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/dist/lib/storage.js
CHANGED
|
@@ -35,21 +35,31 @@ function toMessage(stored) {
|
|
|
35
35
|
// Supabase helpers
|
|
36
36
|
async function supabaseRequest(path, options = {}) {
|
|
37
37
|
const url = `${getSupabaseUrl()}/rest/v1${path}`;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
// console.error(`[Debug] Supabase Request: ${options.method || 'GET'} ${url}`);
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetch(url, {
|
|
41
|
+
...options,
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
'apikey': getSupabaseKey(),
|
|
45
|
+
'Authorization': `Bearer ${getSupabaseKey()}`,
|
|
46
|
+
'Prefer': options.method === 'POST' ? 'return=representation' : 'return=minimal',
|
|
47
|
+
...options.headers,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const text = await response.text();
|
|
52
|
+
console.error(`[Debug] Supabase Error ${response.status}: ${text}`);
|
|
53
|
+
throw new Error(text);
|
|
54
|
+
}
|
|
55
|
+
if (response.status === 204)
|
|
56
|
+
return {};
|
|
57
|
+
return response.json();
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error(`[Debug] Fetch Error:`, err);
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
export async function sendMessage(sender, recipient, subject, body, options) {
|
|
55
65
|
const newMessage = {
|
|
@@ -71,10 +81,10 @@ export async function sendMessage(sender, recipient, subject, body, options) {
|
|
|
71
81
|
const [result] = await supabaseRequest('/agent_messages', {
|
|
72
82
|
method: 'POST',
|
|
73
83
|
body: JSON.stringify({
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
from_agent: newMessage.sender,
|
|
85
|
+
to_agent: newMessage.recipient,
|
|
76
86
|
subject: newMessage.subject || null,
|
|
77
|
-
|
|
87
|
+
message: newMessage.body || null,
|
|
78
88
|
encrypted: newMessage.encrypted,
|
|
79
89
|
ciphertext: newMessage.ciphertext,
|
|
80
90
|
nonce: newMessage.nonce,
|
|
@@ -86,7 +96,8 @@ export async function sendMessage(sender, recipient, subject, body, options) {
|
|
|
86
96
|
id: result.id
|
|
87
97
|
});
|
|
88
98
|
}
|
|
89
|
-
catch {
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error(`[Debug] sendMessage Error:`, err);
|
|
90
101
|
// Fall through to local
|
|
91
102
|
}
|
|
92
103
|
}
|
|
@@ -99,7 +110,7 @@ export async function sendMessage(sender, recipient, subject, body, options) {
|
|
|
99
110
|
export async function getInbox(agentId, options) {
|
|
100
111
|
if (hasSupabase()) {
|
|
101
112
|
try {
|
|
102
|
-
let query = `/agent_messages?
|
|
113
|
+
let query = `/agent_messages?to_agent=eq.${agentId}&order=created_at.desc`;
|
|
103
114
|
if (options?.unreadOnly)
|
|
104
115
|
query += '&read=eq.false';
|
|
105
116
|
if (options?.limit)
|
|
@@ -107,20 +118,21 @@ export async function getInbox(agentId, options) {
|
|
|
107
118
|
const results = await supabaseRequest(query);
|
|
108
119
|
return results.map(r => ({
|
|
109
120
|
id: r.id,
|
|
110
|
-
sender: r.
|
|
111
|
-
recipient: r.
|
|
121
|
+
sender: r.from_agent,
|
|
122
|
+
recipient: r.to_agent,
|
|
112
123
|
subject: r.subject || '',
|
|
113
|
-
body: r.
|
|
124
|
+
body: r.message || '',
|
|
114
125
|
encrypted: r.encrypted,
|
|
115
126
|
ciphertext: r.ciphertext,
|
|
116
127
|
nonce: r.nonce,
|
|
117
128
|
senderPublicKey: r.sender_public_key,
|
|
118
129
|
read: r.read,
|
|
119
|
-
archived:
|
|
130
|
+
archived: false,
|
|
120
131
|
createdAt: new Date(r.created_at),
|
|
121
132
|
}));
|
|
122
133
|
}
|
|
123
|
-
catch {
|
|
134
|
+
catch (err) {
|
|
135
|
+
console.error(`[Debug] getInbox Error:`, err);
|
|
124
136
|
// Fall through to local
|
|
125
137
|
}
|
|
126
138
|
}
|
|
@@ -142,21 +154,22 @@ export async function getMessage(id) {
|
|
|
142
154
|
const r = results[0];
|
|
143
155
|
return {
|
|
144
156
|
id: r.id,
|
|
145
|
-
sender: r.
|
|
146
|
-
recipient: r.
|
|
157
|
+
sender: r.from_agent,
|
|
158
|
+
recipient: r.to_agent,
|
|
147
159
|
subject: r.subject || '',
|
|
148
|
-
body: r.
|
|
160
|
+
body: r.message || '',
|
|
149
161
|
encrypted: r.encrypted,
|
|
150
162
|
ciphertext: r.ciphertext,
|
|
151
163
|
nonce: r.nonce,
|
|
152
164
|
senderPublicKey: r.sender_public_key,
|
|
153
165
|
read: r.read,
|
|
154
|
-
archived:
|
|
166
|
+
archived: false,
|
|
155
167
|
createdAt: new Date(r.created_at),
|
|
156
168
|
};
|
|
157
169
|
}
|
|
158
170
|
}
|
|
159
|
-
catch {
|
|
171
|
+
catch (err) {
|
|
172
|
+
console.error(`[Debug] getMessage Error:`, err);
|
|
160
173
|
// Fall through
|
|
161
174
|
}
|
|
162
175
|
}
|
package/dist/lib/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/lib/storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1E,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;AACzD,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AAqBtD,SAAS,aAAa;IAClB,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxB,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB;IACtB,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1C,IAAI,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAyB;IAChD,aAAa,EAAE,CAAC;IAChB,aAAa,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAA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E,CAAC,CAAC;IACjD,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7B,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC9B,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/src/lib/config.ts
CHANGED
|
@@ -36,20 +36,31 @@ function loadFileConfig(): FileConfig {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function getAgentId(): string {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const fromEnv = process.env.MYCELIUMAIL_AGENT_ID || process.env.MYCELIUMAIL_AGENT;
|
|
40
|
+
const fromFile = loadFileConfig().agent_id;
|
|
41
|
+
const final = fromEnv || fromFile || 'anonymous';
|
|
42
|
+
// console.error(`[Debug] Agent ID: ${final} (Env: ${fromEnv}, File: ${fromFile})`);
|
|
43
|
+
return final;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export function getSupabaseUrl(): string | undefined {
|
|
46
|
-
|
|
47
|
+
const url = process.env.SUPABASE_URL || loadFileConfig().supabase_url;
|
|
48
|
+
// console.error(`[Debug] Supabase URL: ${url ? 'Found' : 'Missing'}`);
|
|
49
|
+
return url;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
export function getSupabaseKey(): string | undefined {
|
|
50
|
-
|
|
53
|
+
const key = process.env.SUPABASE_ANON_KEY || loadFileConfig().supabase_key;
|
|
54
|
+
// console.error(`[Debug] Supabase Key: ${key ? 'Found' : 'Missing'}`);
|
|
55
|
+
return key;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
export function hasSupabase(): boolean {
|
|
54
|
-
|
|
59
|
+
const has = !!(getSupabaseUrl() && getSupabaseKey());
|
|
60
|
+
console.error(`[Debug] hasSupabase: ${has}`);
|
|
61
|
+
if (!has) {
|
|
62
|
+
console.error(`[Debug] Env URL: ${!!process.env.SUPABASE_URL}, Key: ${!!process.env.SUPABASE_ANON_KEY}`);
|
|
63
|
+
console.error(`[Debug] File URL: ${!!loadFileConfig().supabase_url}, Key: ${!!loadFileConfig().supabase_key}`);
|
|
64
|
+
}
|
|
65
|
+
return has;
|
|
55
66
|
}
|
package/src/lib/storage.ts
CHANGED
|
@@ -59,19 +59,32 @@ function toMessage(stored: StoredMessage): Message {
|
|
|
59
59
|
// Supabase helpers
|
|
60
60
|
async function supabaseRequest<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|
61
61
|
const url = `${getSupabaseUrl()}/rest/v1${path}`;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
// console.error(`[Debug] Supabase Request: ${options.method || 'GET'} ${url}`);
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const response = await fetch(url, {
|
|
66
|
+
...options,
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
'apikey': getSupabaseKey()!,
|
|
70
|
+
'Authorization': `Bearer ${getSupabaseKey()}`,
|
|
71
|
+
'Prefer': options.method === 'POST' ? 'return=representation' : 'return=minimal',
|
|
72
|
+
...options.headers,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const text = await response.text();
|
|
78
|
+
console.error(`[Debug] Supabase Error ${response.status}: ${text}`);
|
|
79
|
+
throw new Error(text);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (response.status === 204) return {} as T;
|
|
83
|
+
return response.json() as Promise<T>;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(`[Debug] Fetch Error:`, err);
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
export async function sendMessage(
|
|
@@ -106,10 +119,10 @@ export async function sendMessage(
|
|
|
106
119
|
const [result] = await supabaseRequest<StoredMessage[]>('/agent_messages', {
|
|
107
120
|
method: 'POST',
|
|
108
121
|
body: JSON.stringify({
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
from_agent: newMessage.sender,
|
|
123
|
+
to_agent: newMessage.recipient,
|
|
111
124
|
subject: newMessage.subject || null,
|
|
112
|
-
|
|
125
|
+
message: newMessage.body || null,
|
|
113
126
|
encrypted: newMessage.encrypted,
|
|
114
127
|
ciphertext: newMessage.ciphertext,
|
|
115
128
|
nonce: newMessage.nonce,
|
|
@@ -120,7 +133,8 @@ export async function sendMessage(
|
|
|
120
133
|
...newMessage,
|
|
121
134
|
id: (result as unknown as { id: string }).id
|
|
122
135
|
});
|
|
123
|
-
} catch {
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error(`[Debug] sendMessage Error:`, err);
|
|
124
138
|
// Fall through to local
|
|
125
139
|
}
|
|
126
140
|
}
|
|
@@ -138,32 +152,33 @@ export async function getInbox(
|
|
|
138
152
|
): Promise<Message[]> {
|
|
139
153
|
if (hasSupabase()) {
|
|
140
154
|
try {
|
|
141
|
-
let query = `/agent_messages?
|
|
155
|
+
let query = `/agent_messages?to_agent=eq.${agentId}&order=created_at.desc`;
|
|
142
156
|
if (options?.unreadOnly) query += '&read=eq.false';
|
|
143
157
|
if (options?.limit) query += `&limit=${options.limit}`;
|
|
144
158
|
|
|
145
159
|
const results = await supabaseRequest<Array<{
|
|
146
|
-
id: string;
|
|
147
|
-
subject: string;
|
|
160
|
+
id: string; from_agent: string; to_agent: string;
|
|
161
|
+
subject: string; message: string; encrypted: boolean;
|
|
148
162
|
ciphertext: string; nonce: string; sender_public_key: string;
|
|
149
|
-
read: boolean;
|
|
163
|
+
read: boolean; created_at: string;
|
|
150
164
|
}>>(query);
|
|
151
165
|
|
|
152
166
|
return results.map(r => ({
|
|
153
167
|
id: r.id,
|
|
154
|
-
sender: r.
|
|
155
|
-
recipient: r.
|
|
168
|
+
sender: r.from_agent,
|
|
169
|
+
recipient: r.to_agent,
|
|
156
170
|
subject: r.subject || '',
|
|
157
|
-
body: r.
|
|
171
|
+
body: r.message || '',
|
|
158
172
|
encrypted: r.encrypted,
|
|
159
173
|
ciphertext: r.ciphertext,
|
|
160
174
|
nonce: r.nonce,
|
|
161
175
|
senderPublicKey: r.sender_public_key,
|
|
162
176
|
read: r.read,
|
|
163
|
-
archived:
|
|
177
|
+
archived: false,
|
|
164
178
|
createdAt: new Date(r.created_at),
|
|
165
179
|
}));
|
|
166
|
-
} catch {
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.error(`[Debug] getInbox Error:`, err);
|
|
167
182
|
// Fall through to local
|
|
168
183
|
}
|
|
169
184
|
}
|
|
@@ -181,30 +196,31 @@ export async function getMessage(id: string): Promise<Message | null> {
|
|
|
181
196
|
if (hasSupabase()) {
|
|
182
197
|
try {
|
|
183
198
|
const results = await supabaseRequest<Array<{
|
|
184
|
-
id: string;
|
|
185
|
-
subject: string;
|
|
199
|
+
id: string; from_agent: string; to_agent: string;
|
|
200
|
+
subject: string; message: string; encrypted: boolean;
|
|
186
201
|
ciphertext: string; nonce: string; sender_public_key: string;
|
|
187
|
-
read: boolean;
|
|
202
|
+
read: boolean; created_at: string;
|
|
188
203
|
}>>(`/agent_messages?id=eq.${id}`);
|
|
189
204
|
|
|
190
205
|
if (results.length > 0) {
|
|
191
206
|
const r = results[0];
|
|
192
207
|
return {
|
|
193
208
|
id: r.id,
|
|
194
|
-
sender: r.
|
|
195
|
-
recipient: r.
|
|
209
|
+
sender: r.from_agent,
|
|
210
|
+
recipient: r.to_agent,
|
|
196
211
|
subject: r.subject || '',
|
|
197
|
-
body: r.
|
|
212
|
+
body: r.message || '',
|
|
198
213
|
encrypted: r.encrypted,
|
|
199
214
|
ciphertext: r.ciphertext,
|
|
200
215
|
nonce: r.nonce,
|
|
201
216
|
senderPublicKey: r.sender_public_key,
|
|
202
217
|
read: r.read,
|
|
203
|
-
archived:
|
|
218
|
+
archived: false,
|
|
204
219
|
createdAt: new Date(r.created_at),
|
|
205
220
|
};
|
|
206
221
|
}
|
|
207
|
-
} catch {
|
|
222
|
+
} catch (err) {
|
|
223
|
+
console.error(`[Debug] getMessage Error:`, err);
|
|
208
224
|
// Fall through
|
|
209
225
|
}
|
|
210
226
|
}
|