Skip to content

Commit

Permalink
fix: add task processing endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy authored and backportbot[bot] committed Nov 22, 2024
1 parent 30a6470 commit 30c65b5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,17 @@ export const MENTION = {
GROUP: 'group',
},
}

/**
* Task statuses for OCP\TaskProcessing
*/
export const TASK_PROCESSING = {
STATUS: {
CANCELLED: 'STATUS_CANCELLED',
FAILED: 'STATUS_FAILED',
SUCCESSFUL: 'STATUS_SUCCESSFUL',
RUNNING: 'STATUS_RUNNING',
SCHEDULED: 'STATUS_SCHEDULED',
UNKNOWN: 'STATUS_UNKNOWN',
},
}
6 changes: 6 additions & 0 deletions src/services/coreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { generateOcsUrl } from '@nextcloud/router'

import { getTalkConfig, hasTalkFeature } from './CapabilitiesManager.ts'
import { SHARE } from '../constants.js'
import type { TaskProcessingResponse } from '../types/index.ts'

const canInviteToFederation = hasTalkFeature('local', 'federation-v1')
&& getTalkConfig('local', 'federation', 'enabled')
Expand Down Expand Up @@ -52,6 +53,11 @@ const autocompleteQuery = async function({ searchText, token = 'new', onlyUsers
})
}

const getTaskById = async function(id: number, options?: object): TaskProcessingResponse {
return axios.get(generateOcsUrl('taskprocessing/task/{id}', { id }), options)
}

export {
autocompleteQuery,
getTaskById,
}
30 changes: 30 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { components, operations } from './openapi/openapi-full.ts'
import { TASK_PROCESSING } from '../constants.js'

// General
type ApiResponse<T> = Promise<{ data: T }>
type ApiResponseHeaders<T extends { headers: object }> = {
[K in keyof T['headers'] as Lowercase<string & K>]: T['headers'][K];
}
type ApiResponseUnwrapped<T> = Promise<{
data: {
ocs: {
meta: components['schemas']['OCSMeta']
data: T
}
}
}>

// Capabilities
export type Capabilities = {
Expand Down Expand Up @@ -98,6 +107,7 @@ export type setReadMarkerResponse = ApiResponse<operations['chat-set-read-marker
export type markUnreadResponse = ApiResponse<operations['chat-mark-unread']['responses'][200]['content']['application/json']>
export type summarizeChatParams = operations['chat-summarize-chat']['requestBody']['content']['application/json']
export type summarizeChatResponse = ApiResponse<operations['chat-summarize-chat']['responses'][201]['content']['application/json']>
export type SummarizeChatTask = operations['chat-summarize-chat']['responses'][201]['content']['application/json']['ocs']['data']

// Avatars
export type setFileAvatarResponse = ApiResponse<operations['avatar-upload-avatar']['responses'][200]['content']['application/json']>
Expand Down Expand Up @@ -181,3 +191,23 @@ export type deletePollDraftResponse = ApiResponse<operations['poll-close-poll'][
export type ChatMention = components['schemas']['ChatMentionSuggestion']
export type getMentionsParams = operations['chat-mentions']['parameters']['query']
export type getMentionsResponse = ApiResponse<operations['chat-mentions']['responses'][200]['content']['application/json']>

// AI Summary
export type TaskProcessingResponse = ApiResponseUnwrapped<{
task: {
id: number,
lastUpdated: number,
type: string,
status: typeof TASK_PROCESSING.STATUS[keyof typeof TASK_PROCESSING.STATUS],
userId: string,
appId: string,
input: Record<string, unknown>,
output: Record<string, unknown> | null,
customId: string,
completionExpectedAt: number,
progress: number,
scheduledAt: number,
startedAt: number,
endedAt: number
}
}>

0 comments on commit 30c65b5

Please sign in to comment.