diff --git a/.github/workflows/js-sdk-build.yaml b/.github/workflows/js-sdk-build.yaml new file mode 100644 index 0000000..9864cd2 --- /dev/null +++ b/.github/workflows/js-sdk-build.yaml @@ -0,0 +1,16 @@ +name: Build JS SDK + +on: + pull_request: + types: + - opened + - synchronize + - reopened + paths: + - 'packages/sdk/js/**' + +jobs: + build: + uses: ./.github/workflows/js-sdk-shared.yaml + with: + should-publish: false diff --git a/.github/workflows/js-sdk-publish.yaml b/.github/workflows/js-sdk-publish.yaml index 2a2c4ef..d262001 100644 --- a/.github/workflows/js-sdk-publish.yaml +++ b/.github/workflows/js-sdk-publish.yaml @@ -9,33 +9,6 @@ permissions: jobs: publish: - name: Build and publish SDK to NPM - runs-on: ubuntu-20.04 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - submodules: true - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: '16.x' - registry-url: 'https://registry.npmjs.org' - cache: npm - cache-dependency-path: package-lock.json - - - name: Install dependencies - working-directory: ./packages/sdk/js/ - run: npm ci - - - name: Publish package - run: npm publish --access=public - working-directory: ./packages/sdk/js/ - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Release - uses: softprops/action-gh-release@v1 - with: - generate_release_notes: true + uses: ./.github/workflows/js-sdk-shared.yaml + with: + should-publish: true diff --git a/.github/workflows/js-sdk-shared.yaml b/.github/workflows/js-sdk-shared.yaml new file mode 100644 index 0000000..a35cb2f --- /dev/null +++ b/.github/workflows/js-sdk-shared.yaml @@ -0,0 +1,46 @@ +name: Build and Publish JS SDK Package + +on: + workflow_call: + inputs: + should-publish: + required: false + type: boolean + default: false + +jobs: + build: + name: Build and optionally publish SDK to NPM + runs-on: ubuntu-20.04 + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + cache: npm + cache-dependency-path: package-lock.json + + - name: Install dependencies + working-directory: ./packages/sdk/js/ + run: npm ci + + - name: Build package + working-directory: ./packages/sdk/js/ + run: npm run build + + - name: Publish package + if: ${{ inputs.should-publish }} + run: npm publish --access=public + working-directory: ./packages/sdk/js/ + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Release + if: ${{ inputs.should-publish }} + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true diff --git a/packages/sdk/js/README.md b/packages/sdk/js/README.md index b5368fb..fec5d93 100644 --- a/packages/sdk/js/README.md +++ b/packages/sdk/js/README.md @@ -46,7 +46,7 @@ You can find more info and examples in the [docs](https://agentprotocol.ai/sdks/ ```bash git clone https://github.com/AI-Engineers-Foundation/agent-protocol -cd agent-protocol/sdk/js +cd agent-protocol/packages/sdk/js npm install npm run build ``` diff --git a/packages/sdk/js/src/agent.ts b/packages/sdk/js/src/agent.ts index a8f84f0..b575a34 100644 --- a/packages/sdk/js/src/agent.ts +++ b/packages/sdk/js/src/agent.ts @@ -347,7 +347,10 @@ export const createArtifact = async ( relative_path: relativePath ?? null, created_at: Date.now().toString(), } - task.artifacts = task.artifacts != null ?? [] + task.artifacts = + task.artifacts !== null && task.artifacts !== undefined + ? task.artifacts + : [] task.artifacts.push(artifact) const artifactFolderPath = getArtifactPath(task.task_id, workspace, artifact)