@@ -2,11 +2,16 @@ import type {
22 ApiResponse ,
33 AppDetails ,
44 AppListItem ,
5+ AppVisibility ,
6+ AppWithFavoriteStatus ,
57 BuildOptions ,
68 BuildStartEvent ,
79 Credentials ,
10+ DeleteResult ,
811 PublicAppsQuery ,
12+ ToggleResult ,
913 VibeClientOptions ,
14+ VisibilityUpdateResult ,
1015} from './types' ;
1116import { HttpClient } from './http' ;
1217import { parseNdjsonStream } from './ndjson' ;
@@ -25,7 +30,7 @@ function toQueryString(query: Record<string, string | number | undefined>): stri
2530export class VibeClient {
2631 private http : HttpClient ;
2732
28- constructor ( private options : VibeClientOptions ) {
33+ constructor ( options : VibeClientOptions ) {
2934 this . http = new HttpClient ( options ) ;
3035 }
3136
@@ -35,9 +40,6 @@ export class VibeClient {
3540
3641 /**
3742 * Creates a new agent/app from a prompt and returns a BuildSession.
38- *
39- * Current platform requirement: `token` must be a valid JWT access token.
40- * Later: `apiKey` will be exchanged for a short-lived JWT.
4143 */
4244 async build ( prompt : string , options : BuildOptions = { } ) : Promise < BuildSession > {
4345 const body = {
@@ -48,7 +50,6 @@ export class VibeClient {
4850 behaviorType : options . behaviorType ,
4951 projectType : options . projectType ,
5052 images : options . images ,
51- // Future: credentials
5253 credentials : options . credentials ,
5354 } ;
5455
@@ -79,12 +80,13 @@ export class VibeClient {
7980 throw new Error ( 'No start event received from /api/agent' ) ;
8081 }
8182
82- const session = new BuildSession ( this . options , start , {
83- getAuthToken : ( ) => this . http . getToken ( ) ,
83+ const session = new BuildSession ( start , {
84+ httpClient : this . http ,
8485 ...( options . credentials ? { defaultCredentials : options . credentials } : { } ) ,
8586 } ) ;
87+
8688 if ( options . autoConnect ?? true ) {
87- session . connect ( ) ;
89+ await session . connect ( ) ;
8890 if ( options . autoGenerate ?? true ) {
8991 session . startGeneration ( ) ;
9092 }
@@ -109,13 +111,14 @@ export class VibeClient {
109111 websocketUrl : data . data . websocketUrl ,
110112 } ;
111113
112- return new BuildSession ( this . options , start , {
113- getAuthToken : ( ) => this . http . getToken ( ) ,
114+ return new BuildSession ( start , {
115+ httpClient : this . http ,
114116 ...( options . credentials ? { defaultCredentials : options . credentials } : { } ) ,
115117 } ) ;
116118 }
117119
118120 apps = {
121+ /** List public apps with optional filtering and pagination. */
119122 listPublic : async ( query : PublicAppsQuery = { } ) => {
120123 const qs = toQueryString ( {
121124 limit : query . limit ,
@@ -132,20 +135,72 @@ export class VibeClient {
132135 ) ;
133136 } ,
134137
138+ /** List all apps owned by the authenticated user. */
135139 listMine : async ( ) => {
136- return this . http . fetchJson < ApiResponse < { apps : AppListItem [ ] } > > ( '/api/apps' , {
140+ return this . http . fetchJson < ApiResponse < { apps : AppWithFavoriteStatus [ ] } > > ( '/api/apps' , {
141+ method : 'GET' ,
142+ headers : await this . http . headers ( ) ,
143+ } ) ;
144+ } ,
145+
146+ /** List recent apps (last 10) for the authenticated user. */
147+ listRecent : async ( ) => {
148+ return this . http . fetchJson < ApiResponse < { apps : AppWithFavoriteStatus [ ] } > > ( '/api/apps/recent' , {
137149 method : 'GET' ,
138150 headers : await this . http . headers ( ) ,
139151 } ) ;
140152 } ,
141153
154+ /** List favorite apps for the authenticated user. */
155+ listFavorites : async ( ) => {
156+ return this . http . fetchJson < ApiResponse < { apps : AppWithFavoriteStatus [ ] } > > ( '/api/apps/favorites' , {
157+ method : 'GET' ,
158+ headers : await this . http . headers ( ) ,
159+ } ) ;
160+ } ,
161+
162+ /** Get detailed information about a specific app. */
142163 get : async ( appId : string ) => {
143164 return this . http . fetchJson < ApiResponse < AppDetails > > ( `/api/apps/${ appId } ` , {
144165 method : 'GET' ,
145166 headers : await this . http . headers ( ) ,
146167 } ) ;
147168 } ,
148169
170+ /** Delete an app (owner only). */
171+ delete : async ( appId : string ) => {
172+ return this . http . fetchJson < ApiResponse < DeleteResult > > ( `/api/apps/${ appId } ` , {
173+ method : 'DELETE' ,
174+ headers : await this . http . headers ( ) ,
175+ } ) ;
176+ } ,
177+
178+ /** Update app visibility (owner only). */
179+ setVisibility : async ( appId : string , visibility : AppVisibility ) => {
180+ return this . http . fetchJson < ApiResponse < VisibilityUpdateResult > > ( `/api/apps/${ appId } /visibility` , {
181+ method : 'PUT' ,
182+ headers : await this . http . headers ( { 'Content-Type' : 'application/json' } ) ,
183+ body : JSON . stringify ( { visibility } ) ,
184+ } ) ;
185+ } ,
186+
187+ /** Toggle star/bookmark status on an app. */
188+ toggleStar : async ( appId : string ) => {
189+ return this . http . fetchJson < ApiResponse < ToggleResult > > ( `/api/apps/${ appId } /star` , {
190+ method : 'POST' ,
191+ headers : await this . http . headers ( ) ,
192+ } ) ;
193+ } ,
194+
195+ /** Toggle favorite status on an app. */
196+ toggleFavorite : async ( appId : string ) => {
197+ return this . http . fetchJson < ApiResponse < ToggleResult > > ( `/api/apps/${ appId } /favorite` , {
198+ method : 'POST' ,
199+ headers : await this . http . headers ( ) ,
200+ } ) ;
201+ } ,
202+
203+ /** Generate a git clone token for an app (owner only). */
149204 getGitCloneToken : async ( appId : string ) => {
150205 return this . http . fetchJson <
151206 ApiResponse < { token : string ; expiresIn : number ; expiresAt : string ; cloneUrl : string } >
0 commit comments