feat: sendMessage rpc returns created entry

This commit is contained in:
2026-07-03 01:02:03 +01:00
parent e3a00fe632
commit 430a095f2a
13 changed files with 196 additions and 159 deletions

View File

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

View File

@@ -1,12 +1,30 @@
import { describe, expect, test } from "bun:test"
import { ConversationEntryKind, ConversationEntryVisibility } from "@freya/core"
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" }
return {
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() {
return "pong"

View File

@@ -1,3 +1,5 @@
import type { ConversationEntry } from "@freya/core"
export type AgentEvent =
| { type: "conversation_started"; conversationId: string }
| { type: "message_created"; text: string }
@@ -9,7 +11,7 @@ export type AgentEvent =
export type UserEvent = { type: "typing" }
export interface AgentServerApi {
sendMessage(message: string): Promise<boolean>
sendMessage(message: string): Promise<ConversationEntry>
notify(event: UserEvent): void
ping(): "pong"
}