diff --git a/src/api/query-api.ts b/src/api/query-api.ts index 7035e67..4f78fa7 100644 --- a/src/api/query-api.ts +++ b/src/api/query-api.ts @@ -1,4 +1,5 @@ import { AgentExecutionStatus, Step } from '../common/types' +import { isStepIdValid } from '../utils' import { BackendApiOptions, DefaultSubscriptionOptions, @@ -216,7 +217,13 @@ 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) { + 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') @@ -224,6 +231,7 @@ export class AIQueryApi extends NVMBackendApi { const endpoint = UPDATE_STEP_ENDPOINT.replace('{did}', did) .replace('{taskId}', taskId) .replace('{stepId}', stepId) + return this.put(endpoint, step, { sendThroughProxy: false }) } @@ -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] } diff --git a/src/common/types.ts b/src/common/types.ts index 542f9e8..4e42587 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -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 {