From efaddfad25044bf70de5612f8acd20c8350c7a0f Mon Sep 17 00:00:00 2001
From: nalbion <nalbion@yahoo.com>
Date: Sun, 11 Feb 2024 00:30:25 +1100
Subject: [PATCH] task/step input were being confused with additional_input

---
 packages/sdk/js/README.md           |  7 ++--
 packages/sdk/js/examples/minimal.ts |  7 ++--
 packages/sdk/js/src/agent.ts        | 20 +++++++++---
 packages/sdk/js/src/models.ts       | 50 ++++++++++++++++++-----------
 schemas/openapi.yml                 | 31 +++++++-----------
 5 files changed, 69 insertions(+), 46 deletions(-)

diff --git a/packages/sdk/js/README.md b/packages/sdk/js/README.md
index fec5d93c..5ae77403 100644
--- a/packages/sdk/js/README.md
+++ b/packages/sdk/js/README.md
@@ -22,8 +22,11 @@ import Agent, {
   type TaskInput,
 } from 'agent-protocol'
 
-async function taskHandler(taskInput: TaskInput | null): Promise<StepHandler> {
-  console.log(`task: ${taskInput}`)
+async function taskHandler(
+  taskId: string,
+  taskInput: TaskInput | null
+): Promise<StepHandler> {
+  console.log(`task ${taskId}: ${taskInput}`)
 
   async function stepHandler(stepInput: StepInput | null): Promise<StepResult> {
     console.log(`step: ${stepInput}`)
diff --git a/packages/sdk/js/examples/minimal.ts b/packages/sdk/js/examples/minimal.ts
index d3a7f7f2..b4392aac 100644
--- a/packages/sdk/js/examples/minimal.ts
+++ b/packages/sdk/js/examples/minimal.ts
@@ -5,8 +5,11 @@ import Agent, {
   type StepInput,
 } from 'agent-protocol'
 
-async function taskHandler(taskInput: TaskInput | null): Promise<StepHandler> {
-  console.log(`task: ${taskInput}`)
+async function taskHandler(
+  taskId: string,
+  taskInput: TaskInput | null
+): Promise<StepHandler> {
+  console.log(`task ${taskId}: ${taskInput}`)
 
   async function stepHandler(stepInput: StepInput | null): Promise<StepResult> {
     console.log(`step: ${stepInput}`)
diff --git a/packages/sdk/js/src/agent.ts b/packages/sdk/js/src/agent.ts
index b575a344..411346d1 100644
--- a/packages/sdk/js/src/agent.ts
+++ b/packages/sdk/js/src/agent.ts
@@ -13,6 +13,7 @@ import {
   type Task,
   type TaskRequestBody,
   StepStatus,
+  type AdditionalInput,
 } from './models'
 import {
   createApi,
@@ -26,14 +27,18 @@ import { type Router } from 'express'
  * A function that handles a step in a task.
  * Returns a step result.
  */
-export type StepHandler = (input: StepInput | null) => Promise<StepResult>
+export type StepHandler = (
+  input: StepInput | null,
+  additionalInput: AdditionalInput | null
+) => Promise<StepResult>
 /**
  * A function that handles a task.
  * Returns a step handler.
  */
 export type TaskHandler = (
   taskId: string,
-  input: TaskInput | null
+  input: TaskInput | null,
+  additionalInput: AdditionalInput | null
 ) => Promise<StepHandler>
 
 const tasks: Array<[Task, StepHandler]> = []
@@ -67,7 +72,11 @@ export const createAgentTask = async (
     input: body?.input ?? null,
     artifacts: [],
   }
-  const stepHandler = await taskHandler(task.task_id, body?.input ?? null)
+  const stepHandler = await taskHandler(
+    task.task_id,
+    body?.input ?? null,
+    body?.additional_input ?? null
+  )
   tasks.push([task, stepHandler])
   return task
 }
@@ -175,7 +184,10 @@ export const executeAgentTaskStep = async (
     throw new Error(`Task with id ${taskId} not found`)
   }
   const handler = task[1]
-  const stepResult = await handler(body?.input ?? null)
+  const stepResult = await handler(
+    body?.input ?? null,
+    body?.additional_input ?? null
+  )
   const step: Step = {
     task_id: taskId,
     step_id: uuid(),
diff --git a/packages/sdk/js/src/models.ts b/packages/sdk/js/src/models.ts
index 740f06b7..988a2b7f 100644
--- a/packages/sdk/js/src/models.ts
+++ b/packages/sdk/js/src/models.ts
@@ -1,7 +1,7 @@
 /**
- * Input parameters for the task. Any value is allowed.
+ * Input prompt for the task.
  */
-export type TaskInput = any
+export type TaskInput = string | null | undefined
 
 /**
  * Artifact that the task has produced. Any value is allowed.
@@ -10,19 +10,21 @@ export interface Artifact {
   artifact_id: string
   agent_created: boolean
   file_name: string
-  relative_path: string | null
-  created_at: string
+  relative_path?: string | null
+  created_at?: string
 }
 
 /**
  * Input parameters for the task step. Any value is allowed.
  */
-export type StepInput = any
+export type StepInput = string | null | undefined
 
 /**
  * Output that the task step has produced. Any value is allowed.
  */
-export type StepOutput = any
+export type StepOutput = string | null | undefined
+
+export type AdditionalOutput = any
 
 export enum StepStatus {
   CREATED = 'created',
@@ -31,6 +33,22 @@ export enum StepStatus {
 }
 
 export interface Step {
+  input?: StepInput
+  additional_input?: AdditionalInput
+
+  /**
+   * The ID of the task this step belongs to.
+   */
+  task_id: string
+  /**
+   * The ID of the task step.
+   */
+  step_id: string
+  /**
+   * Current status of step
+   */
+  status: StepStatus
+
   /**
    * The name of the task step
    */
@@ -39,31 +57,22 @@ export interface Step {
    * Output of the task step
    */
   output?: StepOutput
+  additional_output?: AdditionalOutput
+
   /**
    * A list of artifacts that the step has produced.
    */
   artifacts?: Artifact[]
   /**
    * Whether this is the last step in the task.
+   * @default false
    */
   is_last?: boolean
-  input?: StepInput
-  /**
-   * The ID of the task this step belongs to.
-   */
-  task_id: string
-  /**
-   * The ID of the task step.
-   */
-  step_id: string
-  /**
-   * Current status of step
-   */
-  status: StepStatus
 }
 
 export interface StepRequestBody {
   input?: StepInput
+  additional_input?: AdditionalInput
 }
 
 export interface StepResult {
@@ -99,4 +108,7 @@ export interface Task {
 
 export interface TaskRequestBody {
   input?: TaskInput
+  additional_input?: AdditionalInput
 }
+
+export type AdditionalInput = any
diff --git a/schemas/openapi.yml b/schemas/openapi.yml
index 0eadce73..1815552c 100644
--- a/schemas/openapi.yml
+++ b/schemas/openapi.yml
@@ -400,8 +400,8 @@ components:
       required:
         - artifacts
         - pagination
-    TaskInput:
-      description: Input parameters for the task. Any value is allowed.
+    AdditionalInput:
+      description: Additional input parameters for the task. Any value is allowed.
       type: object
       example: |-
         {
@@ -448,14 +448,7 @@ components:
           example: python/code
       required:
         - file
-    StepInput:
-      description: Input parameters for the task step. Any value is allowed.
-      type: object
-      example: |-
-        {
-        "file_to_refactor": "models.py"
-        }
-    StepOutput:
+    AdditionalOutput:
       description: Output that the task step has produced. Any value is allowed.
       type: object
       example: |-
@@ -474,7 +467,7 @@ components:
           example: Write 'Washington' to the file 'output.txt'.
           nullable: true
         additional_input:
-          $ref: '#/components/schemas/TaskInput'
+          $ref: '#/components/schemas/AdditionalInput'
     Task:
       allOf:
         - $ref: '#/components/schemas/TaskRequestBody'
@@ -507,14 +500,14 @@ components:
           example: Write the words you receive to the file 'output.txt'.
           nullable: true
         additional_input:
-          $ref: '#/components/schemas/StepInput'
+          $ref: '#/components/schemas/AdditionalInput'
     Step:
       allOf:
         - $ref: '#/components/schemas/StepRequestBody'
         - type: object
           required:
-            - step_id
             - task_id
+            - step_id
             - status
             - is_last
             - artifacts
@@ -527,11 +520,6 @@ components:
               description: The ID of the task step.
               type: string
               example: 6bb1801a-fd80-45e8-899a-4dd723cc602e
-            name:
-              description: The name of the task step.
-              type: string
-              example: Write to file
-              nullable: true
             status:
               description: The status of the task step.
               type: string
@@ -540,13 +528,18 @@ components:
                 - created
                 - running
                 - completed
+            name:
+              description: The name of the task step.
+              type: string
+              example: Write to file
+              nullable: true
             output:
               description: Output of the task step.
               type: string
               example: "I am going to use the write_to_file command and write Washington to a file called output.txt <write_to_file('output.txt', 'Washington')"
               nullable: true
             additional_output:
-              $ref: '#/components/schemas/StepOutput'
+              $ref: '#/components/schemas/AdditionalOutput'
             artifacts:
               description: A list of artifacts that the step has produced.
               type: array