platform/plugins/ai-bot-resources/src/requests.ts
Victor Ilyushchenko 9d6048f06f
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions
Added summarization action for meeting minutes (#8143)
* Added summarization action for meeting minutes

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

* tweaks

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

* fmt

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

* ff

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

---------

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
2025-03-06 17:50:14 +03:00

147 lines
4.0 KiB
TypeScript

//
// Copyright © 2024 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import {
type ConnectMeetingRequest,
type DisconnectMeetingRequest,
type SummarizeMessagesRequest,
type SummarizeMessagesResponse,
type TranslateRequest,
type TranslateResponse
} from '@hcengineering/ai-bot'
import { type Class, concatLink, type Doc, type Markup, type Ref } from '@hcengineering/core'
import { type Room, type RoomLanguage } from '@hcengineering/love'
import { getMetadata } from '@hcengineering/platform'
import presentation from '@hcengineering/presentation'
import aiBot from './plugin'
export async function translate (text: Markup, lang: string): Promise<TranslateResponse | undefined> {
const url = getMetadata(aiBot.metadata.EndpointURL) ?? ''
const token = getMetadata(presentation.metadata.Token) ?? ''
if (url === '' || token === '') {
return undefined
}
try {
const req: TranslateRequest = { text, lang }
const resp = await fetch(concatLink(url, '/translate'), {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
})
if (!resp.ok) {
return undefined
}
return (await resp.json()) as TranslateResponse
} catch (error) {
console.error(error)
return undefined
}
}
export async function summarizeMessages (
lang: string,
target: Ref<Doc>,
targetClass: Ref<Class<Doc>>
): Promise<SummarizeMessagesResponse | undefined> {
const url = getMetadata(aiBot.metadata.EndpointURL) ?? ''
const token = getMetadata(presentation.metadata.Token) ?? ''
if (url === '' || token === '') {
return undefined
}
try {
const req: SummarizeMessagesRequest = {
target,
targetClass,
lang
}
const resp = await fetch(concatLink(url, '/summarize'), {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
})
if (!resp.ok) {
return undefined
}
return (await resp.json()) as SummarizeMessagesResponse
} catch (error) {
console.error(error)
return undefined
}
}
export async function connectMeeting (
roomId: Ref<Room>,
language: RoomLanguage,
options: Partial<ConnectMeetingRequest>
): Promise<void> {
const url = getMetadata(aiBot.metadata.EndpointURL) ?? ''
const token = getMetadata(presentation.metadata.Token) ?? ''
if (url === '' || token === '') {
return undefined
}
try {
const req: ConnectMeetingRequest = { roomId, transcription: options.transcription ?? false, language }
await fetch(concatLink(url, 'love/connect'), {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
})
} catch (error) {
console.error(error)
return undefined
}
}
export async function disconnectMeeting (roomId: Ref<Room>): Promise<void> {
const url = getMetadata(aiBot.metadata.EndpointURL) ?? ''
const token = getMetadata(presentation.metadata.Token) ?? ''
if (url === '' || token === '') {
return undefined
}
try {
const req: DisconnectMeetingRequest = { roomId }
await fetch(concatLink(url, 'love/disconnect'), {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(req)
})
} catch (error) {
console.error(error)
return undefined
}
}