Skip to content

Kasparpeterson/auth #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/js-sdk-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
cache: npm
cache-dependency-path: package-lock.json

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-client-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'

- name: Install and configure Poetry
uses: snok/install-poetry@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-sdk-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'

- name: Install and configure Poetry
uses: snok/install-poetry@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
git commit -am "Update endpoint docs" || echo "No changes to commit"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install swagger-cli
run: |
Expand All @@ -43,7 +43,7 @@ jobs:
cd ..
npx openapi-format schemas/openapi.yml --output schemas/openapi.yml
swagger-cli bundle -r schemas/openapi.yml -o schemas/openapi.json -t json

git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add schemas/openapi.yml
Expand Down
21 changes: 10 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Contributor Covenant Code of Conduct

## Our Pledge
Expand All @@ -18,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
- The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down
4 changes: 2 additions & 2 deletions packages/client/python/agent_protocol_client/docs/AgentApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

All URIs are relative to _http://localhost_

| Method | HTTP request | Description |
| ---------------------------------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------- |
| Method | HTTP request | Description |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------- |
| [**create_agent_task**](AgentApi.md#create_agent_task) | **POST** /ap/v1/agent/tasks | Creates a task for the agent. |
| [**download_agent_task_artifact**](AgentApi.md#download_agent_task_artifact) | **GET** /ap/v1/agent/tasks/{task_id}/artifacts/{artifact_id} | Download a specified artifact. |
| [**execute_agent_task_step**](AgentApi.md#execute_agent_task_step) | **POST** /ap/v1/agent/tasks/{task_id}/steps | Execute a step in the specified agent task. |
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Agent.handleTask(taskHandler).start()
You can find more info and examples in the [docs](https://agentprotocol.ai/sdks/js).

## Contributing

```bash
git clone https://github.com/AI-Engineers-Foundation/agent-protocol
cd agent-protocol/sdk/js
Expand Down
59 changes: 32 additions & 27 deletions packages/sdk/js/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { v4 as uuid } from 'uuid'
import * as fs from 'fs'
import * as path from 'path'
Expand All @@ -21,8 +20,8 @@ import {
ApiConfig,
RouteRegisterFn,
RouteContext,
} from "./api";
import { Router } from 'express';
} from './api'
import { Router } from 'express'

/**
* A function that handles a step in a task.
Expand Down Expand Up @@ -84,7 +83,7 @@ const registerCreateAgentTask: RouteRegisterFn = (router: Router) => {
res.status(500).json({ error: err.message })
}
})()
});
})
}

/**
Expand Down Expand Up @@ -251,8 +250,8 @@ const registerGetAgentTaskStep: RouteRegisterFn = (router: Router) => {
export const getArtifacts = async (
taskId: string
): Promise<Artifact[] | undefined> => {
const task = await getAgentTask(taskId);
return task.artifacts;
const task = await getAgentTask(taskId)
return task.artifacts
}
const registerGetArtifacts: RouteRegisterFn = (router: Router) => {
router.get('/agent/tasks/:task_id/artifacts', (req, res) => {
Expand All @@ -262,7 +261,7 @@ const registerGetArtifacts: RouteRegisterFn = (router: Router) => {
const artifacts = await getArtifacts(taskId)
const current_page = Number(req.query['current_page']) || 1
const page_size = Number(req.query['page_size']) || 10

if (!artifacts) {
res.status(200).send({
artifacts: [],
Expand Down Expand Up @@ -310,9 +309,9 @@ export const getArtifactPath = (
workspace: string,
artifact: Artifact
): string => {
const rootDir = path.isAbsolute(workspace) ?
workspace :
path.join(process.cwd(), workspace);
const rootDir = path.isAbsolute(workspace)
? workspace
: path.join(process.cwd(), workspace)

return path.join(
rootDir,
Expand Down Expand Up @@ -345,18 +344,17 @@ export const createArtifact = async (
task.artifacts = task.artifacts || []
task.artifacts.push(artifact)

const artifactFolderPath = getArtifactPath(
task.task_id,
workspace,
artifact
)
const artifactFolderPath = getArtifactPath(task.task_id, workspace, artifact)

// Save file to server's file system
fs.mkdirSync(path.join(artifactFolderPath, '..'), { recursive: true })
fs.writeFileSync(artifactFolderPath, file.buffer)
return artifact
}
const registerCreateArtifact: RouteRegisterFn = (router: Router, context: RouteContext) => {
const registerCreateArtifact: RouteRegisterFn = (
router: Router,
context: RouteContext
) => {
router.post('/agent/tasks/:task_id/artifacts', (req, res) => {
void (async () => {
try {
Expand Down Expand Up @@ -406,14 +404,21 @@ export const getTaskArtifact = async (
}
return artifact
}
const registerGetTaskArtifact: RouteRegisterFn = (router: Router, context: RouteContext) => {
const registerGetTaskArtifact: RouteRegisterFn = (
router: Router,
context: RouteContext
) => {
router.get('/agent/tasks/:task_id/artifacts/:artifact_id', (req, res) => {
void (async () => {
const taskId = req.params.task_id
const artifactId = req.params.artifact_id
try {
const artifact = await getTaskArtifact(taskId, artifactId)
const artifactPath = getArtifactPath(taskId, context.workspace, artifact)
const artifactPath = getArtifactPath(
taskId,
context.workspace,
artifact
)
res.status(200).sendFile(artifactPath)
} catch (err: Error | any) {
console.error(err)
Expand All @@ -424,20 +429,20 @@ const registerGetTaskArtifact: RouteRegisterFn = (router: Router, context: Route
}

export interface AgentConfig {
port: number;
workspace: string;
port: number
workspace: string
}

export const defaultAgentConfig: AgentConfig = {
port: 8000,
workspace: "./workspace"
};
workspace: './workspace',
}

export class Agent {
constructor(
public taskHandler: TaskHandler,
public config: AgentConfig
) { }
) {}

static handleTask(
_taskHandler: TaskHandler,
Expand All @@ -446,8 +451,8 @@ export class Agent {
taskHandler = _taskHandler
return new Agent(_taskHandler, {
workspace: config.workspace || defaultAgentConfig.workspace,
port: config.port || defaultAgentConfig.port
});
port: config.port || defaultAgentConfig.port,
})
}

start(port?: number): void {
Expand All @@ -462,13 +467,13 @@ export class Agent {
registerGetAgentTaskStep,
registerGetArtifacts,
registerCreateArtifact,
registerGetTaskArtifact
registerGetTaskArtifact,
],
callback: () => {
console.log(`Agent listening at http://localhost:${this.config.port}`)
},
context: {
workspace: this.config.workspace
workspace: this.config.workspace,
},
}

Expand Down
57 changes: 27 additions & 30 deletions packages/sdk/js/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
import * as OpenApiValidator from "express-openapi-validator";
import yaml from "js-yaml";
import express, { Router } from "express"; // <-- Import Router
import * as core from "express-serve-static-core";
import * as OpenApiValidator from 'express-openapi-validator'
import yaml from 'js-yaml'
import express, { Router } from 'express' // <-- Import Router
import * as core from 'express-serve-static-core'

import spec from "../agent-protocol/schemas/openapi.yml";
import spec from '../agent-protocol/schemas/openapi.yml'

export type ApiApp = core.Express;
export type ApiApp = core.Express

export interface RouteContext {
workspace: string;
workspace: string
}

export type RouteRegisterFn = (
app: Router,
context: RouteContext
) => void;
export type RouteRegisterFn = (app: Router, context: RouteContext) => void

export interface ApiConfig {
context: RouteContext;
port: number;
callback?: () => void;
routes: RouteRegisterFn[];
context: RouteContext
port: number
callback?: () => void
routes: RouteRegisterFn[]
}

export const createApi = (config: ApiConfig) => {
const app = express();
const app = express()

app.use(express.json());
app.use(express.text());
app.use(express.urlencoded({ extended: false }));
app.use(express.json())
app.use(express.text())
app.use(express.urlencoded({ extended: false }))

const parsedSpec = yaml.load(spec);
const parsedSpec = yaml.load(spec)

app.use(
OpenApiValidator.middleware({
apiSpec: parsedSpec as any,
validateRequests: true, // (default)
validateResponses: true, // false by default
})
);
)

app.get("/openapi.yaml", (_, res) => {
res.setHeader("Content-Type", "text/yaml").status(200).send(spec);
});
app.get('/openapi.yaml', (_, res) => {
res.setHeader('Content-Type', 'text/yaml').status(200).send(spec)
})

const router = Router();
const router = Router()

config.routes.map((route) => {
route(router, config.context);
});
route(router, config.context)
})

