1
+ import console from "node:console" ;
2
+
3
+ import type { SDKMessage } from "@captn/react/types" ;
1
4
import { APP_MESSAGE_KEY , DownloadState } from "@captn/utils/constants" ;
2
5
import type { VectorStoreDocument } from "@captn/utils/types" ;
3
6
import { getProperty } from "dot-prop" ;
@@ -10,16 +13,12 @@ import { ID } from "#/enums";
10
13
import type { StoryRequest } from "#/types/story" ;
11
14
import { apps } from "@/apps" ;
12
15
import { captionImages , createStory , maxTokenMap } from "@/ipc/story" ;
16
+ import { logError , logger } from "@/services/logger" ;
13
17
import { downloadsStore , inventoryStore , userStore } from "@/stores" ;
14
18
import { pushToStore } from "@/stores/utils" ;
15
19
import { clone } from "@/utils/git" ;
16
20
import { getCaptainDownloads , getUserData } from "@/utils/path-helpers" ;
17
21
18
- export interface SDKMessage < T > {
19
- payload : T ;
20
- action ?: string ;
21
- }
22
-
23
22
ipcMain . on (
24
23
APP_MESSAGE_KEY ,
25
24
< T > ( _event : IpcMainEvent , { message, appId } : { message : SDKMessage < T > ; appId : string } ) => {
@@ -79,7 +78,7 @@ ipcMain.on(
79
78
await Promise . all ( promises ) ;
80
79
} catch ( error ) {
81
80
// TODO: add "onError" into "clone" to properly catch the error
82
- console . log ( error ) ;
81
+ logError ( error ) ;
83
82
}
84
83
}
85
84
@@ -110,12 +109,13 @@ ipcMain.on(
110
109
111
110
// Seems like no descriptions were generated. Handle as error
112
111
if ( ! imageDescriptions ) {
113
- console . log ( "missing descriptions" ) ;
112
+ logger . error ( "missing descriptions" ) ;
114
113
115
114
return ;
116
115
}
117
116
118
117
// Debugging helper to check how the images were captioned
118
+ // Use native log here as this is only useful while developing
119
119
console . log ( imageDescriptions ) ;
120
120
121
121
const maxTokens = maxTokenMap [ options . length ] * images . length ;
@@ -125,7 +125,7 @@ ipcMain.on(
125
125
{ imageDescriptions, maxTokens, locale, options } ,
126
126
{
127
127
onError ( error ) {
128
- console . log ( error ) ;
128
+ logError ( error ) ;
129
129
} ,
130
130
onChunk ( story ) {
131
131
event . sender . send ( channel , {
@@ -208,13 +208,13 @@ ipcMain.on(
208
208
// Retaining this log facilitates a deeper understanding of the action's payload and helps identify
209
209
// potential issues or anomalies in the data structure or content. It's particularly useful for tracking
210
210
// the flow of data and ensuring that the expected actions are triggered correctly within the SDK.
211
- console . log ( message ) ;
211
+ logger . info ( message ) ;
212
212
switch ( message . action ) {
213
213
case "function" : {
214
214
try {
215
215
handleCaptainAction ( message . payload as VectorStoreDocument [ "payload" ] ) ;
216
216
} catch ( error ) {
217
- console . log ( error ) ;
217
+ logError ( error ) ;
218
218
}
219
219
220
220
if ( apps . prompt ) {
0 commit comments