Download TaskBridgeService.ts from VoidBreach/Chancellor: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/VoidBreach/Chancellor/resolve/main/TaskBridgeService.ts
- Command line
-
hf download hf://VoidBreach/Chancellor/TaskBridgeService.ts
-
curl -L -o TaskBridgeService.ts https://huggingface.co/VoidBreach/Chancellor/resolve/main/TaskBridgeService.ts
1.98 kB
| import { | |
| doc, | |
| getDoc, | |
| updateDoc, | |
| setDoc, | |
| query, | |
| collection, | |
| where, | |
| getDocs, | |
| limit, | |
| orderBy, | |
| } from 'firebase/firestore'; | |
| import { db, getActiveUser } from './cloudSubstrateService'; | |
| import { RegistrationService } from './RegistrationService'; | |
| // The Computation Pipeline | |
| export const TaskBridgeService = { | |
| /** | |
| * Acquire an encrypted task for the node. | |
| */ | |
| async acquireTask(nodeId: string) { | |
| if (!getActiveUser()) throw new Error('AUTHORIZATION_REQUIRED'); | |
| // 1. Get the Node and check status | |
| const nodeRef = doc(db, 'virtualNodes', nodeId); | |
| const nodeSnap = await getDoc(nodeRef); | |
| if (!nodeSnap.exists() || nodeSnap.data().status !== 'registered') { | |
| throw new Error('NODE_UNAVAILABLE_OR_UNAUTHORIZED'); | |
| } | |
| // 2. Find an available task | |
| const tasksRef = collection(db, 'computationalTasks'); | |
| const q = query(tasksRef, where('status', '==', 'pending'), limit(1)); | |
| const taskSnap = await getDocs(q); | |
| if (taskSnap.empty) return null; | |
| const taskDoc = taskSnap.docs[0]; | |
| const taskData = taskDoc.data(); | |
| // 3. Mark as assigned | |
| await updateDoc(taskDoc.ref, { | |
| status: 'assigned', | |
| assignedTo: nodeId, | |
| assignedAt: Date.now(), | |
| }); | |
| // Update node last seen | |
| await updateDoc(nodeRef, { | |
| status: 'active', | |
| lastSeen: Date.now(), | |
| }); | |
| return { | |
| taskId: taskDoc.id, | |
| payload: taskData.encryptedPayload, | |
| checksum: taskData.checksum, | |
| }; | |
| }, | |
| /** | |
| * Submit result and sign | |
| */ | |
| async submitResult(nodeId: string, taskId: string, encryptedResult: string, signature: string) { | |
| const taskRef = doc(db, 'computationalTasks', taskId); | |
| await updateDoc(taskRef, { | |
| status: 'completed', | |
| encryptedResult, | |
| signature, | |
| completedAt: Date.now(), | |
| }); | |
| // Update node status | |
| await updateDoc(doc(db, 'virtualNodes', nodeId), { | |
| status: 'registered', | |
| lastSeen: Date.now(), | |
| }); | |
| }, | |
| }; | |