11import { OpenAI , type ClientOptions } from "openai" ;
2- import { randomUUID } from ' node:crypto' ;
2+ import { randomUUID } from " node:crypto" ;
33import {
44 type NucTokenEnvelope ,
55 NucTokenBuilder ,
@@ -20,12 +20,17 @@ import {
2020 type NilAuthPublicKey ,
2121 RequestType ,
2222 DefaultNilDBConfig ,
23- NilDBDelegation ,
23+ type NilDBDelegation ,
2424} from "./types" ;
2525
2626import { isExpired } from "./utils" ;
27- import { AclDto , CreateOwnedDataRequest , ListDataReferencesResponse , SecretVaultUserClient , Did } from "@nillion/secretvaults" ;
28- import { z } from "zod/v4" ;
27+ import {
28+ type AclDto ,
29+ type CreateOwnedDataRequest ,
30+ type ListDataReferencesResponse ,
31+ SecretVaultUserClient ,
32+ Did ,
33+ } from "@nillion/secretvaults" ;
2934
3035export interface NilaiOpenAIClientOptions
3136 extends NilaiClientOptions ,
@@ -265,11 +270,12 @@ export class NilaiOpenAIClient extends OpenAI {
265270 const client = await SecretVaultUserClient . from ( {
266271 keypair : keypair ,
267272 baseUrls : DefaultNilDBConfig . baseUrls ,
268- } )
273+ } ) ;
269274
270- const response : ListDataReferencesResponse = await client . listDataReferences ( )
275+ const response : ListDataReferencesResponse =
276+ await client . listDataReferences ( ) ;
271277
272- return response
278+ return response ;
273279 }
274280 async requestNildbDelegationToken ( ) : Promise < NilDBDelegation > {
275281 if ( ! this . nilAuthPrivateKey ) {
@@ -281,19 +287,21 @@ export class NilaiOpenAIClient extends OpenAI {
281287
282288 try {
283289 const url = new URL ( `${ this . baseURL } delegation` ) ;
284- url . searchParams . append ( ' prompt_delegation_request' , userDid ) ;
285-
290+ url . searchParams . append ( " prompt_delegation_request" , userDid ) ;
291+
286292 const response = await fetch ( url . toString ( ) , {
287- method : ' GET' ,
293+ method : " GET" ,
288294 headers : {
289- ' Authorization' : `Bearer ${ authToken } ` ,
290- ' Content-Type' : ' application/json' ,
295+ Authorization : `Bearer ${ authToken } ` ,
296+ " Content-Type" : " application/json" ,
291297 } ,
292298 } ) ;
293299
294300 if ( ! response . ok ) {
295301 const errorText = await response . text ( ) ;
296- throw new Error ( `Failed to retrieve the delegation token: ${ errorText } ` ) ;
302+ throw new Error (
303+ `Failed to retrieve the delegation token: ${ errorText } ` ,
304+ ) ;
297305 }
298306
299307 const jsonResponse = await response . json ( ) ;
@@ -307,8 +315,8 @@ export class NilaiOpenAIClient extends OpenAI {
307315 const client = await SecretVaultUserClient . from ( {
308316 keypair : Keypair . from ( this . nilAuthPrivateKey ! . privateKey ( ) ) ,
309317 baseUrls : DefaultNilDBConfig . baseUrls ,
310- blindfold : { operation : ' store' } ,
311- } )
318+ blindfold : { operation : " store" } ,
319+ } ) ;
312320 // Get delegation from nilAI for the user
313321
314322 const delegation = await this . requestNildbDelegationToken ( ) ;
@@ -336,8 +344,8 @@ export class NilaiOpenAIClient extends OpenAI {
336344 {
337345 _id : randomUUID ( ) ,
338346 prompt : {
339- key : ' prompt' ,
340- ' %allot' : prompt , // encrypted field
347+ key : " prompt" ,
348+ " %allot" : prompt , // encrypted field
341349 } ,
342350 } ,
343351 ] ;
@@ -350,27 +358,33 @@ export class NilaiOpenAIClient extends OpenAI {
350358 } ;
351359
352360 const createResponse = await client . createData (
353- delegation . token , createDataRequest
354- )
361+ delegation . token ,
362+ createDataRequest ,
363+ ) ;
355364
356365 const createdIds = [ ] ;
357- for ( const [ nodeId , nodeResponse ] of Object . entries ( createResponse ) ) {
366+ for ( const [ _nodeId , nodeResponse ] of Object . entries ( createResponse ) ) {
358367 if ( nodeResponse . data ?. created ) {
359368 createdIds . push ( ...nodeResponse . data . created ) ;
360369 }
361370 }
362- console . log ( "CreateData response:" , JSON . stringify ( createResponse , null , 2 ) ) ;
363-
371+ console . log (
372+ "CreateData response:" ,
373+ JSON . stringify ( createResponse , null , 2 ) ,
374+ ) ;
375+
364376 // If there are errors, log the detailed error bodies
365377 if ( Array . isArray ( createResponse ) ) {
366378 createResponse . forEach ( ( item , index ) => {
367379 if ( item . error ) {
368- console . log ( `Error ${ index + 1 } details:` , JSON . stringify ( item . error . body , null , 2 ) ) ;
380+ console . log (
381+ `Error ${ index + 1 } details:` ,
382+ JSON . stringify ( item . error . body , null , 2 ) ,
383+ ) ;
369384 }
370385 } ) ;
371386 }
372-
373- return createdIds
374- }
375387
376- }
388+ return createdIds ;
389+ }
390+ }
0 commit comments