Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -16,7 +16,6 @@ app.use(express.json());
|
|
| 16 |
const PORT = process.env.PORT || 7860;
|
| 17 |
const PUBLIC_ENDPOINT = process.env.PUBLIC_ENDPOINT;
|
| 18 |
const SELLER_PRIV_KEY = process.env.SELLER_PRIVATE_KEY;
|
| 19 |
-
const REGISTRY_URL = process.env.REGISTRY_URL || 'https://clinchprotocol.web.app/network-config.json';
|
| 20 |
|
| 21 |
const SUPABASE_URL = process.env.SUPABASE_URL;
|
| 22 |
const SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY;
|
|
@@ -28,9 +27,9 @@ if (!SUPABASE_URL || !SUPABASE_SERVICE_KEY || !PUBLIC_ENDPOINT || !SELLER_PRIV_K
|
|
| 28 |
|
| 29 |
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_KEY);
|
| 30 |
|
| 31 |
-
// Protocol v0.2.0 Core Initialization
|
|
|
|
| 32 |
const core = new ClinchCore({
|
| 33 |
-
registryUrl: REGISTRY_URL,
|
| 34 |
privateKeyHex: SELLER_PRIV_KEY
|
| 35 |
});
|
| 36 |
|
|
@@ -111,7 +110,6 @@ Output ONLY valid JSON matching exactly: {"price": number, "message": "string"}`
|
|
| 111 |
const clean = responseText.replace(/```json|```/g, "").trim();
|
| 112 |
return JSON.parse(clean);
|
| 113 |
} catch (e) {
|
| 114 |
-
// Fallback calculation if LLM format breaks
|
| 115 |
return { price: currentPrice * 0.9, message: "Ginger AI suggests a 10% compromise to keep the deal moving." };
|
| 116 |
}
|
| 117 |
}
|
|
@@ -167,7 +165,7 @@ app.post('/anp/v1/register-handle', async (req, res) => {
|
|
| 167 |
const { error } = await supabase.from('p2p_handles').upsert({
|
| 168 |
handle: normalizedHandle,
|
| 169 |
session_id,
|
| 170 |
-
pub_key: session_pub_key,
|
| 171 |
updated_at: new Date().toISOString()
|
| 172 |
});
|
| 173 |
|
|
@@ -181,10 +179,9 @@ app.post('/anp/v1/register-handle', async (req, res) => {
|
|
| 181 |
});
|
| 182 |
|
| 183 |
// ============================================================================
|
| 184 |
-
// ANP HANDSHAKE ROUTE (Creation & Joining
|
| 185 |
// ============================================================================
|
| 186 |
app.post('/anp/v1/handshake', async (req, res) => {
|
| 187 |
-
// Note: In v0.2.0, the Registry Proxy automatically injects 'buyer_pub_key'
|
| 188 |
const { session_id, buyer_pub_key, constraints } = req.body;
|
| 189 |
|
| 190 |
// Explicitly sync seller's local state machine
|
|
@@ -332,7 +329,6 @@ app.post('/anp/v1/counter', async (req, res) => {
|
|
| 332 |
// ============================================================================
|
| 333 |
app.post('/anp/v1/sign_request', (req, res) => {
|
| 334 |
try {
|
| 335 |
-
// Ginger acts as the notary for the P2P room
|
| 336 |
const sig = core.signAsSeller(req.body.artifact);
|
| 337 |
res.json({ sellerSignature: sig });
|
| 338 |
} catch (e) {
|
|
@@ -348,7 +344,7 @@ app.listen(PORT, async () => {
|
|
| 348 |
console.log(` Stable Public Endpoint: ${PUBLIC_ENDPOINT}\n`);
|
| 349 |
|
| 350 |
try {
|
| 351 |
-
console.log("⏳ Initializing Protocol Core (
|
| 352 |
await core.initialize();
|
| 353 |
|
| 354 |
// Refresh token every 5 days before the 7-day expiry
|
|
@@ -357,7 +353,6 @@ app.listen(PORT, async () => {
|
|
| 357 |
await core.registerNode(`${PUBLIC_ENDPOINT}/anp/v1`, ['p2p_bridge', 'mediation', 'scheduling'], ['p2p_bridge', 'room_routing', 'ai_mediator']);
|
| 358 |
console.log("✓ Successfully registered 'ginger.anp' to the Network.");
|
| 359 |
|
| 360 |
-
// Warm up the AI Mediator in the background
|
| 361 |
getMediatorAI().catch(e => console.error("[AI] Failed to load Qwen 1.5B:", e.message));
|
| 362 |
|
| 363 |
} catch (e) {
|
|
|
|
| 16 |
const PORT = process.env.PORT || 7860;
|
| 17 |
const PUBLIC_ENDPOINT = process.env.PUBLIC_ENDPOINT;
|
| 18 |
const SELLER_PRIV_KEY = process.env.SELLER_PRIVATE_KEY;
|
|
|
|
| 19 |
|
| 20 |
const SUPABASE_URL = process.env.SUPABASE_URL;
|
| 21 |
const SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY;
|
|
|
|
| 27 |
|
| 28 |
const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_KEY);
|
| 29 |
|
| 30 |
+
// Protocol v0.2.0 Core Initialization
|
| 31 |
+
// (Dynamic Firebase Discovery handles the registryURL automatically now)
|
| 32 |
const core = new ClinchCore({
|
|
|
|
| 33 |
privateKeyHex: SELLER_PRIV_KEY
|
| 34 |
});
|
| 35 |
|
|
|
|
| 110 |
const clean = responseText.replace(/```json|```/g, "").trim();
|
| 111 |
return JSON.parse(clean);
|
| 112 |
} catch (e) {
|
|
|
|
| 113 |
return { price: currentPrice * 0.9, message: "Ginger AI suggests a 10% compromise to keep the deal moving." };
|
| 114 |
}
|
| 115 |
}
|
|
|
|
| 165 |
const { error } = await supabase.from('p2p_handles').upsert({
|
| 166 |
handle: normalizedHandle,
|
| 167 |
session_id,
|
| 168 |
+
pub_key: session_pub_key,
|
| 169 |
updated_at: new Date().toISOString()
|
| 170 |
});
|
| 171 |
|
|
|
|
| 179 |
});
|
| 180 |
|
| 181 |
// ============================================================================
|
| 182 |
+
// ANP HANDSHAKE ROUTE (Creation & Joining)
|
| 183 |
// ============================================================================
|
| 184 |
app.post('/anp/v1/handshake', async (req, res) => {
|
|
|
|
| 185 |
const { session_id, buyer_pub_key, constraints } = req.body;
|
| 186 |
|
| 187 |
// Explicitly sync seller's local state machine
|
|
|
|
| 329 |
// ============================================================================
|
| 330 |
app.post('/anp/v1/sign_request', (req, res) => {
|
| 331 |
try {
|
|
|
|
| 332 |
const sig = core.signAsSeller(req.body.artifact);
|
| 333 |
res.json({ sellerSignature: sig });
|
| 334 |
} catch (e) {
|
|
|
|
| 344 |
console.log(` Stable Public Endpoint: ${PUBLIC_ENDPOINT}\n`);
|
| 345 |
|
| 346 |
try {
|
| 347 |
+
console.log("⏳ Initializing Protocol Core (Firebase Discovery & PoW)...");
|
| 348 |
await core.initialize();
|
| 349 |
|
| 350 |
// Refresh token every 5 days before the 7-day expiry
|
|
|
|
| 353 |
await core.registerNode(`${PUBLIC_ENDPOINT}/anp/v1`, ['p2p_bridge', 'mediation', 'scheduling'], ['p2p_bridge', 'room_routing', 'ai_mediator']);
|
| 354 |
console.log("✓ Successfully registered 'ginger.anp' to the Network.");
|
| 355 |
|
|
|
|
| 356 |
getMediatorAI().catch(e => console.error("[AI] Failed to load Qwen 1.5B:", e.message));
|
| 357 |
|
| 358 |
} catch (e) {
|