spudmobile-bridge 1.0.0 → 1.0.1
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/index.js +5 -0
- package/dist/supabase.d.ts +9 -0
- package/dist/supabase.js +44 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ async function main() {
|
|
|
61
61
|
const isActive = await bridge.isPairActive(config.pairId);
|
|
62
62
|
if (isActive) {
|
|
63
63
|
console.log(`✅ Using saved pair: ${config.pairId}`);
|
|
64
|
+
await bridge.resolveUserId();
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
67
|
console.log('⚠️ Saved pair is no longer active. Re-pairing...');
|
|
@@ -137,6 +138,10 @@ async function startOperations() {
|
|
|
137
138
|
}
|
|
138
139
|
// Start presence heartbeat
|
|
139
140
|
bridge.startPresenceHeartbeat();
|
|
141
|
+
// Send Connection established message so iOS app shows Connected
|
|
142
|
+
const projectName = config.projectPath?.split('/').filter(Boolean).pop() || 'unknown';
|
|
143
|
+
await bridge.sendSystemMessage(`SYSTEM: Connection established | workspace:${projectName}`);
|
|
144
|
+
console.log('📱 Sent Connection established to iOS');
|
|
140
145
|
// Process any pending messages
|
|
141
146
|
const pending = await bridge.getPendingMessages();
|
|
142
147
|
if (pending.length > 0) {
|
package/dist/supabase.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare class SupabaseBridge {
|
|
|
26
26
|
private deviceId;
|
|
27
27
|
pairId: string | null;
|
|
28
28
|
sessionId: string | null;
|
|
29
|
+
userId: string | null;
|
|
29
30
|
constructor(config: BridgeConfig);
|
|
30
31
|
/**
|
|
31
32
|
* Create a new session, deactivating any old sessions for this pair
|
|
@@ -61,6 +62,14 @@ export declare class SupabaseBridge {
|
|
|
61
62
|
* Activate a device pair using the pair code from callback
|
|
62
63
|
*/
|
|
63
64
|
activatePair(pairCode: string): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve the iOS user's device ID (user_id) from the paired device
|
|
67
|
+
*/
|
|
68
|
+
resolveUserId(): Promise<string | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Send a SYSTEM message to the messages table (Connection established / terminated)
|
|
71
|
+
*/
|
|
72
|
+
sendSystemMessage(content: string): Promise<void>;
|
|
64
73
|
/**
|
|
65
74
|
* Subscribe to new user messages for processing
|
|
66
75
|
*/
|
package/dist/supabase.js
CHANGED
|
@@ -10,6 +10,7 @@ export class SupabaseBridge {
|
|
|
10
10
|
deviceId;
|
|
11
11
|
pairId;
|
|
12
12
|
sessionId = null;
|
|
13
|
+
userId = null;
|
|
13
14
|
constructor(config) {
|
|
14
15
|
this.config = config;
|
|
15
16
|
this.client = createClient(config.supabaseUrl, config.supabaseAnonKey);
|
|
@@ -191,8 +192,50 @@ export class SupabaseBridge {
|
|
|
191
192
|
}
|
|
192
193
|
this.pairId = pair.id;
|
|
193
194
|
saveConfig({ pairId: pair.id, pairCode });
|
|
195
|
+
// Resolve the iOS user_id from the pair
|
|
196
|
+
await this.resolveUserId();
|
|
194
197
|
return pair.id;
|
|
195
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Resolve the iOS user's device ID (user_id) from the paired device
|
|
201
|
+
*/
|
|
202
|
+
async resolveUserId() {
|
|
203
|
+
if (!this.pairId)
|
|
204
|
+
return null;
|
|
205
|
+
const { data, error } = await this.client
|
|
206
|
+
.from('device_pairs')
|
|
207
|
+
.select('ios_device_id')
|
|
208
|
+
.eq('id', this.pairId)
|
|
209
|
+
.single();
|
|
210
|
+
if (error || !data?.ios_device_id) {
|
|
211
|
+
console.error('⚠️ Could not resolve iOS user_id:', error?.message);
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
this.userId = data.ios_device_id?.toLowerCase() ?? null;
|
|
215
|
+
if (this.userId)
|
|
216
|
+
console.log(`👤 Resolved iOS user_id: ${this.userId.slice(0, 8)}…`);
|
|
217
|
+
return this.userId;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Send a SYSTEM message to the messages table (Connection established / terminated)
|
|
221
|
+
*/
|
|
222
|
+
async sendSystemMessage(content) {
|
|
223
|
+
const { error } = await this.client
|
|
224
|
+
.from('messages')
|
|
225
|
+
.insert({
|
|
226
|
+
role: 'agent',
|
|
227
|
+
content,
|
|
228
|
+
status: 'completed',
|
|
229
|
+
client_type: 'spudmobile',
|
|
230
|
+
pair_id: this.pairId,
|
|
231
|
+
session_id: this.sessionId,
|
|
232
|
+
user_id: this.userId,
|
|
233
|
+
sender: 'macOS',
|
|
234
|
+
});
|
|
235
|
+
if (error) {
|
|
236
|
+
console.error('Failed to send system message:', error.message);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
196
239
|
/**
|
|
197
240
|
* Subscribe to new user messages for processing
|
|
198
241
|
*/
|
|
@@ -289,6 +332,7 @@ export class SupabaseBridge {
|
|
|
289
332
|
client_type: 'spudmobile',
|
|
290
333
|
pair_id: this.pairId,
|
|
291
334
|
session_id: this.sessionId,
|
|
335
|
+
user_id: this.userId,
|
|
292
336
|
sender: 'macOS',
|
|
293
337
|
parent_message_id: parentMessageId,
|
|
294
338
|
})
|