@@ -5,6 +5,8 @@ import type { ChatSurfaceIncomingMessage } from "adminforth";
55import type { PreviousUserMessage } from "./agent/languageDetect.js" ;
66import type { PluginOptions } from "./types.js" ;
77
8+ export const AGENT_SYSTEM_TURN_PROMPT = "__adminforth_system_message__" ;
9+
810export class AgentSessionStore {
911 constructor (
1012 private getAdminforth : ( ) => IAdminForth ,
@@ -23,6 +25,18 @@ export class AgentSessionStore {
2325 return newTurn . createdRecord [ this . options . turnResource . idField ] ;
2426 }
2527
28+ async createSystemTurn ( sessionId : string , systemMessage : string ) {
29+ const turnId = randomUUID ( ) ;
30+ const turnRecord = {
31+ [ this . options . turnResource . idField ] : turnId ,
32+ [ this . options . turnResource . sessionIdField ] : sessionId ,
33+ [ this . options . turnResource . promptField ] : AGENT_SYSTEM_TURN_PROMPT ,
34+ [ this . options . turnResource . responseField ] : systemMessage ,
35+ } ;
36+ const newTurn = await this . getAdminforth ( ) . resource ( this . options . turnResource . resourceId ) . create ( turnRecord ) ;
37+ return newTurn . createdRecord [ this . options . turnResource . idField ] ;
38+ }
39+
2640 async getSessionTurns ( sessionId : string ) {
2741 const turns = await this . getAdminforth ( ) . resource ( this . options . turnResource . resourceId ) . list (
2842 [ Filters . EQ ( this . options . turnResource . sessionIdField , sessionId ) ] ,
@@ -45,6 +59,7 @@ export class AgentSessionStore {
4559 ) ;
4660 return turns
4761 . reverse ( )
62+ . filter ( ( turn ) => turn [ this . options . turnResource . promptField ] !== AGENT_SYSTEM_TURN_PROMPT )
4863 . map ( ( turn ) : PreviousUserMessage => ( {
4964 text : turn [ this . options . turnResource . promptField ] ,
5065 } ) ) ;
0 commit comments