Compare commits

..

1 Commits

Author SHA1 Message Date
72b27cfd09 feat: add tool payload schemas 2026-07-04 14:32:12 +01:00
4 changed files with 13 additions and 67 deletions

View File

@@ -158,9 +158,6 @@
"packages/freya-agent-protocol": { "packages/freya-agent-protocol": {
"name": "@freya/agent-protocol", "name": "@freya/agent-protocol",
"version": "0.0.0", "version": "0.0.0",
"dependencies": {
"@freya/core": "workspace:*",
},
}, },
"packages/freya-components": { "packages/freya-components": {
"name": "@freya/components", "name": "@freya/components",

View File

@@ -6,8 +6,5 @@
"types": "src/index.ts", "types": "src/index.ts",
"scripts": { "scripts": {
"test": "bun test ./src" "test": "bun test ./src"
},
"dependencies": {
"@freya/core": "workspace:*"
} }
} }

View File

@@ -1,40 +1,20 @@
import { ConversationEntryKind, ConversationEntryVisibility } from "@freya/core"
import { describe, expect, test } from "bun:test" import { describe, expect, test } from "bun:test"
import { AgentEventKind, type AgentEvent, type AgentServerApi } from "./index" import type { AgentEvent, AgentServerApi } from "./index"
describe("agent protocol", () => { describe("agent protocol", () => {
test("defines server methods and agent events", () => { test("defines server methods and agent events", () => {
const server: AgentServerApi = { const server: AgentServerApi = {
async sendMessage(message) { async sendMessage(message) {
return { return { message, conversationId: "conversation-1" }
id: "entry-1",
conversationId: "conversation-1",
sequence: 1,
kind: ConversationEntryKind.UserMessage,
visibility: ConversationEntryVisibility.UserVisible,
fileId: null,
payload: {
role: "user",
parts: [{ type: "text", text: message }],
},
metadata: {},
createdAt: "2026-07-03T00:00:00.000Z",
}
},
notify() {
// no-op for protocol shape test
}, },
ping() { ping() {
return "pong" return "pong"
}, },
} }
const event: AgentEvent = { const event: AgentEvent = { type: "message_finished" }
kind: AgentEventKind.ResponseFinished,
conversationId: "conversation-1",
}
expect(server.ping()).toBe("pong") expect(server.ping()).toBe("pong")
expect(event.kind).toBe(AgentEventKind.ResponseFinished) expect(event.type).toBe("message_finished")
}) })
}) })

View File

@@ -1,46 +1,18 @@
import type { ConversationEntry } from "@freya/core" export interface SendMessageResult {
message: string
export const AgentEventKind = {
ConversationStarted: "conversation_started",
ConversationEntryCreated: "conversation_entry_created",
ResponseFinished: "response_finished",
ResponseFailed: "response_failed",
} as const
export type AgentEventKind = (typeof AgentEventKind)[keyof typeof AgentEventKind]
export interface AgentConversationStartedEvent {
kind: typeof AgentEventKind.ConversationStarted
conversationId: string conversationId: string
} }
export interface AgentConversationEntryCreatedEvent {
kind: typeof AgentEventKind.ConversationEntryCreated
entry: ConversationEntry
}
export interface AgentResponseFinishedEvent {
kind: typeof AgentEventKind.ResponseFinished
conversationId: string
}
export interface AgentResponseFailedEvent {
kind: typeof AgentEventKind.ResponseFailed
conversationId: string
error: string
}
export type AgentEvent = export type AgentEvent =
| AgentConversationStartedEvent | { type: "conversation_started"; conversationId: string }
| AgentConversationEntryCreatedEvent | { type: "message_created"; text: string }
| AgentResponseFinishedEvent | { type: "tool_started"; toolName: string }
| AgentResponseFailedEvent | { type: "tool_finished"; toolName: string; ok: boolean }
| { type: "message_finished" }
export type UserEvent = { type: "typing" } | { type: "message_failed"; error: string }
export interface AgentServerApi { export interface AgentServerApi {
sendMessage(message: string): Promise<ConversationEntry> sendMessage(message: string): Promise<SendMessageResult>
notify(event: UserEvent): void
ping(): "pong" ping(): "pong"
} }