mirror of
https://github.com/kennethnym/freya
synced 2026-06-20 08:31:17 +01:00
feat: add agent websocket endpoint (#142)
This commit is contained in:
10
packages/freya-agent-protocol/package.json
Normal file
10
packages/freya-agent-protocol/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@freya/agent-protocol",
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "bun test ./src"
|
||||
}
|
||||
}
|
||||
20
packages/freya-agent-protocol/src/index.test.ts
Normal file
20
packages/freya-agent-protocol/src/index.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
||||
import type { AgentEvent, AgentServerApi } from "./index"
|
||||
|
||||
describe("agent protocol", () => {
|
||||
test("defines server methods and agent events", () => {
|
||||
const server: AgentServerApi = {
|
||||
async sendMessage(message) {
|
||||
return { message, conversationId: "conversation-1" }
|
||||
},
|
||||
ping() {
|
||||
return "pong"
|
||||
},
|
||||
}
|
||||
const event: AgentEvent = { type: "message_finished" }
|
||||
|
||||
expect(server.ping()).toBe("pong")
|
||||
expect(event.type).toBe("message_finished")
|
||||
})
|
||||
})
|
||||
21
packages/freya-agent-protocol/src/index.ts
Normal file
21
packages/freya-agent-protocol/src/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export interface SendMessageResult {
|
||||
message: string
|
||||
conversationId: string
|
||||
}
|
||||
|
||||
export type AgentEvent =
|
||||
| { type: "conversation_started"; conversationId: string }
|
||||
| { type: "message_created"; text: string }
|
||||
| { type: "tool_started"; toolName: string }
|
||||
| { type: "tool_finished"; toolName: string; ok: boolean }
|
||||
| { type: "message_finished" }
|
||||
| { type: "message_failed"; error: string }
|
||||
|
||||
export interface AgentServerApi {
|
||||
sendMessage(message: string): Promise<SendMessageResult>
|
||||
ping(): "pong"
|
||||
}
|
||||
|
||||
export interface AgentClientApi {
|
||||
notify(event: AgentEvent): void
|
||||
}
|
||||
4
packages/freya-agent-protocol/tsconfig.json
Normal file
4
packages/freya-agent-protocol/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user