mirror of
https://github.com/kennethnym/freya
synced 2026-07-04 15:11:15 +01:00
feat: make agent event include conversation entry
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { ConversationEntryKind, ConversationEntryVisibility } from "@freya/core"
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
||||
import { ConversationEntryKind, ConversationEntryVisibility } from "@freya/core"
|
||||
|
||||
import type { AgentEvent, AgentServerApi } from "./index"
|
||||
import { AgentEventKind, type AgentEvent, type AgentServerApi } from "./index"
|
||||
|
||||
describe("agent protocol", () => {
|
||||
test("defines server methods and agent events", () => {
|
||||
@@ -30,9 +29,12 @@ describe("agent protocol", () => {
|
||||
return "pong"
|
||||
},
|
||||
}
|
||||
const event: AgentEvent = { type: "message_finished" }
|
||||
const event: AgentEvent = {
|
||||
kind: AgentEventKind.ResponseFinished,
|
||||
conversationId: "conversation-1",
|
||||
}
|
||||
|
||||
expect(server.ping()).toBe("pong")
|
||||
expect(event.type).toBe("message_finished")
|
||||
expect(event.kind).toBe(AgentEventKind.ResponseFinished)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,12 +1,40 @@
|
||||
import type { ConversationEntry } from "@freya/core"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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 =
|
||||
| { 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 }
|
||||
| AgentConversationStartedEvent
|
||||
| AgentConversationEntryCreatedEvent
|
||||
| AgentResponseFinishedEvent
|
||||
| AgentResponseFailedEvent
|
||||
|
||||
export type UserEvent = { type: "typing" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user