Skip to content

Commit

Permalink
chore: doc and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaitor committed Oct 24, 2024
1 parent 5fb99fd commit ef6c38c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/api/query-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AgentExecutionStatus, Step } from '../common/types'
import { isStepIdValid } from '../utils'
import {
BackendApiOptions,
DefaultSubscriptionOptions,
Expand Down Expand Up @@ -216,14 +217,21 @@ export class AIQueryApi extends NVMBackendApi {
* @param step - The Step object to update. @see https://docs.nevermined.io/docs/protocol/query-protocol#steps-attributes
* @returns The result of the operation
*/
async updateStep(did: string, step: Partial<Step>) {
async updateStep(did: string, step: Step) {
try {
delete (step as { did?: string }).did
} catch {
// no did attribute to delete
}

const { task_id: taskId, step_id: stepId } = step
if (!taskId || !stepId)
throw new Error('The step object must contain the task_id and step_id attributes')

const endpoint = UPDATE_STEP_ENDPOINT.replace('{did}', did)
.replace('{taskId}', taskId)
.replace('{stepId}', stepId)

return this.put(endpoint, step, { sendThroughProxy: false })
}

Expand Down Expand Up @@ -278,7 +286,10 @@ export class AIQueryApi extends NVMBackendApi {
* @returns The complete step information
*/
async getStep(stepId: string) {
if (!isStepIdValid(stepId)) throw new Error('Invalid step id')

const result = await this.searchSteps({ step_id: stepId })

if (result.status === 200 && result.data && result.data.steps && result.data.steps.length > 0) {
return result.data.steps[0]
}
Expand Down
13 changes: 9 additions & 4 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,25 @@ export interface Step extends ExecutionOptions {
*/
task_id: string

/**
* The name of the step
*/
name?: string

/**
* The status of the execution
*/
step_status: AgentExecutionStatus

/**
* Whether this is the last step in the task.
* The step preceeding the current step if any
*/
is_last?: boolean
predecessor?: string

/**
* The name of the step
* Whether this is the last step in the task.
*/
name?: string
is_last?: boolean
}

export interface ExecutionOptions extends ExecutionInput, ExecutionOutput {
Expand Down

0 comments on commit ef6c38c

Please sign in to comment.