@@ -104,8 +104,7 @@ export class AttachmentManager {
104
104
} else if (
105
105
attachment . contentType ?. startsWith ( "video/" ) ||
106
106
this . runtime
107
- . getService ( ServiceType . VIDEO )
108
- . getInstance < IVideoService > ( )
107
+ . getService < IVideoService > ( ServiceType . VIDEO )
109
108
. isVideoUrl ( attachment . url )
110
109
) {
111
110
media = await this . processVideoAttachment ( attachment ) ;
@@ -137,10 +136,16 @@ export class AttachmentManager {
137
136
throw new Error ( "Unsupported audio/video format" ) ;
138
137
}
139
138
140
- const transcription = await this . runtime
141
- . getService ( ServiceType . TRANSCRIPTION )
142
- . getInstance < ITranscriptionService > ( )
143
- . transcribeAttachment ( audioBuffer ) ;
139
+ const transcriptionService =
140
+ this . runtime . getService < ITranscriptionService > (
141
+ ServiceType . TRANSCRIPTION
142
+ ) ;
143
+ if ( ! transcriptionService ) {
144
+ throw new Error ( "Transcription service not found" ) ;
145
+ }
146
+
147
+ const transcription =
148
+ await transcriptionService . transcribeAttachment ( audioBuffer ) ;
144
149
const { title, description } = await generateSummary (
145
150
this . runtime ,
146
151
transcription
@@ -220,8 +225,7 @@ export class AttachmentManager {
220
225
const response = await fetch ( attachment . url ) ;
221
226
const pdfBuffer = await response . arrayBuffer ( ) ;
222
227
const text = await this . runtime
223
- . getService ( ServiceType . PDF )
224
- . getInstance < IPdfService > ( )
228
+ . getService < IPdfService > ( ServiceType . PDF )
225
229
. convertPdfToText ( Buffer . from ( pdfBuffer ) ) ;
226
230
const { title, description } = await generateSummary (
227
231
this . runtime ,
@@ -289,8 +293,9 @@ export class AttachmentManager {
289
293
) : Promise < Media > {
290
294
try {
291
295
const { description, title } = await this . runtime
292
- . getService ( ServiceType . IMAGE_DESCRIPTION )
293
- . getInstance < IImageDescriptionService > ( )
296
+ . getService < IImageDescriptionService > (
297
+ ServiceType . IMAGE_DESCRIPTION
298
+ )
294
299
. describeImage ( attachment . url ) ;
295
300
return {
296
301
id : attachment . id ,
@@ -322,16 +327,16 @@ export class AttachmentManager {
322
327
private async processVideoAttachment (
323
328
attachment : Attachment
324
329
) : Promise < Media > {
325
- if (
326
- this . runtime
327
- . getService ( ServiceType . VIDEO )
328
- . getInstance < IVideoService > ( )
329
- . isVideoUrl ( attachment . url )
330
- ) {
331
- const videoInfo = await this . runtime
332
- . getService ( ServiceType . VIDEO )
333
- . getInstance < IVideoService > ( )
334
- . processVideo ( attachment . url ) ;
330
+ const videoService = this . runtime . getService < IVideoService > (
331
+ ServiceType . VIDEO
332
+ ) ;
333
+
334
+ if ( ! videoService ) {
335
+ throw new Error ( "Video service not found" ) ;
336
+ }
337
+
338
+ if ( videoService . isVideoUrl ( attachment . url ) ) {
339
+ const videoInfo = await videoService . processVideo ( attachment . url ) ;
335
340
return {
336
341
id : attachment . id ,
337
342
url : attachment . url ,
0 commit comments