app.use("/ap/v1", router);
app.listen(config.port, config.callback);
};
app.use('/ap/v1', router)
app.listen(config.port, config.callback)
}
2 changes: 1 addition & 1 deletion packages/sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export {
getAgentTaskStep,
}

export { v4 } from "uuid"
export { v4 } from 'uuid'

export default Agent
14 changes: 7 additions & 7 deletions packages/sdk/js/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export type TaskInput = any
* Artifact that the task has produced. Any value is allowed.
*/
export type Artifact = {
artifact_id: string,
agent_created: boolean,
file_name: string,
relative_path: string | null,
artifact_id: string
agent_created: boolean
file_name: string
relative_path: string | null
created_at: string
}

Expand All @@ -25,9 +25,9 @@ export type StepInput = any
export type StepOutput = any

export enum StepStatus {
CREATED = "created",
RUNNING = "running",
COMPLETED = "completed"
CREATED = 'created',
RUNNING = 'running',
COMPLETED = 'completed',
}

export interface Step {
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Agent.setup_agent(task_handler, step_handler).start(router=my_router)
### Testing

You can test the compliance of your agent using the following script:

```bash
URL=http://127.0.0.1:8000 bash -c "$(curl -fsSL https://agentprotocol.ai/test.sh)"
```
Expand All @@ -92,4 +93,4 @@ poetry install
poetry run python examples/minimal.py
```

Feel free to open [an issue](https://github.com/AI-Engineers-Foundation/agent-protocol/issues) if you run into any problems!
Feel free to open [an issue](https://github.com/AI-Engineers-Foundation/agent-protocol/issues) if you run into any problems!
Loading