From 1ba73f85243f6396692c48ba5a9dc55fc24bec53 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Tue, 26 Nov 2024 17:49:11 -0800 Subject: [PATCH 01/11] Add endpoints and adjust LettaRequest --- letta/client/client.py | 7 +- letta/schemas/letta_request.py | 30 +++----- letta/schemas/message.py | 6 +- letta/server/rest_api/interface.py | 25 +++---- letta/server/rest_api/routers/v1/agents.py | 70 ++++++++++++++----- letta/server/server.py | 12 ++-- .../static_files/assets/index-9fa459a2.js | 2 +- locust_test.py | 2 +- 8 files changed, 83 insertions(+), 71 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index 9a52291d05..ce28faee12 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -964,12 +964,7 @@ def send_message( # TODO: figure out how to handle stream_steps and stream_tokens # When streaming steps is True, stream_tokens must be False - request = LettaRequest( - messages=messages, - stream_steps=stream_steps, - stream_tokens=stream_tokens, - return_message_object=include_full_message, - ) + request = LettaRequest(messages=messages) if stream_tokens or stream_steps: from letta.client.streaming import _sse_post diff --git a/letta/schemas/letta_request.py b/letta/schemas/letta_request.py index 3c0a3ef95b..c4a66fbb59 100644 --- a/letta/schemas/letta_request.py +++ b/letta/schemas/letta_request.py @@ -8,33 +8,21 @@ class LettaRequest(BaseModel): messages: Union[List[MessageCreate], List[Message]] = Field(..., description="The messages to be sent to the agent.") - run_async: bool = Field(default=False, description="Whether to asynchronously send the messages to the agent.") # TODO: implement - - stream_steps: bool = Field( - default=False, description="Flag to determine if the response should be streamed. Set to True for streaming agent steps." - ) - stream_tokens: bool = Field( - default=False, - description="Flag to determine if individual tokens should be streamed. Set to True for token streaming (requires stream_steps = True).", - ) - - return_message_object: bool = Field( - default=False, - description="Set True to return the raw Message object. Set False to return the Message in the format of the Letta API.", - ) # Flags to support the use of AssistantMessage message types - use_assistant_message: bool = Field( - default=False, - description="[Only applicable if return_message_object is False] If true, returns AssistantMessage objects when the agent calls a designated message tool. If false, return FunctionCallMessage objects for all tool calls.", - ) - - assistant_message_function_name: str = Field( + assistant_message_tool_name: str = Field( default=DEFAULT_MESSAGE_TOOL, description="[Only applicable if use_assistant_message is True] The name of the designated message tool.", ) - assistant_message_function_kwarg: str = Field( + assistant_message_tool_kwarg: str = Field( default=DEFAULT_MESSAGE_TOOL_KWARG, description="[Only applicable if use_assistant_message is True] The name of the message argument in the designated message tool.", ) + + +class LettaStreamingRequest(LettaRequest): + stream_tokens: bool = Field( + default=False, + description="Flag to determine if individual tokens should be streamed. Set to True for token streaming (requires stream_steps = True).", + ) diff --git a/letta/schemas/message.py b/letta/schemas/message.py index 4ddcc0c86d..e4c668c1ec 100644 --- a/letta/schemas/message.py +++ b/letta/schemas/message.py @@ -134,8 +134,8 @@ def to_json(self): def to_letta_message( self, assistant_message: bool = False, - assistant_message_function_name: str = DEFAULT_MESSAGE_TOOL, - assistant_message_function_kwarg: str = DEFAULT_MESSAGE_TOOL_KWARG, + assistant_message_tool_name: str = DEFAULT_MESSAGE_TOOL, + assistant_message_tool_kwarg: str = DEFAULT_MESSAGE_TOOL_KWARG, ) -> List[LettaMessage]: """Convert message object (in DB format) to the style used by the original Letta API""" @@ -156,7 +156,7 @@ def to_letta_message( for tool_call in self.tool_calls: # If we're supporting using assistant message, # then we want to treat certain function calls as a special case - if assistant_message and tool_call.function.name == assistant_message_function_name: + if assistant_message and tool_call.function.name == assistant_message_tool_name: # We need to unpack the actual message contents from the function call try: func_args = json.loads(tool_call.function.arguments) diff --git a/letta/server/rest_api/interface.py b/letta/server/rest_api/interface.py index cb5ef669f2..21b4650c6b 100644 --- a/letta/server/rest_api/interface.py +++ b/letta/server/rest_api/interface.py @@ -272,8 +272,8 @@ def __init__( multi_step=True, # Related to if we want to try and pass back the AssistantMessage as a special case function use_assistant_message=False, - assistant_message_function_name=DEFAULT_MESSAGE_TOOL, - assistant_message_function_kwarg=DEFAULT_MESSAGE_TOOL_KWARG, + assistant_message_tool_name=DEFAULT_MESSAGE_TOOL, + assistant_message_tool_kwarg=DEFAULT_MESSAGE_TOOL_KWARG, # Related to if we expect inner_thoughts to be in the kwargs inner_thoughts_in_kwargs=True, inner_thoughts_kwarg=INNER_THOUGHTS_KWARG, @@ -287,7 +287,7 @@ def __init__( self.streaming_chat_completion_mode_function_name = None # NOTE: sadly need to track state during stream # If chat completion mode, we need a special stream reader to # turn function argument to send_message into a normal text stream - self.streaming_chat_completion_json_reader = FunctionArgumentsStreamHandler(json_key=assistant_message_function_kwarg) + self.streaming_chat_completion_json_reader = FunctionArgumentsStreamHandler(json_key=assistant_message_tool_kwarg) self._chunks = deque() self._event = asyncio.Event() # Use an event to notify when chunks are available @@ -301,8 +301,8 @@ def __init__( # Support for AssistantMessage self.use_assistant_message = use_assistant_message - self.assistant_message_function_name = assistant_message_function_name - self.assistant_message_function_kwarg = assistant_message_function_kwarg + self.assistant_message_tool_name = assistant_message_tool_name + self.assistant_message_tool_kwarg = assistant_message_tool_kwarg # Support for inner_thoughts_in_kwargs self.inner_thoughts_in_kwargs = inner_thoughts_in_kwargs @@ -455,17 +455,14 @@ def _process_chunk_to_letta_style( # If we get a "hit" on the special keyword we're looking for, we want to skip to the next chunk # TODO I don't think this handles the function name in multi-pieces problem. Instead, we should probably reset the streaming_chat_completion_mode_function_name when we make this hit? - # if self.streaming_chat_completion_mode_function_name == self.assistant_message_function_name: - if tool_call.function.name == self.assistant_message_function_name: + # if self.streaming_chat_completion_mode_function_name == self.assistant_message_tool_name: + if tool_call.function.name == self.assistant_message_tool_name: self.streaming_chat_completion_json_reader.reset() # early exit to turn into content mode return None # if we're in the middle of parsing a send_message, we'll keep processing the JSON chunks - if ( - tool_call.function.arguments - and self.streaming_chat_completion_mode_function_name == self.assistant_message_function_name - ): + if tool_call.function.arguments and self.streaming_chat_completion_mode_function_name == self.assistant_message_tool_name: # Strip out any extras tokens cleaned_func_args = self.streaming_chat_completion_json_reader.process_json_chunk(tool_call.function.arguments) # In the case that we just have the prefix of something, no message yet, then we should early exit to move to the next chunk @@ -909,13 +906,13 @@ def function_message(self, msg: str, msg_obj: Optional[Message] = None): if ( self.use_assistant_message - and function_call.function.name == self.assistant_message_function_name - and self.assistant_message_function_kwarg in func_args + and function_call.function.name == self.assistant_message_tool_name + and self.assistant_message_tool_kwarg in func_args ): processed_chunk = AssistantMessage( id=msg_obj.id, date=msg_obj.created_at, - assistant_message=func_args[self.assistant_message_function_kwarg], + assistant_message=func_args[self.assistant_message_tool_kwarg], ) else: processed_chunk = FunctionCallMessage( diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index 3553760ecf..127e4fe952 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -14,7 +14,7 @@ LettaMessage, LettaMessageUnion, ) -from letta.schemas.letta_request import LettaRequest +from letta.schemas.letta_request import LettaRequest, LettaStreamingRequest from letta.schemas.letta_response import LettaResponse from letta.schemas.memory import ( ArchivalMemorySummary, @@ -406,11 +406,11 @@ def get_agent_messages( False, description="[Only applicable if msg_object is False] If true, returns AssistantMessage objects when the agent calls a designated message tool. If false, return FunctionCallMessage objects for all tool calls.", ), - assistant_message_function_name: str = Query( + assistant_message_tool_name: str = Query( DEFAULT_MESSAGE_TOOL, description="[Only applicable if use_assistant_message is True] The name of the designated message tool.", ), - assistant_message_function_kwarg: str = Query( + assistant_message_tool_kwarg: str = Query( DEFAULT_MESSAGE_TOOL_KWARG, description="[Only applicable if use_assistant_message is True] The name of the message argument in the designated message tool.", ), @@ -429,8 +429,8 @@ def get_agent_messages( reverse=True, return_message_object=msg_object, use_assistant_message=use_assistant_message, - assistant_message_function_name=assistant_message_function_name, - assistant_message_function_kwarg=assistant_message_function_kwarg, + assistant_message_tool_name=assistant_message_tool_name, + assistant_message_tool_kwarg=assistant_message_tool_kwarg, ) @@ -450,28 +450,61 @@ def update_message( @router.post( "/{agent_id}/messages", + response_model=LettaResponse, + operation_id="create_agent_message", +) +async def send_message( + agent_id: str, + server: SyncServer = Depends(get_letta_server), + request: LettaRequest = Body(...), + user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present +): + """ + Process a user message and return the agent's response. + This endpoint accepts a message from a user and processes it through the agent. + """ + actor = server.get_user_or_default(user_id=user_id) + + agent_lock = server.per_agent_lock_manager.get_lock(agent_id) + async with agent_lock: + result = await send_message_to_agent( + server=server, + agent_id=agent_id, + user_id=actor.id, + messages=request.messages, + stream_steps=False, + stream_tokens=False, + return_message_object=False, + # Support for AssistantMessage + assistant_message_tool_name=request.assistant_message_tool_name, + assistant_message_tool_kwarg=request.assistant_message_tool_kwarg, + ) + return result + + +@router.post( + "/{agent_id}/messages/stream", response_model=None, operation_id="create_agent_message", responses={ 200: { "description": "Successful response", "content": { - "application/json": {"$ref": "#/components/schemas/LettaResponse"}, # Use model_json_schema() instead of model directly "text/event-stream": {"description": "Server-Sent Events stream"}, }, } }, ) -async def send_message( +async def send_message_streaming( agent_id: str, server: SyncServer = Depends(get_letta_server), - request: LettaRequest = Body(...), + request: LettaStreamingRequest = Body(...), user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present ): """ Process a user message and return the agent's response. This endpoint accepts a message from a user and processes it through the agent. - It can optionally stream the response if 'stream_steps' or 'stream_tokens' is set to True. + It will stream the steps of the response always, and stream the tokens if 'stream_tokens' is set to True. """ actor = server.get_user_or_default(user_id=user_id) @@ -482,15 +515,14 @@ async def send_message( agent_id=agent_id, user_id=actor.id, messages=request.messages, - stream_steps=request.stream_steps, + stream_steps=True, stream_tokens=request.stream_tokens, - return_message_object=request.return_message_object, + return_message_object=False, # Support for AssistantMessage - use_assistant_message=request.use_assistant_message, - assistant_message_function_name=request.assistant_message_function_name, - assistant_message_function_kwarg=request.assistant_message_function_kwarg, + assistant_message_tool_name=request.assistant_message_tool_name, + assistant_message_tool_kwarg=request.assistant_message_tool_kwarg, ) - return result + return result # TODO: move this into server.py? @@ -508,8 +540,8 @@ async def send_message_to_agent( timestamp: Optional[datetime] = None, # Support for AssistantMessage use_assistant_message: bool = False, - assistant_message_function_name: str = DEFAULT_MESSAGE_TOOL, - assistant_message_function_kwarg: str = DEFAULT_MESSAGE_TOOL_KWARG, + assistant_message_tool_name: str = DEFAULT_MESSAGE_TOOL, + assistant_message_tool_kwarg: str = DEFAULT_MESSAGE_TOOL_KWARG, ) -> Union[StreamingResponse, LettaResponse]: """Split off into a separate function so that it can be imported in the /chat/completion proxy.""" @@ -551,8 +583,8 @@ async def send_message_to_agent( # Allow AssistantMessage is desired by client streaming_interface.use_assistant_message = use_assistant_message - streaming_interface.assistant_message_function_name = assistant_message_function_name - streaming_interface.assistant_message_function_kwarg = assistant_message_function_kwarg + streaming_interface.assistant_message_tool_name = assistant_message_tool_name + streaming_interface.assistant_message_tool_kwarg = assistant_message_tool_kwarg # Related to JSON buffer reader streaming_interface.inner_thoughts_in_kwargs = ( diff --git a/letta/server/server.py b/letta/server/server.py index f06689aa65..4d6d944d6d 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -1355,8 +1355,8 @@ def get_agent_recall_cursor( reverse: Optional[bool] = False, return_message_object: bool = True, use_assistant_message: bool = False, - assistant_message_function_name: str = constants.DEFAULT_MESSAGE_TOOL, - assistant_message_function_kwarg: str = constants.DEFAULT_MESSAGE_TOOL_KWARG, + assistant_message_tool_name: str = constants.DEFAULT_MESSAGE_TOOL, + assistant_message_tool_kwarg: str = constants.DEFAULT_MESSAGE_TOOL_KWARG, ) -> Union[List[Message], List[LettaMessage]]: if self.user_manager.get_user_by_id(user_id=user_id) is None: raise ValueError(f"User user_id={user_id} does not exist") @@ -1381,8 +1381,8 @@ def get_agent_recall_cursor( for m in records for msg in m.to_letta_message( assistant_message=use_assistant_message, - assistant_message_function_name=assistant_message_function_name, - assistant_message_function_kwarg=assistant_message_function_kwarg, + assistant_message_tool_name=assistant_message_tool_name, + assistant_message_tool_kwarg=assistant_message_tool_kwarg, )[::-1] ] else: @@ -1391,8 +1391,8 @@ def get_agent_recall_cursor( for m in records for msg in m.to_letta_message( assistant_message=use_assistant_message, - assistant_message_function_name=assistant_message_function_name, - assistant_message_function_kwarg=assistant_message_function_kwarg, + assistant_message_tool_name=assistant_message_tool_name, + assistant_message_tool_kwarg=assistant_message_tool_kwarg, ) ] diff --git a/letta/server/static_files/assets/index-9fa459a2.js b/letta/server/static_files/assets/index-9fa459a2.js index 103d9649cd..c5bb64bf14 100644 --- a/letta/server/static_files/assets/index-9fa459a2.js +++ b/letta/server/static_files/assets/index-9fa459a2.js @@ -86,7 +86,7 @@ Error generating stack: `+o.message+` `)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(a=>r.set(a)),r}static accessor(t){const r=(this[a2]=this[a2]={accessors:{}}).accessors,a=this.prototype;function o(i){const s=lu(i);r[s]||(cZ(a,i),r[s]=!0)}return J.isArray(t)?t.forEach(o):o(t),this}}Ym.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);J.reduceDescriptors(Ym.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}});J.freezeMethods(Ym);const fo=Ym;function Ab(e,t){const n=this||u_,r=t||n,a=fo.from(r.headers);let o=r.data;return J.forEach(e,function(s){o=s.call(n,o,a.normalize(),t?t.status:void 0)}),a.normalize(),o}function s6(e){return!!(e&&e.__CANCEL__)}function of(e,t,n){st.call(this,e??"canceled",st.ERR_CANCELED,t,n),this.name="CanceledError"}J.inherits(of,st,{__CANCEL__:!0});function uZ(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new st("Request failed with status code "+n.status,[st.ERR_BAD_REQUEST,st.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}const dZ=Ia.hasStandardBrowserEnv?{write(e,t,n,r,a,o){const i=[e+"="+encodeURIComponent(t)];J.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),J.isString(r)&&i.push("path="+r),J.isString(a)&&i.push("domain="+a),o===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function fZ(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function pZ(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function l6(e,t){return e&&!fZ(t)?pZ(e,t):t}const gZ=Ia.hasStandardBrowserEnv?function(){const t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");let r;function a(o){let i=o;return t&&(n.setAttribute("href",i),i=n.href),n.setAttribute("href",i),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:n.pathname.charAt(0)==="/"?n.pathname:"/"+n.pathname}}return r=a(window.location.href),function(i){const s=J.isString(i)?a(i):i;return s.protocol===r.protocol&&s.host===r.host}}():function(){return function(){return!0}}();function mZ(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function hZ(e,t){e=e||10;const n=new Array(e),r=new Array(e);let a=0,o=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),u=r[o];i||(i=c),n[a]=l,r[a]=c;let d=o,g=0;for(;d!==a;)g+=n[d++],d=d%e;if(a=(a+1)%e,a===o&&(o=(o+1)%e),c-i{const o=a.loaded,i=a.lengthComputable?a.total:void 0,s=o-n,l=r(s),c=o<=i;n=o;const u={loaded:o,total:i,progress:i?o/i:void 0,bytes:s,rate:l||void 0,estimated:l&&i&&c?(i-o)/l:void 0,event:a};u[t?"download":"upload"]=!0,e(u)}}const bZ=typeof XMLHttpRequest<"u",yZ=bZ&&function(e){return new Promise(function(n,r){let a=e.data;const o=fo.from(e.headers).normalize();let{responseType:i,withXSRFToken:s}=e,l;function c(){e.cancelToken&&e.cancelToken.unsubscribe(l),e.signal&&e.signal.removeEventListener("abort",l)}let u;if(J.isFormData(a)){if(Ia.hasStandardBrowserEnv||Ia.hasStandardBrowserWebWorkerEnv)o.setContentType(!1);else if((u=o.getContentType())!==!1){const[y,...w]=u?u.split(";").map(v=>v.trim()).filter(Boolean):[];o.setContentType([y||"multipart/form-data",...w].join("; "))}}let d=new XMLHttpRequest;if(e.auth){const y=e.auth.username||"",w=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(y+":"+w))}const g=l6(e.baseURL,e.url);d.open(e.method.toUpperCase(),r6(g,e.params,e.paramsSerializer),!0),d.timeout=e.timeout;function m(){if(!d)return;const y=fo.from("getAllResponseHeaders"in d&&d.getAllResponseHeaders()),v={data:!i||i==="text"||i==="json"?d.responseText:d.response,status:d.status,statusText:d.statusText,headers:y,config:e,request:d};uZ(function(S){n(S),c()},function(S){r(S),c()},v),d=null}if("onloadend"in d?d.onloadend=m:d.onreadystatechange=function(){!d||d.readyState!==4||d.status===0&&!(d.responseURL&&d.responseURL.indexOf("file:")===0)||setTimeout(m)},d.onabort=function(){d&&(r(new st("Request aborted",st.ECONNABORTED,e,d)),d=null)},d.onerror=function(){r(new st("Network Error",st.ERR_NETWORK,e,d)),d=null},d.ontimeout=function(){let w=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const v=e.transitional||a6;e.timeoutErrorMessage&&(w=e.timeoutErrorMessage),r(new st(w,v.clarifyTimeoutError?st.ETIMEDOUT:st.ECONNABORTED,e,d)),d=null},Ia.hasStandardBrowserEnv&&(s&&J.isFunction(s)&&(s=s(e)),s||s!==!1&&gZ(g))){const y=e.xsrfHeaderName&&e.xsrfCookieName&&dZ.read(e.xsrfCookieName);y&&o.set(e.xsrfHeaderName,y)}a===void 0&&o.setContentType(null),"setRequestHeader"in d&&J.forEach(o.toJSON(),function(w,v){d.setRequestHeader(v,w)}),J.isUndefined(e.withCredentials)||(d.withCredentials=!!e.withCredentials),i&&i!=="json"&&(d.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&d.addEventListener("progress",o2(e.onDownloadProgress,!0)),typeof e.onUploadProgress=="function"&&d.upload&&d.upload.addEventListener("progress",o2(e.onUploadProgress)),(e.cancelToken||e.signal)&&(l=y=>{d&&(r(!y||y.type?new of(null,e,d):y),d.abort(),d=null)},e.cancelToken&&e.cancelToken.subscribe(l),e.signal&&(e.signal.aborted?l():e.signal.addEventListener("abort",l)));const b=mZ(g);if(b&&Ia.protocols.indexOf(b)===-1){r(new st("Unsupported protocol "+b+":",st.ERR_BAD_REQUEST,e));return}d.send(a||null)})},q1={http:BY,xhr:yZ};J.forEach(q1,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const i2=e=>`- ${e}`,vZ=e=>J.isFunction(e)||e===null||e===!1,c6={getAdapter:e=>{e=J.isArray(e)?e:[e];const{length:t}=e;let n,r;const a={};for(let o=0;o`adapter ${s} `+(l===!1?"is not supported by the environment":"is not available in the build"));let i=t?o.length>1?`since : `+o.map(i2).join(` `):" "+i2(o[0]):"as no adapter specified";throw new st("There is no suitable adapter to dispatch the request "+i,"ERR_NOT_SUPPORT")}return r},adapters:q1};function Tb(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new of(null,e)}function s2(e){return Tb(e),e.headers=fo.from(e.headers),e.data=Ab.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),c6.getAdapter(e.adapter||u_.adapter)(e).then(function(r){return Tb(e),r.data=Ab.call(e,e.transformResponse,r),r.headers=fo.from(r.headers),r},function(r){return s6(r)||(Tb(e),r&&r.response&&(r.response.data=Ab.call(e,e.transformResponse,r.response),r.response.headers=fo.from(r.response.headers))),Promise.reject(r)})}const l2=e=>e instanceof fo?{...e}:e;function bc(e,t){t=t||{};const n={};function r(c,u,d){return J.isPlainObject(c)&&J.isPlainObject(u)?J.merge.call({caseless:d},c,u):J.isPlainObject(u)?J.merge({},u):J.isArray(u)?u.slice():u}function a(c,u,d){if(J.isUndefined(u)){if(!J.isUndefined(c))return r(void 0,c,d)}else return r(c,u,d)}function o(c,u){if(!J.isUndefined(u))return r(void 0,u)}function i(c,u){if(J.isUndefined(u)){if(!J.isUndefined(c))return r(void 0,c)}else return r(void 0,u)}function s(c,u,d){if(d in t)return r(c,u);if(d in e)return r(void 0,c)}const l={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:s,headers:(c,u)=>a(l2(c),l2(u),!0)};return J.forEach(Object.keys(Object.assign({},e,t)),function(u){const d=l[u]||a,g=d(e[u],t[u],u);J.isUndefined(g)&&d!==s||(n[u]=g)}),n}const u6="1.6.8",d_={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{d_[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const c2={};d_.transitional=function(t,n,r){function a(o,i){return"[Axios v"+u6+"] Transitional option '"+o+"'"+i+(r?". "+r:"")}return(o,i,s)=>{if(t===!1)throw new st(a(i," has been removed"+(n?" in "+n:"")),st.ERR_DEPRECATED);return n&&!c2[i]&&(c2[i]=!0,console.warn(a(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,i,s):!0}};function SZ(e,t,n){if(typeof e!="object")throw new st("options must be an object",st.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let a=r.length;for(;a-- >0;){const o=r[a],i=t[o];if(i){const s=e[o],l=s===void 0||i(s,o,e);if(l!==!0)throw new st("option "+o+" must be "+l,st.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new st("Unknown option "+o,st.ERR_BAD_OPTION)}}const G1={assertOptions:SZ,validators:d_},Mo=G1.validators;class Rg{constructor(t){this.defaults=t,this.interceptors={request:new r2,response:new r2}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let a;Error.captureStackTrace?Error.captureStackTrace(a={}):a=new Error;const o=a.stack?a.stack.replace(/^.+\n/,""):"";r.stack?o&&!String(r.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(r.stack+=` -`+o):r.stack=o}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=bc(this.defaults,n);const{transitional:r,paramsSerializer:a,headers:o}=n;r!==void 0&&G1.assertOptions(r,{silentJSONParsing:Mo.transitional(Mo.boolean),forcedJSONParsing:Mo.transitional(Mo.boolean),clarifyTimeoutError:Mo.transitional(Mo.boolean)},!1),a!=null&&(J.isFunction(a)?n.paramsSerializer={serialize:a}:G1.assertOptions(a,{encode:Mo.function,serialize:Mo.function},!0)),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&J.merge(o.common,o[n.method]);o&&J.forEach(["delete","get","head","post","put","patch","common"],b=>{delete o[b]}),n.headers=fo.concat(i,o);const s=[];let l=!0;this.interceptors.request.forEach(function(y){typeof y.runWhen=="function"&&y.runWhen(n)===!1||(l=l&&y.synchronous,s.unshift(y.fulfilled,y.rejected))});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let u,d=0,g;if(!l){const b=[s2.bind(this),void 0];for(b.unshift.apply(b,s),b.push.apply(b,c),g=b.length,u=Promise.resolve(n);d{if(!r._listeners)return;let o=r._listeners.length;for(;o-- >0;)r._listeners[o](a);r._listeners=null}),this.promise.then=a=>{let o;const i=new Promise(s=>{r.subscribe(s),o=s}).then(a);return i.cancel=function(){r.unsubscribe(o)},i},t(function(o,i,s){r.reason||(r.reason=new of(o,i,s),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}static source(){let t;return{token:new f_(function(a){t=a}),cancel:t}}}const wZ=f_;function EZ(e){return function(n){return e.apply(null,n)}}function xZ(e){return J.isObject(e)&&e.isAxiosError===!0}const W1={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(W1).forEach(([e,t])=>{W1[t]=e});const kZ=W1;function d6(e){const t=new Vp(e),n=qF(Vp.prototype.request,t);return J.extend(n,Vp.prototype,t,{allOwnKeys:!0}),J.extend(n,t,null,{allOwnKeys:!0}),n.create=function(a){return d6(bc(e,a))},n}const rn=d6(u_);rn.Axios=Vp;rn.CanceledError=of;rn.CancelToken=wZ;rn.isCancel=s6;rn.VERSION=u6;rn.toFormData=Km;rn.AxiosError=st;rn.Cancel=rn.CanceledError;rn.all=function(t){return Promise.all(t)};rn.spread=EZ;rn.isAxiosError=xZ;rn.mergeConfig=bc;rn.AxiosHeaders=fo;rn.formToJSON=e=>i6(J.isHTMLForm(e)?new FormData(e):e);rn.getAdapter=c6.getAdapter;rn.HttpStatusCode=kZ;rn.default=rn;const f6=rn,CZ={baseURL:sY,headers:{"Content-Type":"application/json","Cache-Control":"no-cache"}},cl=f6.create(CZ),_Z=()=>cl,AZ=({children:e})=>{const[t,n]=p.useState(!1),r=Mi(),a=VF();return p.useEffect(()=>{const o=s=>s,i=s=>Promise.reject(s);cl.interceptors.response.use(o,i)},[r,cl]),p.useEffect(()=>{const o=s=>(s.headers.Authorization=a||"",s),i=cl.interceptors.request.use(o);return()=>{cl.interceptors.request.eject(i)}},[a,cl]),p.useEffect(()=>{t||setTimeout(()=>n(!0),10)},[t]),t?e:f.jsx("div",{className:"sr-only",children:"Re-authenticating..."})},TZ="ToolsServiceListTools",p_=({userId:e}={},t)=>[TZ,...t??[{userId:e}]],RZ="SourcesServiceListSources",sf=({userId:e}={},t)=>[RZ,...t??[{userId:e}]],NZ="AgentsServiceListAgents",p6=({userId:e}={},t)=>[NZ,...t??[{userId:e}]],IZ="AgentsServiceGetAgent",$s=({agentId:e,userId:t},n)=>[IZ,...n??[{agentId:e,userId:t}]],OZ="AgentsServiceGetAgentSources",g6=({agentId:e},t)=>[OZ,...t??[{agentId:e}]],DZ="AgentsServiceListAgentArchivalMemory",m6=({after:e,agentId:t,before:n,limit:r,userId:a},o)=>[DZ,...o??[{after:e,agentId:t,before:n,limit:r,userId:a}]],LZ="AgentsServiceListAgentMessages",MZ=({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s},l)=>[LZ,...l??[{agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s}]],PZ="ModelsServiceListModels",$Z=e=>[PZ,...e??[]],FZ="LlmsServiceListEmbeddingModels",jZ=e=>[FZ,...e??[]],zZ="BlocksServiceListMemoryBlocks",lf=({label:e,name:t,templatesOnly:n,userId:r}={},a)=>[zZ,...a??[{label:e,name:t,templatesOnly:n,userId:r}]],UZ="JobsServiceListJobs",BZ=({sourceId:e,userId:t}={},n)=>[UZ,...n??[{sourceId:e,userId:t}]],HZ="JobsServiceListActiveJobs",h6=({userId:e}={},t)=>[HZ,...t??[{userId:e}]];class u2{constructor(){this._fns=[]}eject(t){const n=this._fns.indexOf(t);n!==-1&&(this._fns=[...this._fns.slice(0,n),...this._fns.slice(n+1)])}use(t){this._fns=[...this._fns,t]}}const Ie={CREDENTIALS:"include",ENCODE_PATH:void 0,HEADERS:void 0,PASSWORD:void 0,TOKEN:void 0,USERNAME:void 0,VERSION:"1.0.0",WITH_CREDENTIALS:!1,interceptors:{request:new u2,response:new u2},BASE:""};class d2 extends Error{constructor(t,n,r){super(r),this.name="ApiError",this.url=n.url,this.status=n.status,this.statusText=n.statusText,this.body=n.body,this.request=t}}class VZ extends Error{constructor(t){super(t),this.name="CancelError"}get isCancelled(){return!0}}class qZ{constructor(t){this._isResolved=!1,this._isRejected=!1,this._isCancelled=!1,this.cancelHandlers=[],this.promise=new Promise((n,r)=>{this._resolve=n,this._reject=r;const a=s=>{this._isResolved||this._isRejected||this._isCancelled||(this._isResolved=!0,this._resolve&&this._resolve(s))},o=s=>{this._isResolved||this._isRejected||this._isCancelled||(this._isRejected=!0,this._reject&&this._reject(s))},i=s=>{this._isResolved||this._isRejected||this._isCancelled||this.cancelHandlers.push(s)};return Object.defineProperty(i,"isResolved",{get:()=>this._isResolved}),Object.defineProperty(i,"isRejected",{get:()=>this._isRejected}),Object.defineProperty(i,"isCancelled",{get:()=>this._isCancelled}),t(a,o,i)})}get[Symbol.toStringTag](){return"Cancellable Promise"}then(t,n){return this.promise.then(t,n)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}cancel(){if(!(this._isResolved||this._isRejected||this._isCancelled)){if(this._isCancelled=!0,this.cancelHandlers.length)try{for(const t of this.cancelHandlers)t()}catch(t){console.warn("Cancellation threw an error",t);return}this.cancelHandlers.length=0,this._reject&&this._reject(new VZ("Request aborted"))}}get isCancelled(){return this._isCancelled}}const Zm=e=>typeof e=="string",Rb=e=>Zm(e)&&e!=="",b6=e=>e instanceof Blob,GZ=e=>e instanceof FormData,f2=e=>e>=200&&e<300,WZ=e=>{try{return btoa(e)}catch{return Buffer.from(e).toString("base64")}},KZ=e=>{const t=[],n=(a,o)=>{t.push(`${encodeURIComponent(a)}=${encodeURIComponent(String(o))}`)},r=(a,o)=>{o!=null&&(o instanceof Date?n(a,o.toISOString()):Array.isArray(o)?o.forEach(i=>r(a,i)):typeof o=="object"?Object.entries(o).forEach(([i,s])=>r(`${a}[${i}]`,s)):n(a,o))};return Object.entries(e).forEach(([a,o])=>r(a,o)),t.length?`?${t.join("&")}`:""},YZ=(e,t)=>{const n=e.ENCODE_PATH||encodeURI,r=t.url.replace("{api-version}",e.VERSION).replace(/{(.*?)}/g,(o,i)=>{var s;return(s=t.path)!=null&&s.hasOwnProperty(i)?n(String(t.path[i])):o}),a=e.BASE+r;return t.query?a+KZ(t.query):a},ZZ=e=>{if(e.formData){const t=new FormData,n=(r,a)=>{Zm(a)||b6(a)?t.append(r,a):t.append(r,JSON.stringify(a))};return Object.entries(e.formData).filter(([,r])=>r!=null).forEach(([r,a])=>{Array.isArray(a)?a.forEach(o=>n(r,o)):n(r,a)}),t}},Yf=async(e,t)=>typeof t=="function"?t(e):t,XZ=async(e,t)=>{const[n,r,a,o]=await Promise.all([Yf(t,e.TOKEN),Yf(t,e.USERNAME),Yf(t,e.PASSWORD),Yf(t,e.HEADERS)]),i=Object.entries({Accept:"application/json",...o,...t.headers}).filter(([,s])=>s!=null).reduce((s,[l,c])=>({...s,[l]:String(c)}),{});if(Rb(n)&&(i.Authorization=`Bearer ${n}`),Rb(r)&&Rb(a)){const s=WZ(`${r}:${a}`);i.Authorization=`Basic ${s}`}return t.body!==void 0?t.mediaType?i["Content-Type"]=t.mediaType:b6(t.body)?i["Content-Type"]=t.body.type||"application/octet-stream":Zm(t.body)?i["Content-Type"]="text/plain":GZ(t.body)||(i["Content-Type"]="application/json"):t.formData!==void 0&&t.mediaType&&(i["Content-Type"]=t.mediaType),i},QZ=e=>{if(e.body)return e.body},JZ=async(e,t,n,r,a,o,i,s)=>{const l=new AbortController;let c={data:r??a,headers:o,method:t.method,signal:l.signal,url:n,withCredentials:e.WITH_CREDENTIALS};i(()=>l.abort());for(const u of e.interceptors.request._fns)c=await u(c);try{return await s.request(c)}catch(u){const d=u;if(d.response)return d.response;throw u}},eX=(e,t)=>{if(t){const n=e.headers[t];if(Zm(n))return n}},tX=e=>{if(e.status!==204)return e.data},nX=(e,t)=>{const r={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"Im a teapot",421:"Misdirected Request",422:"Unprocessable Content",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required",...e.errors}[t.status];if(r)throw new d2(e,t,r);if(!t.ok){const a=t.status??"unknown",o=t.statusText??"unknown",i=(()=>{try{return JSON.stringify(t.body,null,2)}catch{return}})();throw new d2(e,t,`Generic Error: status: ${a}; status text: ${o}; body: ${i}`)}},Pe=(e,t,n=f6)=>new qZ(async(r,a,o)=>{try{const i=YZ(e,t),s=ZZ(t),l=QZ(t),c=await XZ(e,t);if(!o.isCancelled){let u=await JZ(e,t,i,l,s,c,o,n);for(const y of e.interceptors.response._fns)u=await y(u);const d=tX(u),g=eX(u,t.responseHeader);let m=d;t.responseTransformer&&f2(u.status)&&(m=await t.responseTransformer(d));const b={url:i,ok:f2(u.status),status:u.status,statusText:u.statusText,body:g??m};nX(t,b),r(b.body)}}catch(i){a(i)}});class g_{static deleteTool(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/tools/{tool_id}",path:{tool_id:t.toolId},errors:{422:"Validation Error"},headers:n})}static getTool(t,n){return Pe(Ie,{method:"GET",url:"/v1/tools/{tool_id}",path:{tool_id:t.toolId},errors:{422:"Validation Error"},headers:n})}static updateTool(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/tools/{tool_id}",path:{tool_id:t.toolId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static getToolIdByName(t,n){return Pe(Ie,{method:"GET",url:"/v1/tools/name/{tool_name}",path:{tool_name:t.toolName},errors:{422:"Validation Error"},headers:n})}static listTools(t={},n){return Pe(Ie,{method:"GET",url:"/v1/tools/",errors:{422:"Validation Error"},headers:n})}static createTool(t,n){return Pe(Ie,{method:"POST",url:"/v1/tools/",query:{update:t.update},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}}class Pc{static getSource(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/{source_id}",path:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static updateSource(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/sources/{source_id}",path:{source_id:t.sourceId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static deleteSource(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/sources/{source_id}",path:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static getSourceIdByName(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/name/{source_name}",path:{source_name:t.sourceName},errors:{422:"Validation Error"},headers:n})}static listSources(t={},n){return Pe(Ie,{method:"GET",url:"/v1/sources/",errors:{422:"Validation Error"},headers:n})}static createSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/",body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static attachAgentToSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/{source_id}/attach",path:{source_id:t.sourceId},query:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static detachAgentFromSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/{source_id}/detach",path:{source_id:t.sourceId},query:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static uploadFileToSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/{source_id}/upload",path:{source_id:t.sourceId},formData:t.formData,mediaType:"multipart/form-data",errors:{422:"Validation Error"},headers:n})}static listSourcePassages(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/{source_id}/passages",path:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static listFilesFromSource(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/{source_id}/files",path:{source_id:t.sourceId},query:{limit:t.limit,cursor:t.cursor},errors:{422:"Validation Error"},headers:n})}}class Va{static listAgents(t={},n){return Pe(Ie,{method:"GET",url:"/v1/agents/",errors:{422:"Validation Error"},headers:n})}static createAgent(t,n){return Pe(Ie,{method:"POST",url:"/v1/agents/",body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static updateAgent(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/agents/{agent_id}",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static getAgent(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static deleteAgent(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/agents/{agent_id}",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static getAgentSources(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/sources",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static listAgentInContextMessages(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory/messages",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static getAgentMemory(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static updateAgentMemory(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/agents/{agent_id}/memory",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static getAgentRecallMemorySummary(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory/recall",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static getAgentArchivalMemorySummary(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory/archival",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static listAgentArchivalMemory(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/archival",path:{agent_id:t.agentId},query:{after:t.after,before:t.before,limit:t.limit},errors:{422:"Validation Error"},headers:n})}static createAgentArchivalMemory(t,n){return Pe(Ie,{method:"POST",url:"/v1/agents/{agent_id}/archival",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static deleteAgentArchivalMemory(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/agents/{agent_id}/archival/{memory_id}",path:{agent_id:t.agentId,memory_id:t.memoryId},errors:{422:"Validation Error"},headers:n})}static listAgentMessages(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/messages",path:{agent_id:t.agentId},query:{before:t.before,limit:t.limit,msg_object:t.msgObject,use_assistant_message:t.useAssistantMessage,assistant_message_function_name:t.assistantMessageFunctionName,assistant_message_function_kwarg:t.assistantMessageFunctionKwarg},errors:{422:"Validation Error"},headers:n})}static createAgentMessage(t,n){return Pe(Ie,{method:"POST",url:"/v1/agents/{agent_id}/messages",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static updateAgentMessage(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/agents/{agent_id}/messages/{message_id}",path:{agent_id:t.agentId,message_id:t.messageId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}}class rX{static listModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/",headers:t})}static listEmbeddingModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/embedding",headers:t})}}class aX{static listModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/",headers:t})}static listEmbeddingModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/embedding",headers:t})}}class m_{static listMemoryBlocks(t={},n){return Pe(Ie,{method:"GET",url:"/v1/blocks/",query:{label:t.label,templates_only:t.templatesOnly,name:t.name},errors:{422:"Validation Error"},headers:n})}static createMemoryBlock(t,n){return Pe(Ie,{method:"POST",url:"/v1/blocks/",body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static updateMemoryBlock(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/blocks/{block_id}",path:{block_id:t.blockId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static deleteMemoryBlock(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/blocks/{block_id}",path:{block_id:t.blockId},errors:{422:"Validation Error"},headers:n})}static getMemoryBlock(t,n){return Pe(Ie,{method:"GET",url:"/v1/blocks/{block_id}",path:{block_id:t.blockId},errors:{422:"Validation Error"},headers:n})}}class oX{static listJobs(t={},n){return Pe(Ie,{method:"GET",url:"/v1/jobs/",query:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static listActiveJobs(t={},n){return Pe(Ie,{method:"GET",url:"/v1/jobs/active",errors:{422:"Validation Error"},headers:n})}static getJob(t,n){return Pe(Ie,{method:"GET",url:"/v1/jobs/{job_id}",path:{job_id:t.jobId},errors:{422:"Validation Error"},headers:n})}static deleteJob(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/jobs/{job_id}",path:{job_id:t.jobId},errors:{422:"Validation Error"},headers:n})}}const Xm=({userId:e}={},t,n)=>Jr({queryKey:p_({userId:e},t),queryFn:()=>g_.listTools({userId:e}),...n}),h_=({userId:e}={},t,n)=>Jr({queryKey:sf({userId:e},t),queryFn:()=>Pc.listSources({userId:e}),...n}),Qm=({userId:e}={},t,n)=>Jr({queryKey:p6({userId:e},t),queryFn:()=>Va.listAgents({userId:e}),...n}),b_=({agentId:e,userId:t},n,r)=>Jr({queryKey:$s({agentId:e,userId:t},n),queryFn:()=>Va.getAgent({agentId:e,userId:t}),...r}),y6=({agentId:e},t,n)=>Jr({queryKey:g6({agentId:e},t),queryFn:()=>Va.getAgentSources({agentId:e}),...n}),v6=({after:e,agentId:t,before:n,limit:r,userId:a},o,i)=>Jr({queryKey:m6({after:e,agentId:t,before:n,limit:r,userId:a},o),queryFn:()=>Va.listAgentArchivalMemory({after:e,agentId:t,before:n,limit:r,userId:a}),...i}),iX=({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s},l,c)=>Jr({queryKey:MZ({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s},l),queryFn:()=>Va.listAgentMessages({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s}),...c}),S6=(e,t)=>Jr({queryKey:$Z(e),queryFn:()=>rX.listModels(),...t}),w6=(e,t)=>Jr({queryKey:jZ(e),queryFn:()=>aX.listEmbeddingModels(),...t}),Ng=({label:e,name:t,templatesOnly:n,userId:r}={},a,o)=>Jr({queryKey:lf({label:e,name:t,templatesOnly:n,userId:r},a),queryFn:()=>m_.listMemoryBlocks({label:e,name:t,templatesOnly:n,userId:r}),...o}),sX=({userId:e}={},t,n)=>Jr({queryKey:h6({userId:e},t),queryFn:()=>oX.listActiveJobs({userId:e}),...n}),lX=e=>gr({mutationFn:({requestBody:t,update:n,userId:r})=>g_.createTool({requestBody:t,update:n,userId:r}),...e}),cX=e=>gr({mutationFn:({requestBody:t,userId:n})=>Pc.createSource({requestBody:t,userId:n}),...e}),E6=e=>gr({mutationFn:({agentId:t,sourceId:n,userId:r})=>Pc.attachAgentToSource({agentId:t,sourceId:n,userId:r}),...e}),x6=e=>gr({mutationFn:({agentId:t,sourceId:n,userId:r})=>Pc.detachAgentFromSource({agentId:t,sourceId:n,userId:r}),...e}),k6=e=>gr({mutationFn:({formData:t,sourceId:n,userId:r})=>Pc.uploadFileToSource({formData:t,sourceId:n,userId:r}),...e}),uX=e=>gr({mutationFn:({requestBody:t,userId:n})=>Va.createAgent({requestBody:t,userId:n}),...e}),dX=e=>gr({mutationFn:({agentId:t,requestBody:n,userId:r})=>Va.createAgentArchivalMemory({agentId:t,requestBody:n,userId:r}),...e}),C6=e=>gr({mutationFn:({requestBody:t,userId:n})=>m_.createMemoryBlock({requestBody:t,userId:n}),...e}),fX=e=>gr({mutationFn:({requestBody:t,toolId:n,userId:r})=>g_.updateTool({requestBody:t,toolId:n,userId:r}),...e}),pX=e=>gr({mutationFn:({requestBody:t,sourceId:n,userId:r})=>Pc.updateSource({requestBody:t,sourceId:n,userId:r}),...e}),cf=e=>gr({mutationFn:({agentId:t,requestBody:n,userId:r})=>Va.updateAgent({agentId:t,requestBody:n,userId:r}),...e}),y_=e=>gr({mutationFn:({blockId:t,requestBody:n})=>m_.updateMemoryBlock({blockId:t,requestBody:n}),...e}),gX=e=>gr({mutationFn:({agentId:t,userId:n})=>Va.deleteAgent({agentId:t,userId:n}),...e}),mX=e=>gr({mutationFn:({agentId:t,memoryId:n,userId:r})=>Va.deleteAgentArchivalMemory({agentId:t,memoryId:n,userId:r}),...e});Ie.BASE="";Ie.HEADERS={"Content-Type":"application/json","Cache-Control":"no-cache"};const hX=({children:e})=>{const[t,n]=p.useState(!1),r=VF(),a=Mi();return p.useEffect(()=>{const o=i=>i;return Ie.interceptors.response.use(o),()=>{Ie.interceptors.response.eject(o)}},[a]),p.useEffect(()=>{const o=i=>(i.headers={...i.headers,Authorization:"Bearer password"},i);return Ie.interceptors.request.use(o),()=>{Ie.interceptors.request.eject(o)}},[r]),p.useEffect(()=>{t||setTimeout(()=>n(!0),10)},[t]),t?e:f.jsx("div",{className:"sr-only",children:"Re-authenticating..."})},yc=ef("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",xs:"text-xs h-7 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10",iconSm:"h-9 w-9",iconXs:"h-7 w-7"}},defaultVariants:{variant:"default",size:"default"}});function p2({isBusy:e,icon:t}){return e?f.jsx(un,{className:"h-4 w-4 animate-spin"}):t||null}const ue=p.forwardRef(({className:e,children:t,label:n,isBusy:r,icon:a,iconPosition:o="left",disabled:i,variant:s,size:l,asChild:c=!1,...u},d)=>{const g=c?$a:"button",m=p.useMemo(()=>i||r,[i,r]),b=p.useMemo(()=>a||o?"flex items-center gap-1":"",[a,o]);return f.jsxs(g,{className:ee(b,yc({variant:s,size:l,className:e})),disabled:m,ref:d,...u,children:[o==="left"&&f.jsx(p2,{isBusy:r??!1,icon:a??null}),f.jsx(Rm,{children:t}),o==="right"&&f.jsx(p2,{isBusy:r??!1,icon:a??null})]})});ue.displayName="Button";const Fs=({children:e,className:t})=>f.jsx("div",{className:ee("h-full w-full overflow-auto",t),children:e});function Zf({children:e,className:t}){return f.jsx("div",{className:ee("flex justify-center text-muted-foreground",t),children:e})}function bX(e){return f.jsxs("svg",{viewBox:"0 0 20 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M5.21875 8.90625H3.84375C3.46875 8.90625 3.125 9.21875 3.125 9.625C3.125 10.0313 3.4375 10.3437 3.84375 10.3437H5.21875C5.59375 10.3437 5.9375 10.0313 5.9375 9.625C5.9375 9.21875 5.59375 8.90625 5.21875 8.90625Z",fill:"currentColor"}),f.jsx("path",{d:"M12.875 8.90625H11.5C11.125 8.90625 10.7812 9.21875 10.7812 9.625C10.7812 10.0313 11.0937 10.3437 11.5 10.3437H12.875C13.25 10.3437 13.5938 10.0313 13.5938 9.625C13.5938 9.21875 13.25 8.90625 12.875 8.90625Z",fill:"currentColor"}),f.jsx("path",{d:"M17.7187 8.09375V3.9375C18.5 3.65625 19.0312 2.90625 19.0312 2.0625C19.0312 0.9375 18.125 0.03125 17 0.03125C15.875 0.03125 14.9687 0.9375 14.9687 2.0625C14.9687 2.9375 15.5312 3.65625 16.2812 3.9375V8.0625H15.9375V7.84375C15.9375 6.59375 14.9062 5.5625 13.6562 5.5625H11.875V4.875C11.875 3.84375 11.0312 3.03125 10.0312 3.03125H9.0625V0.96875C9.0625 0.59375 8.75 0.25 8.34375 0.25C7.9375 0.25 7.625 0.5625 7.625 0.96875V3.03125H6.625C5.59375 3.03125 4.78125 3.875 4.78125 4.875V5.5625H2.8125C1.5625 5.5625 0.53125 6.59375 0.53125 7.84375V13.6875C0.53125 14.9375 1.5625 15.9688 2.8125 15.9688H13.6875C14.9375 15.9688 15.9687 14.9375 15.9687 13.6875V13.4688H17.625C18.6562 13.4688 19.4687 12.625 19.4687 11.625V9.96875C19.4687 8.9375 18.6875 8.15625 17.7187 8.09375ZM17 1.4375C17.3437 1.4375 17.625 1.71875 17.625 2.0625C17.625 2.40625 17.3437 2.6875 17 2.6875C16.6562 2.6875 16.375 2.40625 16.375 2.0625C16.375 1.71875 16.6562 1.4375 17 1.4375ZM6.21875 4.875C6.21875 4.625 6.40625 4.4375 6.65625 4.4375H10.0312C10.2812 4.4375 10.4687 4.625 10.4687 4.875V5.5625H6.21875V4.875ZM14.5312 13.6875C14.5312 14.1562 14.1562 14.5625 13.6562 14.5625H2.8125C2.34375 14.5625 1.9375 14.1875 1.9375 13.6875V7.84375C1.9375 7.375 2.3125 6.96875 2.8125 6.96875H13.6875C14.1562 6.96875 14.5625 7.34375 14.5625 7.84375V13.6875H14.5312ZM18.0625 11.5938C18.0625 11.8438 17.875 12.0312 17.625 12.0312H15.9375V9.46875H17.5937C17.8437 9.46875 18.0312 9.65625 18.0312 9.90625V11.5938H18.0625Z",fill:"currentColor"}),f.jsx("path",{d:"M9.5 11.125C9.125 11.125 8.78125 11.4375 8.78125 11.8437C8.78125 12.0937 8.59375 12.2813 8.34375 12.2813C8.09375 12.2813 7.90625 12.0937 7.90625 11.8437C7.90625 11.4687 7.59375 11.125 7.1875 11.125C6.78125 11.125 6.46875 11.4375 6.46875 11.8437C6.46875 12.875 7.3125 13.6875 8.3125 13.6875C9.3125 13.6875 10.1562 12.8437 10.1562 11.8437C10.1875 11.4375 9.875 11.125 9.5 11.125Z",fill:"currentColor"})]})}function yX(e){return f.jsx("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:f.jsx("path",{d:"M8.00039 11.3998C7.85039 11.3998 7.72539 11.3498 7.60039 11.2498L1.85039 5.5998C1.62539 5.3748 1.62539 5.0248 1.85039 4.7998C2.07539 4.5748 2.42539 4.5748 2.65039 4.7998L8.00039 10.0248L13.3504 4.7498C13.5754 4.5248 13.9254 4.5248 14.1504 4.7498C14.3754 4.9748 14.3754 5.3248 14.1504 5.5498L8.40039 11.1998C8.27539 11.3248 8.15039 11.3998 8.00039 11.3998Z",fill:"currentColor"})})}function vX(e){return f.jsx("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:f.jsx("path",{d:"M13.7504 11.4002C13.6004 11.4002 13.4754 11.3502 13.3504 11.2502L8.00039 5.9752L2.65039 11.2252C2.42539 11.4502 2.07539 11.4502 1.85039 11.2252C1.62539 11.0002 1.62539 10.6502 1.85039 10.4252L7.60039 4.7752C7.82539 4.5502 8.17539 4.5502 8.40039 4.7752L14.1504 10.4252C14.3754 10.6502 14.3754 11.0002 14.1504 11.2252C14.0504 11.3252 13.9004 11.4002 13.7504 11.4002Z",fill:"currentColor"})})}function SX(e){return f.jsxs("svg",{viewBox:"0 0 20 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M10 9.5C12.5938 9.5 14.6875 7.40625 14.6875 4.8125C14.6875 2.21875 12.5938 0.125 10 0.125C7.40625 0.125 5.3125 2.21875 5.3125 4.8125C5.3125 7.40625 7.40625 9.5 10 9.5ZM10 1.53125C11.8125 1.53125 13.2812 3 13.2812 4.8125C13.2812 6.625 11.8125 8.09375 10 8.09375C8.1875 8.09375 6.71875 6.625 6.71875 4.8125C6.71875 3 8.1875 1.53125 10 1.53125Z",fill:"currentColor"}),f.jsx("path",{d:"M19.2191 14.625C16.6566 12.4688 13.4066 11.2812 10.0004 11.2812C6.59412 11.2812 3.34412 12.4688 0.781616 14.625C0.500366 14.875 0.437866 15.3125 0.687866 15.625C0.937866 15.9063 1.37537 15.9688 1.68787 15.7188C4.00037 13.75 6.93787 12.6875 10.0004 12.6875C13.0629 12.6875 16.0004 13.75 18.2816 15.6875C18.4066 15.8125 18.5629 15.8438 18.7504 15.8438C18.9379 15.8438 19.1566 15.75 19.2816 15.5938C19.5316 15.3125 19.5004 14.875 19.2191 14.625Z",fill:"currentColor"})]})}function wX(e){return f.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M17.875 2.9375H11C10.625 2.9375 10.2812 3.0625 10 3.25C9.71875 3.0625 9.375 2.9375 9 2.9375H2.125C1.25 2.9375 0.5625 3.65625 0.5625 4.5V14.6875C0.5625 15.5625 1.28125 16.25 2.125 16.25H9.3125V16.3437C9.3125 16.7187 9.625 17.0625 10.0312 17.0625C10.4062 17.0625 10.75 16.75 10.75 16.3437V16.25H17.9375C18.8125 16.25 19.5 15.5312 19.5 14.6875V4.5C19.4688 3.625 18.75 2.9375 17.875 2.9375ZM2.125 14.875C2.03125 14.875 1.96875 14.8125 1.96875 14.7187V4.5C1.96875 4.40625 2.03125 4.34375 2.125 4.34375H9.03125C9.1875 4.34375 9.3125 4.46875 9.3125 4.625V14.875H2.125ZM18.0625 14.6875C18.0625 14.7812 18 14.8437 17.9062 14.8437H10.7188V4.625C10.7188 4.46875 10.8438 4.34375 11 4.34375H17.9062C18 4.34375 18.0625 4.40625 18.0625 4.5V14.6875Z",fill:"currentColor"}),f.jsx("path",{d:"M4.46875 7.40625H6.78125C7.15625 7.40625 7.5 7.09375 7.5 6.6875C7.5 6.28125 7.1875 5.96875 6.78125 5.96875H4.46875C4.09375 5.96875 3.75 6.28125 3.75 6.6875C3.75 7.09375 4.0625 7.40625 4.46875 7.40625Z",fill:"currentColor"}),f.jsx("path",{d:"M13.125 7.40625H15.4375C15.8125 7.40625 16.1562 7.09375 16.1562 6.6875C16.1562 6.28125 15.8438 5.96875 15.4375 5.96875H13.125C12.75 5.96875 12.4062 6.28125 12.4062 6.6875C12.4062 7.09375 12.75 7.40625 13.125 7.40625Z",fill:"currentColor"}),f.jsx("path",{d:"M15.5 8.5625H13.1875C12.8125 8.5625 12.4688 8.875 12.4688 9.28125C12.4688 9.6875 12.7812 10 13.1875 10H15.5C15.875 10 16.2188 9.6875 16.2188 9.28125C16.2188 8.875 15.875 8.5625 15.5 8.5625Z",fill:"currentColor"}),f.jsx("path",{d:"M6.8125 8.5625H4.5C4.125 8.5625 3.78125 8.875 3.78125 9.28125C3.78125 9.6875 4.09375 10 4.5 10H6.8125C7.1875 10 7.53125 9.6875 7.53125 9.28125C7.53125 8.875 7.21875 8.5625 6.8125 8.5625Z",fill:"currentColor"}),f.jsx("path",{d:"M6.8125 11.3125H4.5C4.125 11.3125 3.78125 11.625 3.78125 12.0312C3.78125 12.4375 4.09375 12.75 4.5 12.75H6.8125C7.1875 12.75 7.53125 12.4375 7.53125 12.0312C7.53125 11.625 7.21875 11.3125 6.8125 11.3125Z",fill:"currentColor"}),f.jsx("path",{d:"M15.5 11.3125H13.1875C12.8125 11.3125 12.4688 11.625 12.4688 12.0312C12.4688 12.4375 12.7812 12.75 13.1875 12.75H15.5C15.875 12.75 16.2188 12.4375 16.2188 12.0312C16.2188 11.625 15.875 11.3125 15.5 11.3125Z",fill:"currentColor"})]})}function EX(e){return f.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M17.5625 2.28125H2.4375C1.40625 2.28125 0.5625 3.125 0.5625 4.15625V12.875C0.5625 13.9063 1.40625 14.75 2.4375 14.75H6.9375L9.4375 17.5C9.5625 17.6563 9.75 17.7188 9.96875 17.7188C10.1562 17.7188 10.3438 17.625 10.5 17.5L13.0625 14.7188H17.5938C18.625 14.7188 19.4688 13.875 19.4688 12.8438V4.15625C19.4688 3.125 18.5938 2.28125 17.5625 2.28125ZM18.0625 12.8438C18.0625 13.0938 17.8438 13.3125 17.5938 13.3125H12.7188C12.5312 13.3125 12.3438 13.4063 12.1875 13.5313L9.9375 15.9688L7.75 13.5625C7.625 13.4063 7.4375 13.3438 7.21875 13.3438H2.4375C2.1875 13.3438 1.96875 13.125 1.96875 12.875V4.15625C1.96875 3.90625 2.1875 3.6875 2.4375 3.6875H17.5625C17.8125 3.6875 18.0312 3.90625 18.0312 4.15625V12.8438H18.0625Z",fill:"currentColor"}),f.jsx("path",{d:"M5.5625 7.59375C5.15625 7.59375 4.8125 7.9375 4.8125 8.34375C4.8125 8.75 5.15625 9.09375 5.5625 9.09375C5.96875 9.09375 6.3125 8.75 6.3125 8.34375C6.3125 7.9375 6 7.59375 5.5625 7.59375Z",fill:"currentColor"}),f.jsx("path",{d:"M10 7.59375C9.59375 7.59375 9.25 7.9375 9.25 8.34375C9.25 8.75 9.59375 9.09375 10 9.09375C10.4062 9.09375 10.75 8.75 10.75 8.34375C10.75 7.9375 10.4062 7.59375 10 7.59375Z",fill:"currentColor"}),f.jsx("path",{d:"M14.4375 7.59375C14.0313 7.59375 13.6875 7.9375 13.6875 8.34375C13.6875 8.75 14.0313 9.09375 14.4375 9.09375C14.8438 9.09375 15.1875 8.75 15.1875 8.34375C15.1875 7.9375 14.8438 7.59375 14.4375 7.59375Z",fill:"currentColor"})]})}function xX(e){return f.jsx("svg",{viewBox:"0 0 14 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:f.jsx("path",{d:"M7 0.5625C3.34375 0.5625 0.46875 2.28125 0.46875 4.4375V15.5625C0.46875 17.7188 3.40625 19.4375 6.96875 19.4375C10.5625 19.4375 13.5 17.6875 13.5 15.5625V4.4375C13.5312 2.25 10.6562 0.5625 7 0.5625ZM7 1.96875C10 1.96875 12.125 3.28125 12.125 4.4375C12.125 5.625 10.0312 6.90625 7 6.90625C3.96875 6.90625 1.875 5.59375 1.875 4.4375C1.875 3.25 4 1.96875 7 1.96875ZM7 18.0625C4.0625 18.0625 1.90625 16.75 1.90625 15.5938V14.375C3.09375 15.25 4.90625 15.7813 7 15.7813C9.09375 15.7813 10.9375 15.2188 12.125 14.375V15.5938C12.125 16.75 9.9375 18.0625 7 18.0625ZM7 14.375C4 14.375 1.90625 13.125 1.90625 12V10.5625C3.125 11.4375 5.03125 11.9688 7 11.9688C9.0625 11.9688 10.9063 11.4375 12.125 10.5625V12C12.125 13.125 10 14.375 7 14.375ZM11.3125 9.40625C10.3437 10.125 8.75 10.5625 7 10.5625C5.28125 10.5625 3.65625 10.125 2.6875 9.40625C2.3125 9.15625 1.90625 8.71875 1.90625 8.1875V6.875C3.09375 7.75 4.9375 8.3125 7.03125 8.3125C9.125 8.3125 10.9688 7.75 12.1562 6.875V8.1875C12.125 8.6875 11.6875 9.125 11.3125 9.40625Z",fill:"currentColor"})})}function kX(e){return f.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("g",{clipPath:"url(#clip0_6318_531)",children:f.jsx("path",{d:"M18.7505 13.7189L16.813 11.7814C16.0317 11.0002 14.7505 11.0002 13.9692 11.7814L13.438 12.3127L11.7192 10.5939L13.3442 8.96891L16.5317 8.12515C17.2192 7.93765 17.7817 7.37515 17.9692 6.68765L18.8755 3.3439C18.9692 2.9689 18.7505 2.5939 18.3755 2.4689C18.0005 2.37515 17.6255 2.5939 17.5005 2.9689L16.5942 6.31265C16.5317 6.5314 16.3755 6.68765 16.1567 6.75015L12.813 7.6564C12.688 7.68765 12.5942 7.75015 12.5005 7.8439L10.7505 9.59391L9.68799 8.5314L11.438 6.7814C11.5317 6.68765 11.5942 6.5939 11.6255 6.4689L12.5005 3.12515C12.563 2.9064 12.7192 2.75015 12.938 2.68765L16.2817 1.7814C16.6567 1.68765 16.8755 1.2814 16.7817 0.906405C16.688 0.531405 16.313 0.312655 15.938 0.437655L12.5942 1.31265C11.9067 1.50015 11.3442 2.06265 11.1567 2.75015L10.313 5.9064L8.68799 7.5314L7.063 5.9064C7.688 5.18765 7.7505 4.12515 7.188 3.3439L5.84425 1.56265C5.5005 1.0939 4.96925 0.812655 4.3755 0.781405C3.78175 0.750155 3.21925 0.937655 2.813 1.37515L1.53175 2.6564C1.1255 3.06265 0.906746 3.62515 0.937996 4.2189C0.969246 4.81265 1.2505 5.3439 1.71925 5.68765L3.5005 7.0314C3.84425 7.31265 4.28175 7.43765 4.71925 7.43765C5.21925 7.43765 5.688 7.25015 6.063 6.9064L7.688 8.5314L5.59425 10.6252L2.438 11.4689C1.7505 11.6564 1.188 12.2189 1.0005 12.9064L0.312996 15.5002C0.125496 16.1877 0.312996 16.9377 0.844246 17.4689L1.813 18.4377C2.188 18.8127 2.71925 19.0314 3.2505 19.0314C3.438 19.0314 3.59425 19.0002 3.78175 18.9689L6.3755 18.2814C7.063 18.0939 7.6255 17.5314 7.813 16.8439L8.65675 13.6877L10.7505 11.5939L12.4692 13.3127L11.938 13.8439C11.1567 14.6252 11.1567 15.9064 11.938 16.6877L13.8755 18.6252C14.5317 19.2814 15.3755 19.6252 16.313 19.6252C17.2505 19.6252 18.0942 19.2814 18.7505 18.6252C19.4067 17.9689 19.7505 17.1252 19.7505 16.1877C19.7505 15.2502 19.4067 14.3752 18.7505 13.7189ZM4.34425 5.87515L2.563 4.5314C2.3755 4.37515 2.34425 4.18765 2.313 4.0939C2.313 4.00015 2.313 3.7814 2.5005 3.62515L3.78175 2.3439C3.938 2.18765 4.09425 2.1564 4.21925 2.1564H4.2505C4.34425 2.1564 4.53175 2.2189 4.688 2.4064L6.03175 4.18765C6.21925 4.43765 6.188 4.75015 5.96925 4.9689L5.1255 5.81265C4.938 6.0314 4.59425 6.06265 4.34425 5.87515ZM7.53175 12.8127C7.438 12.9064 7.3755 13.0002 7.34425 13.1252L6.438 16.4689C6.3755 16.6877 6.21925 16.8439 6.0005 16.9064L3.40675 17.5939C3.188 17.6564 2.96925 17.5939 2.813 17.4377L1.84425 16.4689C1.688 16.3127 1.6255 16.0939 1.688 15.8752L2.3755 13.2814C2.438 13.0627 2.59425 12.9064 2.813 12.8439L6.15675 11.9377C6.28175 11.9064 6.3755 11.8439 6.46925 11.7502L8.71924 9.50015L9.78174 10.5627L7.53175 12.8127ZM17.7505 17.5939C17.3755 17.9689 16.8442 18.1877 16.313 18.1877C15.7817 18.1877 15.2505 17.9689 14.8755 17.5939L12.938 15.6564C12.7192 15.4377 12.7192 15.0314 12.938 14.8127L13.4692 14.2814L13.9067 14.7189C14.0317 14.8439 14.2192 14.9377 14.4067 14.9377C14.5942 14.9377 14.7817 14.8752 14.9067 14.7189C15.188 14.4377 15.188 14.0002 14.9067 13.7189L14.4692 13.2814L15.0005 12.7502C15.1255 12.6252 15.2505 12.5627 15.438 12.5627C15.5942 12.5627 15.7505 12.6252 15.8755 12.7502L17.813 14.6877C18.188 15.0627 18.4067 15.5939 18.4067 16.1252C18.4067 16.6564 18.1567 17.2189 17.7505 17.5939Z",fill:"currentColor"})}),f.jsx("defs",{children:f.jsx("clipPath",{id:"clip0_6318_531",children:f.jsx("rect",{width:"20",height:"20",fill:"white"})})})]})}/** +`+o):r.stack=o}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=bc(this.defaults,n);const{transitional:r,paramsSerializer:a,headers:o}=n;r!==void 0&&G1.assertOptions(r,{silentJSONParsing:Mo.transitional(Mo.boolean),forcedJSONParsing:Mo.transitional(Mo.boolean),clarifyTimeoutError:Mo.transitional(Mo.boolean)},!1),a!=null&&(J.isFunction(a)?n.paramsSerializer={serialize:a}:G1.assertOptions(a,{encode:Mo.function,serialize:Mo.function},!0)),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&J.merge(o.common,o[n.method]);o&&J.forEach(["delete","get","head","post","put","patch","common"],b=>{delete o[b]}),n.headers=fo.concat(i,o);const s=[];let l=!0;this.interceptors.request.forEach(function(y){typeof y.runWhen=="function"&&y.runWhen(n)===!1||(l=l&&y.synchronous,s.unshift(y.fulfilled,y.rejected))});const c=[];this.interceptors.response.forEach(function(y){c.push(y.fulfilled,y.rejected)});let u,d=0,g;if(!l){const b=[s2.bind(this),void 0];for(b.unshift.apply(b,s),b.push.apply(b,c),g=b.length,u=Promise.resolve(n);d{if(!r._listeners)return;let o=r._listeners.length;for(;o-- >0;)r._listeners[o](a);r._listeners=null}),this.promise.then=a=>{let o;const i=new Promise(s=>{r.subscribe(s),o=s}).then(a);return i.cancel=function(){r.unsubscribe(o)},i},t(function(o,i,s){r.reason||(r.reason=new of(o,i,s),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}static source(){let t;return{token:new f_(function(a){t=a}),cancel:t}}}const wZ=f_;function EZ(e){return function(n){return e.apply(null,n)}}function xZ(e){return J.isObject(e)&&e.isAxiosError===!0}const W1={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(W1).forEach(([e,t])=>{W1[t]=e});const kZ=W1;function d6(e){const t=new Vp(e),n=qF(Vp.prototype.request,t);return J.extend(n,Vp.prototype,t,{allOwnKeys:!0}),J.extend(n,t,null,{allOwnKeys:!0}),n.create=function(a){return d6(bc(e,a))},n}const rn=d6(u_);rn.Axios=Vp;rn.CanceledError=of;rn.CancelToken=wZ;rn.isCancel=s6;rn.VERSION=u6;rn.toFormData=Km;rn.AxiosError=st;rn.Cancel=rn.CanceledError;rn.all=function(t){return Promise.all(t)};rn.spread=EZ;rn.isAxiosError=xZ;rn.mergeConfig=bc;rn.AxiosHeaders=fo;rn.formToJSON=e=>i6(J.isHTMLForm(e)?new FormData(e):e);rn.getAdapter=c6.getAdapter;rn.HttpStatusCode=kZ;rn.default=rn;const f6=rn,CZ={baseURL:sY,headers:{"Content-Type":"application/json","Cache-Control":"no-cache"}},cl=f6.create(CZ),_Z=()=>cl,AZ=({children:e})=>{const[t,n]=p.useState(!1),r=Mi(),a=VF();return p.useEffect(()=>{const o=s=>s,i=s=>Promise.reject(s);cl.interceptors.response.use(o,i)},[r,cl]),p.useEffect(()=>{const o=s=>(s.headers.Authorization=a||"",s),i=cl.interceptors.request.use(o);return()=>{cl.interceptors.request.eject(i)}},[a,cl]),p.useEffect(()=>{t||setTimeout(()=>n(!0),10)},[t]),t?e:f.jsx("div",{className:"sr-only",children:"Re-authenticating..."})},TZ="ToolsServiceListTools",p_=({userId:e}={},t)=>[TZ,...t??[{userId:e}]],RZ="SourcesServiceListSources",sf=({userId:e}={},t)=>[RZ,...t??[{userId:e}]],NZ="AgentsServiceListAgents",p6=({userId:e}={},t)=>[NZ,...t??[{userId:e}]],IZ="AgentsServiceGetAgent",$s=({agentId:e,userId:t},n)=>[IZ,...n??[{agentId:e,userId:t}]],OZ="AgentsServiceGetAgentSources",g6=({agentId:e},t)=>[OZ,...t??[{agentId:e}]],DZ="AgentsServiceListAgentArchivalMemory",m6=({after:e,agentId:t,before:n,limit:r,userId:a},o)=>[DZ,...o??[{after:e,agentId:t,before:n,limit:r,userId:a}]],LZ="AgentsServiceListAgentMessages",MZ=({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s},l)=>[LZ,...l??[{agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s}]],PZ="ModelsServiceListModels",$Z=e=>[PZ,...e??[]],FZ="LlmsServiceListEmbeddingModels",jZ=e=>[FZ,...e??[]],zZ="BlocksServiceListMemoryBlocks",lf=({label:e,name:t,templatesOnly:n,userId:r}={},a)=>[zZ,...a??[{label:e,name:t,templatesOnly:n,userId:r}]],UZ="JobsServiceListJobs",BZ=({sourceId:e,userId:t}={},n)=>[UZ,...n??[{sourceId:e,userId:t}]],HZ="JobsServiceListActiveJobs",h6=({userId:e}={},t)=>[HZ,...t??[{userId:e}]];class u2{constructor(){this._fns=[]}eject(t){const n=this._fns.indexOf(t);n!==-1&&(this._fns=[...this._fns.slice(0,n),...this._fns.slice(n+1)])}use(t){this._fns=[...this._fns,t]}}const Ie={CREDENTIALS:"include",ENCODE_PATH:void 0,HEADERS:void 0,PASSWORD:void 0,TOKEN:void 0,USERNAME:void 0,VERSION:"1.0.0",WITH_CREDENTIALS:!1,interceptors:{request:new u2,response:new u2},BASE:""};class d2 extends Error{constructor(t,n,r){super(r),this.name="ApiError",this.url=n.url,this.status=n.status,this.statusText=n.statusText,this.body=n.body,this.request=t}}class VZ extends Error{constructor(t){super(t),this.name="CancelError"}get isCancelled(){return!0}}class qZ{constructor(t){this._isResolved=!1,this._isRejected=!1,this._isCancelled=!1,this.cancelHandlers=[],this.promise=new Promise((n,r)=>{this._resolve=n,this._reject=r;const a=s=>{this._isResolved||this._isRejected||this._isCancelled||(this._isResolved=!0,this._resolve&&this._resolve(s))},o=s=>{this._isResolved||this._isRejected||this._isCancelled||(this._isRejected=!0,this._reject&&this._reject(s))},i=s=>{this._isResolved||this._isRejected||this._isCancelled||this.cancelHandlers.push(s)};return Object.defineProperty(i,"isResolved",{get:()=>this._isResolved}),Object.defineProperty(i,"isRejected",{get:()=>this._isRejected}),Object.defineProperty(i,"isCancelled",{get:()=>this._isCancelled}),t(a,o,i)})}get[Symbol.toStringTag](){return"Cancellable Promise"}then(t,n){return this.promise.then(t,n)}catch(t){return this.promise.catch(t)}finally(t){return this.promise.finally(t)}cancel(){if(!(this._isResolved||this._isRejected||this._isCancelled)){if(this._isCancelled=!0,this.cancelHandlers.length)try{for(const t of this.cancelHandlers)t()}catch(t){console.warn("Cancellation threw an error",t);return}this.cancelHandlers.length=0,this._reject&&this._reject(new VZ("Request aborted"))}}get isCancelled(){return this._isCancelled}}const Zm=e=>typeof e=="string",Rb=e=>Zm(e)&&e!=="",b6=e=>e instanceof Blob,GZ=e=>e instanceof FormData,f2=e=>e>=200&&e<300,WZ=e=>{try{return btoa(e)}catch{return Buffer.from(e).toString("base64")}},KZ=e=>{const t=[],n=(a,o)=>{t.push(`${encodeURIComponent(a)}=${encodeURIComponent(String(o))}`)},r=(a,o)=>{o!=null&&(o instanceof Date?n(a,o.toISOString()):Array.isArray(o)?o.forEach(i=>r(a,i)):typeof o=="object"?Object.entries(o).forEach(([i,s])=>r(`${a}[${i}]`,s)):n(a,o))};return Object.entries(e).forEach(([a,o])=>r(a,o)),t.length?`?${t.join("&")}`:""},YZ=(e,t)=>{const n=e.ENCODE_PATH||encodeURI,r=t.url.replace("{api-version}",e.VERSION).replace(/{(.*?)}/g,(o,i)=>{var s;return(s=t.path)!=null&&s.hasOwnProperty(i)?n(String(t.path[i])):o}),a=e.BASE+r;return t.query?a+KZ(t.query):a},ZZ=e=>{if(e.formData){const t=new FormData,n=(r,a)=>{Zm(a)||b6(a)?t.append(r,a):t.append(r,JSON.stringify(a))};return Object.entries(e.formData).filter(([,r])=>r!=null).forEach(([r,a])=>{Array.isArray(a)?a.forEach(o=>n(r,o)):n(r,a)}),t}},Yf=async(e,t)=>typeof t=="function"?t(e):t,XZ=async(e,t)=>{const[n,r,a,o]=await Promise.all([Yf(t,e.TOKEN),Yf(t,e.USERNAME),Yf(t,e.PASSWORD),Yf(t,e.HEADERS)]),i=Object.entries({Accept:"application/json",...o,...t.headers}).filter(([,s])=>s!=null).reduce((s,[l,c])=>({...s,[l]:String(c)}),{});if(Rb(n)&&(i.Authorization=`Bearer ${n}`),Rb(r)&&Rb(a)){const s=WZ(`${r}:${a}`);i.Authorization=`Basic ${s}`}return t.body!==void 0?t.mediaType?i["Content-Type"]=t.mediaType:b6(t.body)?i["Content-Type"]=t.body.type||"application/octet-stream":Zm(t.body)?i["Content-Type"]="text/plain":GZ(t.body)||(i["Content-Type"]="application/json"):t.formData!==void 0&&t.mediaType&&(i["Content-Type"]=t.mediaType),i},QZ=e=>{if(e.body)return e.body},JZ=async(e,t,n,r,a,o,i,s)=>{const l=new AbortController;let c={data:r??a,headers:o,method:t.method,signal:l.signal,url:n,withCredentials:e.WITH_CREDENTIALS};i(()=>l.abort());for(const u of e.interceptors.request._fns)c=await u(c);try{return await s.request(c)}catch(u){const d=u;if(d.response)return d.response;throw u}},eX=(e,t)=>{if(t){const n=e.headers[t];if(Zm(n))return n}},tX=e=>{if(e.status!==204)return e.data},nX=(e,t)=>{const r={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"Im a teapot",421:"Misdirected Request",422:"Unprocessable Content",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required",...e.errors}[t.status];if(r)throw new d2(e,t,r);if(!t.ok){const a=t.status??"unknown",o=t.statusText??"unknown",i=(()=>{try{return JSON.stringify(t.body,null,2)}catch{return}})();throw new d2(e,t,`Generic Error: status: ${a}; status text: ${o}; body: ${i}`)}},Pe=(e,t,n=f6)=>new qZ(async(r,a,o)=>{try{const i=YZ(e,t),s=ZZ(t),l=QZ(t),c=await XZ(e,t);if(!o.isCancelled){let u=await JZ(e,t,i,l,s,c,o,n);for(const y of e.interceptors.response._fns)u=await y(u);const d=tX(u),g=eX(u,t.responseHeader);let m=d;t.responseTransformer&&f2(u.status)&&(m=await t.responseTransformer(d));const b={url:i,ok:f2(u.status),status:u.status,statusText:u.statusText,body:g??m};nX(t,b),r(b.body)}}catch(i){a(i)}});class g_{static deleteTool(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/tools/{tool_id}",path:{tool_id:t.toolId},errors:{422:"Validation Error"},headers:n})}static getTool(t,n){return Pe(Ie,{method:"GET",url:"/v1/tools/{tool_id}",path:{tool_id:t.toolId},errors:{422:"Validation Error"},headers:n})}static updateTool(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/tools/{tool_id}",path:{tool_id:t.toolId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static getToolIdByName(t,n){return Pe(Ie,{method:"GET",url:"/v1/tools/name/{tool_name}",path:{tool_name:t.toolName},errors:{422:"Validation Error"},headers:n})}static listTools(t={},n){return Pe(Ie,{method:"GET",url:"/v1/tools/",errors:{422:"Validation Error"},headers:n})}static createTool(t,n){return Pe(Ie,{method:"POST",url:"/v1/tools/",query:{update:t.update},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}}class Pc{static getSource(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/{source_id}",path:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static updateSource(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/sources/{source_id}",path:{source_id:t.sourceId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static deleteSource(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/sources/{source_id}",path:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static getSourceIdByName(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/name/{source_name}",path:{source_name:t.sourceName},errors:{422:"Validation Error"},headers:n})}static listSources(t={},n){return Pe(Ie,{method:"GET",url:"/v1/sources/",errors:{422:"Validation Error"},headers:n})}static createSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/",body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static attachAgentToSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/{source_id}/attach",path:{source_id:t.sourceId},query:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static detachAgentFromSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/{source_id}/detach",path:{source_id:t.sourceId},query:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static uploadFileToSource(t,n){return Pe(Ie,{method:"POST",url:"/v1/sources/{source_id}/upload",path:{source_id:t.sourceId},formData:t.formData,mediaType:"multipart/form-data",errors:{422:"Validation Error"},headers:n})}static listSourcePassages(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/{source_id}/passages",path:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static listFilesFromSource(t,n){return Pe(Ie,{method:"GET",url:"/v1/sources/{source_id}/files",path:{source_id:t.sourceId},query:{limit:t.limit,cursor:t.cursor},errors:{422:"Validation Error"},headers:n})}}class Va{static listAgents(t={},n){return Pe(Ie,{method:"GET",url:"/v1/agents/",errors:{422:"Validation Error"},headers:n})}static createAgent(t,n){return Pe(Ie,{method:"POST",url:"/v1/agents/",body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static updateAgent(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/agents/{agent_id}",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static getAgent(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static deleteAgent(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/agents/{agent_id}",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static getAgentSources(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/sources",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static listAgentInContextMessages(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory/messages",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static getAgentMemory(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static updateAgentMemory(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/agents/{agent_id}/memory",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static getAgentRecallMemorySummary(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory/recall",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static getAgentArchivalMemorySummary(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/memory/archival",path:{agent_id:t.agentId},errors:{422:"Validation Error"},headers:n})}static listAgentArchivalMemory(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/archival",path:{agent_id:t.agentId},query:{after:t.after,before:t.before,limit:t.limit},errors:{422:"Validation Error"},headers:n})}static createAgentArchivalMemory(t,n){return Pe(Ie,{method:"POST",url:"/v1/agents/{agent_id}/archival",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static deleteAgentArchivalMemory(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/agents/{agent_id}/archival/{memory_id}",path:{agent_id:t.agentId,memory_id:t.memoryId},errors:{422:"Validation Error"},headers:n})}static listAgentMessages(t,n){return Pe(Ie,{method:"GET",url:"/v1/agents/{agent_id}/messages",path:{agent_id:t.agentId},query:{before:t.before,limit:t.limit,msg_object:t.msgObject,use_assistant_message:t.useAssistantMessage,assistant_message_tool_name:t.assistantMessageFunctionName,assistant_message_tool_kwarg:t.assistantMessageFunctionKwarg},errors:{422:"Validation Error"},headers:n})}static createAgentMessage(t,n){return Pe(Ie,{method:"POST",url:"/v1/agents/{agent_id}/messages",path:{agent_id:t.agentId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static updateAgentMessage(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/agents/{agent_id}/messages/{message_id}",path:{agent_id:t.agentId,message_id:t.messageId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}}class rX{static listModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/",headers:t})}static listEmbeddingModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/embedding",headers:t})}}class aX{static listModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/",headers:t})}static listEmbeddingModels(t){return Pe(Ie,{method:"GET",url:"/v1/models/embedding",headers:t})}}class m_{static listMemoryBlocks(t={},n){return Pe(Ie,{method:"GET",url:"/v1/blocks/",query:{label:t.label,templates_only:t.templatesOnly,name:t.name},errors:{422:"Validation Error"},headers:n})}static createMemoryBlock(t,n){return Pe(Ie,{method:"POST",url:"/v1/blocks/",body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static updateMemoryBlock(t,n){return Pe(Ie,{method:"PATCH",url:"/v1/blocks/{block_id}",path:{block_id:t.blockId},body:t.requestBody,mediaType:"application/json",errors:{422:"Validation Error"},headers:n})}static deleteMemoryBlock(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/blocks/{block_id}",path:{block_id:t.blockId},errors:{422:"Validation Error"},headers:n})}static getMemoryBlock(t,n){return Pe(Ie,{method:"GET",url:"/v1/blocks/{block_id}",path:{block_id:t.blockId},errors:{422:"Validation Error"},headers:n})}}class oX{static listJobs(t={},n){return Pe(Ie,{method:"GET",url:"/v1/jobs/",query:{source_id:t.sourceId},errors:{422:"Validation Error"},headers:n})}static listActiveJobs(t={},n){return Pe(Ie,{method:"GET",url:"/v1/jobs/active",errors:{422:"Validation Error"},headers:n})}static getJob(t,n){return Pe(Ie,{method:"GET",url:"/v1/jobs/{job_id}",path:{job_id:t.jobId},errors:{422:"Validation Error"},headers:n})}static deleteJob(t,n){return Pe(Ie,{method:"DELETE",url:"/v1/jobs/{job_id}",path:{job_id:t.jobId},errors:{422:"Validation Error"},headers:n})}}const Xm=({userId:e}={},t,n)=>Jr({queryKey:p_({userId:e},t),queryFn:()=>g_.listTools({userId:e}),...n}),h_=({userId:e}={},t,n)=>Jr({queryKey:sf({userId:e},t),queryFn:()=>Pc.listSources({userId:e}),...n}),Qm=({userId:e}={},t,n)=>Jr({queryKey:p6({userId:e},t),queryFn:()=>Va.listAgents({userId:e}),...n}),b_=({agentId:e,userId:t},n,r)=>Jr({queryKey:$s({agentId:e,userId:t},n),queryFn:()=>Va.getAgent({agentId:e,userId:t}),...r}),y6=({agentId:e},t,n)=>Jr({queryKey:g6({agentId:e},t),queryFn:()=>Va.getAgentSources({agentId:e}),...n}),v6=({after:e,agentId:t,before:n,limit:r,userId:a},o,i)=>Jr({queryKey:m6({after:e,agentId:t,before:n,limit:r,userId:a},o),queryFn:()=>Va.listAgentArchivalMemory({after:e,agentId:t,before:n,limit:r,userId:a}),...i}),iX=({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s},l,c)=>Jr({queryKey:MZ({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s},l),queryFn:()=>Va.listAgentMessages({agentId:e,assistantMessageFunctionKwarg:t,assistantMessageFunctionName:n,before:r,limit:a,msgObject:o,useAssistantMessage:i,userId:s}),...c}),S6=(e,t)=>Jr({queryKey:$Z(e),queryFn:()=>rX.listModels(),...t}),w6=(e,t)=>Jr({queryKey:jZ(e),queryFn:()=>aX.listEmbeddingModels(),...t}),Ng=({label:e,name:t,templatesOnly:n,userId:r}={},a,o)=>Jr({queryKey:lf({label:e,name:t,templatesOnly:n,userId:r},a),queryFn:()=>m_.listMemoryBlocks({label:e,name:t,templatesOnly:n,userId:r}),...o}),sX=({userId:e}={},t,n)=>Jr({queryKey:h6({userId:e},t),queryFn:()=>oX.listActiveJobs({userId:e}),...n}),lX=e=>gr({mutationFn:({requestBody:t,update:n,userId:r})=>g_.createTool({requestBody:t,update:n,userId:r}),...e}),cX=e=>gr({mutationFn:({requestBody:t,userId:n})=>Pc.createSource({requestBody:t,userId:n}),...e}),E6=e=>gr({mutationFn:({agentId:t,sourceId:n,userId:r})=>Pc.attachAgentToSource({agentId:t,sourceId:n,userId:r}),...e}),x6=e=>gr({mutationFn:({agentId:t,sourceId:n,userId:r})=>Pc.detachAgentFromSource({agentId:t,sourceId:n,userId:r}),...e}),k6=e=>gr({mutationFn:({formData:t,sourceId:n,userId:r})=>Pc.uploadFileToSource({formData:t,sourceId:n,userId:r}),...e}),uX=e=>gr({mutationFn:({requestBody:t,userId:n})=>Va.createAgent({requestBody:t,userId:n}),...e}),dX=e=>gr({mutationFn:({agentId:t,requestBody:n,userId:r})=>Va.createAgentArchivalMemory({agentId:t,requestBody:n,userId:r}),...e}),C6=e=>gr({mutationFn:({requestBody:t,userId:n})=>m_.createMemoryBlock({requestBody:t,userId:n}),...e}),fX=e=>gr({mutationFn:({requestBody:t,toolId:n,userId:r})=>g_.updateTool({requestBody:t,toolId:n,userId:r}),...e}),pX=e=>gr({mutationFn:({requestBody:t,sourceId:n,userId:r})=>Pc.updateSource({requestBody:t,sourceId:n,userId:r}),...e}),cf=e=>gr({mutationFn:({agentId:t,requestBody:n,userId:r})=>Va.updateAgent({agentId:t,requestBody:n,userId:r}),...e}),y_=e=>gr({mutationFn:({blockId:t,requestBody:n})=>m_.updateMemoryBlock({blockId:t,requestBody:n}),...e}),gX=e=>gr({mutationFn:({agentId:t,userId:n})=>Va.deleteAgent({agentId:t,userId:n}),...e}),mX=e=>gr({mutationFn:({agentId:t,memoryId:n,userId:r})=>Va.deleteAgentArchivalMemory({agentId:t,memoryId:n,userId:r}),...e});Ie.BASE="";Ie.HEADERS={"Content-Type":"application/json","Cache-Control":"no-cache"};const hX=({children:e})=>{const[t,n]=p.useState(!1),r=VF(),a=Mi();return p.useEffect(()=>{const o=i=>i;return Ie.interceptors.response.use(o),()=>{Ie.interceptors.response.eject(o)}},[a]),p.useEffect(()=>{const o=i=>(i.headers={...i.headers,Authorization:"Bearer password"},i);return Ie.interceptors.request.use(o),()=>{Ie.interceptors.request.eject(o)}},[r]),p.useEffect(()=>{t||setTimeout(()=>n(!0),10)},[t]),t?e:f.jsx("div",{className:"sr-only",children:"Re-authenticating..."})},yc=ef("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",xs:"text-xs h-7 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10",iconSm:"h-9 w-9",iconXs:"h-7 w-7"}},defaultVariants:{variant:"default",size:"default"}});function p2({isBusy:e,icon:t}){return e?f.jsx(un,{className:"h-4 w-4 animate-spin"}):t||null}const ue=p.forwardRef(({className:e,children:t,label:n,isBusy:r,icon:a,iconPosition:o="left",disabled:i,variant:s,size:l,asChild:c=!1,...u},d)=>{const g=c?$a:"button",m=p.useMemo(()=>i||r,[i,r]),b=p.useMemo(()=>a||o?"flex items-center gap-1":"",[a,o]);return f.jsxs(g,{className:ee(b,yc({variant:s,size:l,className:e})),disabled:m,ref:d,...u,children:[o==="left"&&f.jsx(p2,{isBusy:r??!1,icon:a??null}),f.jsx(Rm,{children:t}),o==="right"&&f.jsx(p2,{isBusy:r??!1,icon:a??null})]})});ue.displayName="Button";const Fs=({children:e,className:t})=>f.jsx("div",{className:ee("h-full w-full overflow-auto",t),children:e});function Zf({children:e,className:t}){return f.jsx("div",{className:ee("flex justify-center text-muted-foreground",t),children:e})}function bX(e){return f.jsxs("svg",{viewBox:"0 0 20 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M5.21875 8.90625H3.84375C3.46875 8.90625 3.125 9.21875 3.125 9.625C3.125 10.0313 3.4375 10.3437 3.84375 10.3437H5.21875C5.59375 10.3437 5.9375 10.0313 5.9375 9.625C5.9375 9.21875 5.59375 8.90625 5.21875 8.90625Z",fill:"currentColor"}),f.jsx("path",{d:"M12.875 8.90625H11.5C11.125 8.90625 10.7812 9.21875 10.7812 9.625C10.7812 10.0313 11.0937 10.3437 11.5 10.3437H12.875C13.25 10.3437 13.5938 10.0313 13.5938 9.625C13.5938 9.21875 13.25 8.90625 12.875 8.90625Z",fill:"currentColor"}),f.jsx("path",{d:"M17.7187 8.09375V3.9375C18.5 3.65625 19.0312 2.90625 19.0312 2.0625C19.0312 0.9375 18.125 0.03125 17 0.03125C15.875 0.03125 14.9687 0.9375 14.9687 2.0625C14.9687 2.9375 15.5312 3.65625 16.2812 3.9375V8.0625H15.9375V7.84375C15.9375 6.59375 14.9062 5.5625 13.6562 5.5625H11.875V4.875C11.875 3.84375 11.0312 3.03125 10.0312 3.03125H9.0625V0.96875C9.0625 0.59375 8.75 0.25 8.34375 0.25C7.9375 0.25 7.625 0.5625 7.625 0.96875V3.03125H6.625C5.59375 3.03125 4.78125 3.875 4.78125 4.875V5.5625H2.8125C1.5625 5.5625 0.53125 6.59375 0.53125 7.84375V13.6875C0.53125 14.9375 1.5625 15.9688 2.8125 15.9688H13.6875C14.9375 15.9688 15.9687 14.9375 15.9687 13.6875V13.4688H17.625C18.6562 13.4688 19.4687 12.625 19.4687 11.625V9.96875C19.4687 8.9375 18.6875 8.15625 17.7187 8.09375ZM17 1.4375C17.3437 1.4375 17.625 1.71875 17.625 2.0625C17.625 2.40625 17.3437 2.6875 17 2.6875C16.6562 2.6875 16.375 2.40625 16.375 2.0625C16.375 1.71875 16.6562 1.4375 17 1.4375ZM6.21875 4.875C6.21875 4.625 6.40625 4.4375 6.65625 4.4375H10.0312C10.2812 4.4375 10.4687 4.625 10.4687 4.875V5.5625H6.21875V4.875ZM14.5312 13.6875C14.5312 14.1562 14.1562 14.5625 13.6562 14.5625H2.8125C2.34375 14.5625 1.9375 14.1875 1.9375 13.6875V7.84375C1.9375 7.375 2.3125 6.96875 2.8125 6.96875H13.6875C14.1562 6.96875 14.5625 7.34375 14.5625 7.84375V13.6875H14.5312ZM18.0625 11.5938C18.0625 11.8438 17.875 12.0312 17.625 12.0312H15.9375V9.46875H17.5937C17.8437 9.46875 18.0312 9.65625 18.0312 9.90625V11.5938H18.0625Z",fill:"currentColor"}),f.jsx("path",{d:"M9.5 11.125C9.125 11.125 8.78125 11.4375 8.78125 11.8437C8.78125 12.0937 8.59375 12.2813 8.34375 12.2813C8.09375 12.2813 7.90625 12.0937 7.90625 11.8437C7.90625 11.4687 7.59375 11.125 7.1875 11.125C6.78125 11.125 6.46875 11.4375 6.46875 11.8437C6.46875 12.875 7.3125 13.6875 8.3125 13.6875C9.3125 13.6875 10.1562 12.8437 10.1562 11.8437C10.1875 11.4375 9.875 11.125 9.5 11.125Z",fill:"currentColor"})]})}function yX(e){return f.jsx("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:f.jsx("path",{d:"M8.00039 11.3998C7.85039 11.3998 7.72539 11.3498 7.60039 11.2498L1.85039 5.5998C1.62539 5.3748 1.62539 5.0248 1.85039 4.7998C2.07539 4.5748 2.42539 4.5748 2.65039 4.7998L8.00039 10.0248L13.3504 4.7498C13.5754 4.5248 13.9254 4.5248 14.1504 4.7498C14.3754 4.9748 14.3754 5.3248 14.1504 5.5498L8.40039 11.1998C8.27539 11.3248 8.15039 11.3998 8.00039 11.3998Z",fill:"currentColor"})})}function vX(e){return f.jsx("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:f.jsx("path",{d:"M13.7504 11.4002C13.6004 11.4002 13.4754 11.3502 13.3504 11.2502L8.00039 5.9752L2.65039 11.2252C2.42539 11.4502 2.07539 11.4502 1.85039 11.2252C1.62539 11.0002 1.62539 10.6502 1.85039 10.4252L7.60039 4.7752C7.82539 4.5502 8.17539 4.5502 8.40039 4.7752L14.1504 10.4252C14.3754 10.6502 14.3754 11.0002 14.1504 11.2252C14.0504 11.3252 13.9004 11.4002 13.7504 11.4002Z",fill:"currentColor"})})}function SX(e){return f.jsxs("svg",{viewBox:"0 0 20 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M10 9.5C12.5938 9.5 14.6875 7.40625 14.6875 4.8125C14.6875 2.21875 12.5938 0.125 10 0.125C7.40625 0.125 5.3125 2.21875 5.3125 4.8125C5.3125 7.40625 7.40625 9.5 10 9.5ZM10 1.53125C11.8125 1.53125 13.2812 3 13.2812 4.8125C13.2812 6.625 11.8125 8.09375 10 8.09375C8.1875 8.09375 6.71875 6.625 6.71875 4.8125C6.71875 3 8.1875 1.53125 10 1.53125Z",fill:"currentColor"}),f.jsx("path",{d:"M19.2191 14.625C16.6566 12.4688 13.4066 11.2812 10.0004 11.2812C6.59412 11.2812 3.34412 12.4688 0.781616 14.625C0.500366 14.875 0.437866 15.3125 0.687866 15.625C0.937866 15.9063 1.37537 15.9688 1.68787 15.7188C4.00037 13.75 6.93787 12.6875 10.0004 12.6875C13.0629 12.6875 16.0004 13.75 18.2816 15.6875C18.4066 15.8125 18.5629 15.8438 18.7504 15.8438C18.9379 15.8438 19.1566 15.75 19.2816 15.5938C19.5316 15.3125 19.5004 14.875 19.2191 14.625Z",fill:"currentColor"})]})}function wX(e){return f.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M17.875 2.9375H11C10.625 2.9375 10.2812 3.0625 10 3.25C9.71875 3.0625 9.375 2.9375 9 2.9375H2.125C1.25 2.9375 0.5625 3.65625 0.5625 4.5V14.6875C0.5625 15.5625 1.28125 16.25 2.125 16.25H9.3125V16.3437C9.3125 16.7187 9.625 17.0625 10.0312 17.0625C10.4062 17.0625 10.75 16.75 10.75 16.3437V16.25H17.9375C18.8125 16.25 19.5 15.5312 19.5 14.6875V4.5C19.4688 3.625 18.75 2.9375 17.875 2.9375ZM2.125 14.875C2.03125 14.875 1.96875 14.8125 1.96875 14.7187V4.5C1.96875 4.40625 2.03125 4.34375 2.125 4.34375H9.03125C9.1875 4.34375 9.3125 4.46875 9.3125 4.625V14.875H2.125ZM18.0625 14.6875C18.0625 14.7812 18 14.8437 17.9062 14.8437H10.7188V4.625C10.7188 4.46875 10.8438 4.34375 11 4.34375H17.9062C18 4.34375 18.0625 4.40625 18.0625 4.5V14.6875Z",fill:"currentColor"}),f.jsx("path",{d:"M4.46875 7.40625H6.78125C7.15625 7.40625 7.5 7.09375 7.5 6.6875C7.5 6.28125 7.1875 5.96875 6.78125 5.96875H4.46875C4.09375 5.96875 3.75 6.28125 3.75 6.6875C3.75 7.09375 4.0625 7.40625 4.46875 7.40625Z",fill:"currentColor"}),f.jsx("path",{d:"M13.125 7.40625H15.4375C15.8125 7.40625 16.1562 7.09375 16.1562 6.6875C16.1562 6.28125 15.8438 5.96875 15.4375 5.96875H13.125C12.75 5.96875 12.4062 6.28125 12.4062 6.6875C12.4062 7.09375 12.75 7.40625 13.125 7.40625Z",fill:"currentColor"}),f.jsx("path",{d:"M15.5 8.5625H13.1875C12.8125 8.5625 12.4688 8.875 12.4688 9.28125C12.4688 9.6875 12.7812 10 13.1875 10H15.5C15.875 10 16.2188 9.6875 16.2188 9.28125C16.2188 8.875 15.875 8.5625 15.5 8.5625Z",fill:"currentColor"}),f.jsx("path",{d:"M6.8125 8.5625H4.5C4.125 8.5625 3.78125 8.875 3.78125 9.28125C3.78125 9.6875 4.09375 10 4.5 10H6.8125C7.1875 10 7.53125 9.6875 7.53125 9.28125C7.53125 8.875 7.21875 8.5625 6.8125 8.5625Z",fill:"currentColor"}),f.jsx("path",{d:"M6.8125 11.3125H4.5C4.125 11.3125 3.78125 11.625 3.78125 12.0312C3.78125 12.4375 4.09375 12.75 4.5 12.75H6.8125C7.1875 12.75 7.53125 12.4375 7.53125 12.0312C7.53125 11.625 7.21875 11.3125 6.8125 11.3125Z",fill:"currentColor"}),f.jsx("path",{d:"M15.5 11.3125H13.1875C12.8125 11.3125 12.4688 11.625 12.4688 12.0312C12.4688 12.4375 12.7812 12.75 13.1875 12.75H15.5C15.875 12.75 16.2188 12.4375 16.2188 12.0312C16.2188 11.625 15.875 11.3125 15.5 11.3125Z",fill:"currentColor"})]})}function EX(e){return f.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("path",{d:"M17.5625 2.28125H2.4375C1.40625 2.28125 0.5625 3.125 0.5625 4.15625V12.875C0.5625 13.9063 1.40625 14.75 2.4375 14.75H6.9375L9.4375 17.5C9.5625 17.6563 9.75 17.7188 9.96875 17.7188C10.1562 17.7188 10.3438 17.625 10.5 17.5L13.0625 14.7188H17.5938C18.625 14.7188 19.4688 13.875 19.4688 12.8438V4.15625C19.4688 3.125 18.5938 2.28125 17.5625 2.28125ZM18.0625 12.8438C18.0625 13.0938 17.8438 13.3125 17.5938 13.3125H12.7188C12.5312 13.3125 12.3438 13.4063 12.1875 13.5313L9.9375 15.9688L7.75 13.5625C7.625 13.4063 7.4375 13.3438 7.21875 13.3438H2.4375C2.1875 13.3438 1.96875 13.125 1.96875 12.875V4.15625C1.96875 3.90625 2.1875 3.6875 2.4375 3.6875H17.5625C17.8125 3.6875 18.0312 3.90625 18.0312 4.15625V12.8438H18.0625Z",fill:"currentColor"}),f.jsx("path",{d:"M5.5625 7.59375C5.15625 7.59375 4.8125 7.9375 4.8125 8.34375C4.8125 8.75 5.15625 9.09375 5.5625 9.09375C5.96875 9.09375 6.3125 8.75 6.3125 8.34375C6.3125 7.9375 6 7.59375 5.5625 7.59375Z",fill:"currentColor"}),f.jsx("path",{d:"M10 7.59375C9.59375 7.59375 9.25 7.9375 9.25 8.34375C9.25 8.75 9.59375 9.09375 10 9.09375C10.4062 9.09375 10.75 8.75 10.75 8.34375C10.75 7.9375 10.4062 7.59375 10 7.59375Z",fill:"currentColor"}),f.jsx("path",{d:"M14.4375 7.59375C14.0313 7.59375 13.6875 7.9375 13.6875 8.34375C13.6875 8.75 14.0313 9.09375 14.4375 9.09375C14.8438 9.09375 15.1875 8.75 15.1875 8.34375C15.1875 7.9375 14.8438 7.59375 14.4375 7.59375Z",fill:"currentColor"})]})}function xX(e){return f.jsx("svg",{viewBox:"0 0 14 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:f.jsx("path",{d:"M7 0.5625C3.34375 0.5625 0.46875 2.28125 0.46875 4.4375V15.5625C0.46875 17.7188 3.40625 19.4375 6.96875 19.4375C10.5625 19.4375 13.5 17.6875 13.5 15.5625V4.4375C13.5312 2.25 10.6562 0.5625 7 0.5625ZM7 1.96875C10 1.96875 12.125 3.28125 12.125 4.4375C12.125 5.625 10.0312 6.90625 7 6.90625C3.96875 6.90625 1.875 5.59375 1.875 4.4375C1.875 3.25 4 1.96875 7 1.96875ZM7 18.0625C4.0625 18.0625 1.90625 16.75 1.90625 15.5938V14.375C3.09375 15.25 4.90625 15.7813 7 15.7813C9.09375 15.7813 10.9375 15.2188 12.125 14.375V15.5938C12.125 16.75 9.9375 18.0625 7 18.0625ZM7 14.375C4 14.375 1.90625 13.125 1.90625 12V10.5625C3.125 11.4375 5.03125 11.9688 7 11.9688C9.0625 11.9688 10.9063 11.4375 12.125 10.5625V12C12.125 13.125 10 14.375 7 14.375ZM11.3125 9.40625C10.3437 10.125 8.75 10.5625 7 10.5625C5.28125 10.5625 3.65625 10.125 2.6875 9.40625C2.3125 9.15625 1.90625 8.71875 1.90625 8.1875V6.875C3.09375 7.75 4.9375 8.3125 7.03125 8.3125C9.125 8.3125 10.9688 7.75 12.1562 6.875V8.1875C12.125 8.6875 11.6875 9.125 11.3125 9.40625Z",fill:"currentColor"})})}function kX(e){return f.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e,children:[f.jsx("g",{clipPath:"url(#clip0_6318_531)",children:f.jsx("path",{d:"M18.7505 13.7189L16.813 11.7814C16.0317 11.0002 14.7505 11.0002 13.9692 11.7814L13.438 12.3127L11.7192 10.5939L13.3442 8.96891L16.5317 8.12515C17.2192 7.93765 17.7817 7.37515 17.9692 6.68765L18.8755 3.3439C18.9692 2.9689 18.7505 2.5939 18.3755 2.4689C18.0005 2.37515 17.6255 2.5939 17.5005 2.9689L16.5942 6.31265C16.5317 6.5314 16.3755 6.68765 16.1567 6.75015L12.813 7.6564C12.688 7.68765 12.5942 7.75015 12.5005 7.8439L10.7505 9.59391L9.68799 8.5314L11.438 6.7814C11.5317 6.68765 11.5942 6.5939 11.6255 6.4689L12.5005 3.12515C12.563 2.9064 12.7192 2.75015 12.938 2.68765L16.2817 1.7814C16.6567 1.68765 16.8755 1.2814 16.7817 0.906405C16.688 0.531405 16.313 0.312655 15.938 0.437655L12.5942 1.31265C11.9067 1.50015 11.3442 2.06265 11.1567 2.75015L10.313 5.9064L8.68799 7.5314L7.063 5.9064C7.688 5.18765 7.7505 4.12515 7.188 3.3439L5.84425 1.56265C5.5005 1.0939 4.96925 0.812655 4.3755 0.781405C3.78175 0.750155 3.21925 0.937655 2.813 1.37515L1.53175 2.6564C1.1255 3.06265 0.906746 3.62515 0.937996 4.2189C0.969246 4.81265 1.2505 5.3439 1.71925 5.68765L3.5005 7.0314C3.84425 7.31265 4.28175 7.43765 4.71925 7.43765C5.21925 7.43765 5.688 7.25015 6.063 6.9064L7.688 8.5314L5.59425 10.6252L2.438 11.4689C1.7505 11.6564 1.188 12.2189 1.0005 12.9064L0.312996 15.5002C0.125496 16.1877 0.312996 16.9377 0.844246 17.4689L1.813 18.4377C2.188 18.8127 2.71925 19.0314 3.2505 19.0314C3.438 19.0314 3.59425 19.0002 3.78175 18.9689L6.3755 18.2814C7.063 18.0939 7.6255 17.5314 7.813 16.8439L8.65675 13.6877L10.7505 11.5939L12.4692 13.3127L11.938 13.8439C11.1567 14.6252 11.1567 15.9064 11.938 16.6877L13.8755 18.6252C14.5317 19.2814 15.3755 19.6252 16.313 19.6252C17.2505 19.6252 18.0942 19.2814 18.7505 18.6252C19.4067 17.9689 19.7505 17.1252 19.7505 16.1877C19.7505 15.2502 19.4067 14.3752 18.7505 13.7189ZM4.34425 5.87515L2.563 4.5314C2.3755 4.37515 2.34425 4.18765 2.313 4.0939C2.313 4.00015 2.313 3.7814 2.5005 3.62515L3.78175 2.3439C3.938 2.18765 4.09425 2.1564 4.21925 2.1564H4.2505C4.34425 2.1564 4.53175 2.2189 4.688 2.4064L6.03175 4.18765C6.21925 4.43765 6.188 4.75015 5.96925 4.9689L5.1255 5.81265C4.938 6.0314 4.59425 6.06265 4.34425 5.87515ZM7.53175 12.8127C7.438 12.9064 7.3755 13.0002 7.34425 13.1252L6.438 16.4689C6.3755 16.6877 6.21925 16.8439 6.0005 16.9064L3.40675 17.5939C3.188 17.6564 2.96925 17.5939 2.813 17.4377L1.84425 16.4689C1.688 16.3127 1.6255 16.0939 1.688 15.8752L2.3755 13.2814C2.438 13.0627 2.59425 12.9064 2.813 12.8439L6.15675 11.9377C6.28175 11.9064 6.3755 11.8439 6.46925 11.7502L8.71924 9.50015L9.78174 10.5627L7.53175 12.8127ZM17.7505 17.5939C17.3755 17.9689 16.8442 18.1877 16.313 18.1877C15.7817 18.1877 15.2505 17.9689 14.8755 17.5939L12.938 15.6564C12.7192 15.4377 12.7192 15.0314 12.938 14.8127L13.4692 14.2814L13.9067 14.7189C14.0317 14.8439 14.2192 14.9377 14.4067 14.9377C14.5942 14.9377 14.7817 14.8752 14.9067 14.7189C15.188 14.4377 15.188 14.0002 14.9067 13.7189L14.4692 13.2814L15.0005 12.7502C15.1255 12.6252 15.2505 12.5627 15.438 12.5627C15.5942 12.5627 15.7505 12.6252 15.8755 12.7502L17.813 14.6877C18.188 15.0627 18.4067 15.5939 18.4067 16.1252C18.4067 16.6564 18.1567 17.2189 17.7505 17.5939Z",fill:"currentColor"})}),f.jsx("defs",{children:f.jsx("clipPath",{id:"clip0_6318_531",children:f.jsx("rect",{width:"20",height:"20",fill:"white"})})})]})}/** * table-core * * Copyright (c) TanStack diff --git a/locust_test.py b/locust_test.py index 445dfbaffb..570e6eef47 100644 --- a/locust_test.py +++ b/locust_test.py @@ -56,7 +56,7 @@ def on_start(self): @task(1) def send_message(self): messages = [MessageCreate(role=MessageRole("user"), text="hello")] - request = LettaRequest(messages=messages, stream_steps=False, stream_tokens=False, return_message_object=False) + request = LettaRequest(messages=messages) with self.client.post( f"/v1/agents/{self.agent_id}/messages", json=request.model_dump(), headers=self.client.headers, catch_response=True From f06ed5d53f4c95284d262462469bf00ad7af0bf1 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Tue, 26 Nov 2024 18:04:57 -0800 Subject: [PATCH 02/11] Add endpoint --- letta/server/rest_api/routers/v1/agents.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index 127e4fe952..896e28887a 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -564,8 +564,10 @@ async def send_message_to_agent( # TODO: cleanup this logic llm_config = letta_agent.agent_state.llm_config if llm_config.model_endpoint_type != "openai" or "inference.memgpt.ai" in llm_config.model_endpoint: - print("Warning: token streaming is only supported for OpenAI models. Setting to False.") - stream_tokens = False + raise HTTPException( + status_code=400, + detail=f"Token streaming is only supported for models with type 'openai': agent has endpoint type {llm_config.model_endpoint_type}.", + ) # Create a new interface per request letta_agent.interface = StreamingServerInterface() From 278c961d1c1236074f99519270cd3068dbeca083 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 11:09:32 -0800 Subject: [PATCH 03/11] Factor out legacy fields --- examples/swarm/swarm.py | 4 +- letta/client/client.py | 39 ++-- letta/schemas/letta_request.py | 4 +- letta/server/rest_api/interface.py | 6 +- .../routers/openai/assistants/threads.py | 1 - .../chat_completions/chat_completions.py | 2 - letta/server/rest_api/routers/v1/agents.py | 25 +- letta/server/server.py | 36 +-- tests/test_client_legacy.py | 24 +- tests/test_server.py | 214 +----------------- 10 files changed, 36 insertions(+), 319 deletions(-) diff --git a/examples/swarm/swarm.py b/examples/swarm/swarm.py index 053115b110..ef080806d2 100644 --- a/examples/swarm/swarm.py +++ b/examples/swarm/swarm.py @@ -76,9 +76,9 @@ def run(self, agent_name: str, message: str): # print(self.client.get_agent(agent_id).tools) # TODO: implement with sending multiple messages if len(history) == 0: - response = self.client.send_message(agent_id=agent_id, message=message, role="user", include_full_message=True) + response = self.client.send_message(agent_id=agent_id, message=message, role="user") else: - response = self.client.send_messages(agent_id=agent_id, messages=history, include_full_message=True) + response = self.client.send_messages(agent_id=agent_id, messages=history) # update history history += response.messages diff --git a/letta/client/client.py b/letta/client/client.py index ce28faee12..e950cb9405 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -154,11 +154,10 @@ def send_message( stream: Optional[bool] = False, stream_steps: bool = False, stream_tokens: bool = False, - include_full_message: Optional[bool] = False, ) -> LettaResponse: raise NotImplementedError - def user_message(self, agent_id: str, message: str, include_full_message: Optional[bool] = False) -> LettaResponse: + def user_message(self, agent_id: str, message: str) -> LettaResponse: raise NotImplementedError def create_human(self, name: str, text: str) -> Human: @@ -839,7 +838,7 @@ def get_in_context_messages(self, agent_id: str) -> List[Message]: # agent interactions - def user_message(self, agent_id: str, message: str, include_full_message: Optional[bool] = False) -> LettaResponse: + def user_message(self, agent_id: str, message: str) -> LettaResponse: """ Send a message to an agent as a user @@ -850,7 +849,7 @@ def user_message(self, agent_id: str, message: str, include_full_message: Option Returns: response (LettaResponse): Response from the agent """ - return self.send_message(agent_id, message, role="user", include_full_message=include_full_message) + return self.send_message(agent_id, message, role="user") def save(self): raise NotImplementedError @@ -937,13 +936,13 @@ def get_messages( def send_message( self, - agent_id: str, message: str, role: str, + agent_id: Optional[str] = None, name: Optional[str] = None, + stream: Optional[bool] = False, stream_steps: bool = False, stream_tokens: bool = False, - include_full_message: bool = False, ) -> Union[LettaResponse, Generator[LettaStreamingResponse, None, None]]: """ Send a message to an agent @@ -968,8 +967,7 @@ def send_message( if stream_tokens or stream_steps: from letta.client.streaming import _sse_post - request.return_message_object = False - return _sse_post(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/messages", request.model_dump(), self.headers) + return _sse_post(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/messages/stream", request.model_dump(), self.headers) else: response = requests.post( f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/messages", json=request.model_dump(), headers=self.headers @@ -2245,7 +2243,6 @@ def send_messages( self, agent_id: str, messages: List[Union[Message | MessageCreate]], - include_full_message: Optional[bool] = False, ): """ Send pre-packed messages to an agent. @@ -2266,12 +2263,9 @@ def send_messages( # format messages messages = self.interface.to_list() - if include_full_message: - letta_messages = messages - else: - letta_messages = [] - for m in messages: - letta_messages += m.to_letta_message() + letta_messages = [] + for m in messages: + letta_messages += m.to_letta_message() return LettaResponse(messages=letta_messages, usage=usage) @@ -2284,7 +2278,6 @@ def send_message( agent_name: Optional[str] = None, stream_steps: bool = False, stream_tokens: bool = False, - include_full_message: Optional[bool] = False, ) -> LettaResponse: """ Send a message to an agent @@ -2333,16 +2326,13 @@ def send_message( # format messages messages = self.interface.to_list() - if include_full_message: - letta_messages = messages - else: - letta_messages = [] - for m in messages: - letta_messages += m.to_letta_message() + letta_messages = [] + for m in messages: + letta_messages += m.to_letta_message() return LettaResponse(messages=letta_messages, usage=usage) - def user_message(self, agent_id: str, message: str, include_full_message: Optional[bool] = False) -> LettaResponse: + def user_message(self, agent_id: str, message: str) -> LettaResponse: """ Send a message to an agent as a user @@ -2354,7 +2344,7 @@ def user_message(self, agent_id: str, message: str, include_full_message: Option response (LettaResponse): Response from the agent """ self.interface.clear() - return self.send_message(role="user", agent_id=agent_id, message=message, include_full_message=include_full_message) + return self.send_message(role="user", agent_id=agent_id, message=message) def run_command(self, agent_id: str, command: str) -> LettaResponse: """ @@ -2946,7 +2936,6 @@ def get_messages( after=after, limit=limit, reverse=True, - return_message_object=True, ) def list_blocks(self, label: Optional[str] = None, templates_only: Optional[bool] = True) -> List[Block]: diff --git a/letta/schemas/letta_request.py b/letta/schemas/letta_request.py index c4a66fbb59..11ef8bad49 100644 --- a/letta/schemas/letta_request.py +++ b/letta/schemas/letta_request.py @@ -13,11 +13,11 @@ class LettaRequest(BaseModel): assistant_message_tool_name: str = Field( default=DEFAULT_MESSAGE_TOOL, - description="[Only applicable if use_assistant_message is True] The name of the designated message tool.", + description="The name of the designated message tool.", ) assistant_message_tool_kwarg: str = Field( default=DEFAULT_MESSAGE_TOOL_KWARG, - description="[Only applicable if use_assistant_message is True] The name of the message argument in the designated message tool.", + description="The name of the message argument in the designated message tool.", ) diff --git a/letta/server/rest_api/interface.py b/letta/server/rest_api/interface.py index 21b4650c6b..11843250c7 100644 --- a/letta/server/rest_api/interface.py +++ b/letta/server/rest_api/interface.py @@ -271,7 +271,6 @@ def __init__( self, multi_step=True, # Related to if we want to try and pass back the AssistantMessage as a special case function - use_assistant_message=False, assistant_message_tool_name=DEFAULT_MESSAGE_TOOL, assistant_message_tool_kwarg=DEFAULT_MESSAGE_TOOL_KWARG, # Related to if we expect inner_thoughts to be in the kwargs @@ -300,7 +299,7 @@ def __init__( self.multi_step_gen_indicator = MessageStreamStatus.done_generation # Support for AssistantMessage - self.use_assistant_message = use_assistant_message + self.use_assistant_message = False # TODO: Remove this self.assistant_message_tool_name = assistant_message_tool_name self.assistant_message_tool_kwarg = assistant_message_tool_kwarg @@ -497,9 +496,6 @@ def _process_chunk_to_letta_style( ) elif self.inner_thoughts_in_kwargs and tool_call.function: - if self.use_assistant_message: - raise NotImplementedError("inner_thoughts_in_kwargs with use_assistant_message not yet supported") - processed_chunk = None if tool_call.function.name: diff --git a/letta/server/rest_api/routers/openai/assistants/threads.py b/letta/server/rest_api/routers/openai/assistants/threads.py index af63e7b799..a8a072e5b1 100644 --- a/letta/server/rest_api/routers/openai/assistants/threads.py +++ b/letta/server/rest_api/routers/openai/assistants/threads.py @@ -161,7 +161,6 @@ def list_messages( before=before_uuid, order_by="created_at", reverse=reverse, - return_message_object=True, ) assert isinstance(json_messages, List) assert all([isinstance(message, Message) for message in json_messages]) diff --git a/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py b/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py index 3c1afc3938..4703104228 100644 --- a/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py +++ b/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py @@ -68,7 +68,6 @@ async def create_chat_completion( stream_tokens=True, # Turn on ChatCompletion mode (eg remaps send_message to content) chat_completion_mode=True, - return_message_object=False, ) else: @@ -86,7 +85,6 @@ async def create_chat_completion( # Turn streaming OFF stream_steps=False, stream_tokens=False, - return_message_object=False, ) # print(response_messages) diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index 896e28887a..f1f43e8874 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -31,7 +31,6 @@ from letta.server.rest_api.interface import StreamingServerInterface from letta.server.rest_api.utils import get_letta_server, sse_async_generator from letta.server.server import SyncServer -from letta.utils import deduplicate # These can be forward refs, but because Fastapi needs them at runtime the must be imported normally @@ -408,11 +407,11 @@ def get_agent_messages( ), assistant_message_tool_name: str = Query( DEFAULT_MESSAGE_TOOL, - description="[Only applicable if use_assistant_message is True] The name of the designated message tool.", + description="The name of the designated message tool.", ), assistant_message_tool_kwarg: str = Query( DEFAULT_MESSAGE_TOOL_KWARG, - description="[Only applicable if use_assistant_message is True] The name of the message argument in the designated message tool.", + description="The name of the message argument in the designated message tool.", ), user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present ): @@ -427,8 +426,6 @@ def get_agent_messages( before=before, limit=limit, reverse=True, - return_message_object=msg_object, - use_assistant_message=use_assistant_message, assistant_message_tool_name=assistant_message_tool_name, assistant_message_tool_kwarg=assistant_message_tool_kwarg, ) @@ -474,7 +471,6 @@ async def send_message( messages=request.messages, stream_steps=False, stream_tokens=False, - return_message_object=False, # Support for AssistantMessage assistant_message_tool_name=request.assistant_message_tool_name, assistant_message_tool_kwarg=request.assistant_message_tool_kwarg, @@ -517,7 +513,6 @@ async def send_message_streaming( messages=request.messages, stream_steps=True, stream_tokens=request.stream_tokens, - return_message_object=False, # Support for AssistantMessage assistant_message_tool_name=request.assistant_message_tool_name, assistant_message_tool_kwarg=request.assistant_message_tool_kwarg, @@ -535,11 +530,9 @@ async def send_message_to_agent( stream_steps: bool, stream_tokens: bool, # related to whether or not we return `LettaMessage`s or `Message`s - return_message_object: bool, # Should be True for Python Client, False for REST API chat_completion_mode: bool = False, timestamp: Optional[datetime] = None, # Support for AssistantMessage - use_assistant_message: bool = False, assistant_message_tool_name: str = DEFAULT_MESSAGE_TOOL, assistant_message_tool_kwarg: str = DEFAULT_MESSAGE_TOOL_KWARG, ) -> Union[StreamingResponse, LettaResponse]: @@ -584,7 +577,6 @@ async def send_message_to_agent( # streaming_interface.function_call_legacy_mode = stream # Allow AssistantMessage is desired by client - streaming_interface.use_assistant_message = use_assistant_message streaming_interface.assistant_message_tool_name = assistant_message_tool_name streaming_interface.assistant_message_tool_kwarg = assistant_message_tool_kwarg @@ -605,10 +597,6 @@ async def send_message_to_agent( ) if stream_steps: - if return_message_object: - # TODO implement returning `Message`s in a stream, not just `LettaMessage` format - raise NotImplementedError - # return a stream return StreamingResponse( sse_async_generator( @@ -638,14 +626,7 @@ async def send_message_to_agent( # If we want to convert these to Message, we can use the attached IDs # NOTE: we will need to de-duplicate the Messsage IDs though (since Assistant->Inner+Func_Call) # TODO: eventually update the interface to use `Message` and `MessageChunk` (new) inside the deque instead - if return_message_object: - message_ids = [m.id for m in filtered_stream] - message_ids = deduplicate(message_ids) - message_objs = [server.get_agent_message(agent_id=agent_id, message_id=m_id) for m_id in message_ids] - message_objs = [m for m in message_objs if m is not None] - return LettaResponse(messages=message_objs, usage=usage) - else: - return LettaResponse(messages=filtered_stream, usage=usage) + return LettaResponse(messages=filtered_stream, usage=usage) except HTTPException: raise diff --git a/letta/server/server.py b/letta/server/server.py index 4d6d944d6d..cc6e18a597 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -1220,7 +1220,6 @@ def get_agent_messages( agent_id: str, start: int, count: int, - return_message_object: bool = True, ) -> Union[List[Message], List[LettaMessage]]: """Paginated query of all messages in agent message queue""" # Get the agent object (loaded in memory) @@ -1265,9 +1264,6 @@ def get_agent_messages( # for d in json_messages: # d["in_context"] = True if str(d["id"]) in in_context_message_ids else False - if not return_message_object: - messages = [msg for m in messages for msg in m.to_letta_message()] - return messages def get_agent_archival(self, user_id: str, agent_id: str, start: int, count: int) -> List[Passage]: @@ -1353,8 +1349,6 @@ def get_agent_recall_cursor( order_by: Optional[str] = "created_at", order: Optional[str] = "asc", reverse: Optional[bool] = False, - return_message_object: bool = True, - use_assistant_message: bool = False, assistant_message_tool_name: str = constants.DEFAULT_MESSAGE_TOOL, assistant_message_tool_kwarg: str = constants.DEFAULT_MESSAGE_TOOL_KWARG, ) -> Union[List[Message], List[LettaMessage]]: @@ -1373,28 +1367,14 @@ def get_agent_recall_cursor( assert all(isinstance(m, Message) for m in records) - if not return_message_object: - # If we're GETing messages in reverse, we need to reverse the inner list (generated by to_letta_message) - if reverse: - records = [ - msg - for m in records - for msg in m.to_letta_message( - assistant_message=use_assistant_message, - assistant_message_tool_name=assistant_message_tool_name, - assistant_message_tool_kwarg=assistant_message_tool_kwarg, - )[::-1] - ] - else: - records = [ - msg - for m in records - for msg in m.to_letta_message( - assistant_message=use_assistant_message, - assistant_message_tool_name=assistant_message_tool_name, - assistant_message_tool_kwarg=assistant_message_tool_kwarg, - ) - ] + records = [ + msg + for m in records + for msg in m.to_letta_message( + assistant_message_tool_name=assistant_message_tool_name, + assistant_message_tool_kwarg=assistant_message_tool_kwarg, + ) + ] return records diff --git a/tests/test_client_legacy.py b/tests/test_client_legacy.py index 0b6f3821ac..c2c92e6474 100644 --- a/tests/test_client_legacy.py +++ b/tests/test_client_legacy.py @@ -143,26 +143,10 @@ def test_memory(client: Union[LocalClient, RESTClient], agent: AgentState): def test_agent_interactions(client: Union[LocalClient, RESTClient], agent: AgentState): - # _reset_config() - - message = "Hello, agent!" - print("Sending message", message) - response = client.user_message(agent_id=agent.id, message=message, include_full_message=True) - # Check the types coming back - assert all([isinstance(m, Message) for m in response.messages]), "All messages should be Message" - - print("Response", response) - assert isinstance(response.usage, LettaUsageStatistics) - assert response.usage.step_count == 1 - assert response.usage.total_tokens > 0 - assert response.usage.completion_tokens > 0 - assert isinstance(response.messages[0], Message) - print(response.messages) - - # test that it also works with LettaMessage + # test that it is a LettaMessage message = "Hello again, agent!" print("Sending message", message) - response = client.user_message(agent_id=agent.id, message=message, include_full_message=False) + response = client.user_message(agent_id=agent.id, message=message) assert all([isinstance(m, LettaMessage) for m in response.messages]), "All messages should be LettaMessages" # We should also check that the types were cast properly @@ -528,10 +512,10 @@ def test_message_update(client: Union[LocalClient, RESTClient], agent: AgentStat """Test that we can update the details of a message""" # create a message - message_response = client.send_message(agent_id=agent.id, message="Test message", role="user", include_full_message=True) + message_response = client.send_message(agent_id=agent.id, message="Test message", role="user") print("Messages=", message_response) assert isinstance(message_response, LettaResponse) - assert isinstance(message_response.messages[-1], Message) + assert isinstance(message_response.messages[-1], FunctionReturn) message = message_response.messages[-1] new_text = "This exact string would never show up in the message???" diff --git a/tests/test_server.py b/tests/test_server.py index c48876063b..b56ff7e311 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,11 +1,10 @@ import json import uuid -import warnings import pytest import letta.utils as utils -from letta.constants import BASE_TOOLS, DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG +from letta.constants import BASE_TOOLS from letta.schemas.enums import MessageRole from letta.schemas.user import User @@ -15,18 +14,8 @@ from letta.config import LettaConfig from letta.schemas.agent import CreateAgent from letta.schemas.embedding_config import EmbeddingConfig -from letta.schemas.letta_message import ( - AssistantMessage, - FunctionCallMessage, - FunctionReturn, - InternalMonologue, - LettaMessage, - SystemMessage, - UserMessage, -) from letta.schemas.llm_config import LLMConfig from letta.schemas.memory import ChatMemory -from letta.schemas.message import Message from letta.schemas.source import Source from letta.server.server import SyncServer @@ -174,11 +163,7 @@ def test_get_recall_memory(server, org_id, user_id, agent_id): messages_2[-1].id messages_3 = server.get_agent_recall_cursor(user_id=user_id, agent_id=agent_id, limit=1000) messages_3[-1].id - # [m["id"] for m in messages_3] - # [m["id"] for m in messages_2] - timestamps = [m.created_at for m in messages_3] - print("timestamps", timestamps) - assert messages_3[-1].created_at >= messages_3[0].created_at + assert messages_3[-1].date >= messages_3[0].date assert len(messages_3) == len(messages_1) + len(messages_2) messages_4 = server.get_agent_recall_cursor(user_id=user_id, agent_id=agent_id, reverse=True, before=cursor1) assert len(messages_4) == 1 @@ -248,201 +233,6 @@ def test_get_archival_memory(server, user_id, agent_id): assert len(passage_none) == 0 -def _test_get_messages_letta_format( - server, - user_id, - agent_id, - reverse=False, - # flag that determines whether or not to use AssistantMessage, or just FunctionCallMessage universally - use_assistant_message=False, -): - """Reverse is off by default, the GET goes in chronological order""" - - messages = server.get_agent_recall_cursor( - user_id=user_id, - agent_id=agent_id, - limit=1000, - reverse=reverse, - return_message_object=True, - use_assistant_message=use_assistant_message, - ) - # messages = server.get_agent_messages(agent_id=agent_id, start=0, count=1000) - assert all(isinstance(m, Message) for m in messages) - - letta_messages = server.get_agent_recall_cursor( - user_id=user_id, - agent_id=agent_id, - limit=1000, - reverse=reverse, - return_message_object=False, - use_assistant_message=use_assistant_message, - ) - # letta_messages = server.get_agent_messages(agent_id=agent_id, start=0, count=1000, return_message_object=False) - assert all(isinstance(m, LettaMessage) for m in letta_messages) - - # Loop through `messages` while also looping through `letta_messages` - # Each message in `messages` should have 1+ corresponding messages in `letta_messages` - # If role of message (in `messages`) is `assistant`, - # then there should be two messages in `letta_messages`, one which is type InternalMonologue and one which is type FunctionCallMessage. - # If role of message (in `messages`) is `user`, then there should be one message in `letta_messages` which is type UserMessage. - # If role of message (in `messages`) is `system`, then there should be one message in `letta_messages` which is type SystemMessage. - # If role of message (in `messages`) is `tool`, then there should be one message in `letta_messages` which is type FunctionReturn. - - print("MESSAGES (obj):") - for i, m in enumerate(messages): - # print(m) - print(f"{i}: {m.role}, {m.text[:50]}...") - # print(m.role) - - print("MEMGPT_MESSAGES:") - for i, m in enumerate(letta_messages): - print(f"{i}: {type(m)} ...{str(m)[-50:]}") - - # Collect system messages and their texts - system_messages = [m for m in messages if m.role == MessageRole.system] - system_texts = [m.text for m in system_messages] - - # If there are multiple system messages, print the diff - if len(system_messages) > 1: - print("Differences between system messages:") - for i in range(len(system_texts) - 1): - for j in range(i + 1, len(system_texts)): - import difflib - - diff = difflib.unified_diff( - system_texts[i].splitlines(), - system_texts[j].splitlines(), - fromfile=f"System Message {i+1}", - tofile=f"System Message {j+1}", - lineterm="", - ) - print("\n".join(diff)) - else: - print("There is only one or no system message.") - - letta_message_index = 0 - for i, message in enumerate(messages): - assert isinstance(message, Message) - - print(f"\n\nmessage {i}: {message.role}, {message.text[:50] if message.text else 'null'}") - while letta_message_index < len(letta_messages): - letta_message = letta_messages[letta_message_index] - print(f"letta_message {letta_message_index}: {str(letta_message)[:50]}") - - if message.role == MessageRole.assistant: - print(f"i={i}, M=assistant, MM={type(letta_message)}") - - # If reverse, function call will come first - if reverse: - - # If there are multiple tool calls, we should have multiple back to back FunctionCallMessages - if message.tool_calls is not None: - for tool_call in message.tool_calls: - - # Try to parse the tool call args - try: - func_args = json.loads(tool_call.function.arguments) - except: - warnings.warn(f"Function call arguments are not valid JSON: {tool_call.function.arguments}") - func_args = {} - - # If assistant_message is True, we expect FunctionCallMessage to be AssistantMessage if the tool call is the assistant message tool - if ( - use_assistant_message - and tool_call.function.name == DEFAULT_MESSAGE_TOOL - and DEFAULT_MESSAGE_TOOL_KWARG in func_args - ): - assert isinstance(letta_message, AssistantMessage) - assert func_args[DEFAULT_MESSAGE_TOOL_KWARG] == letta_message.assistant_message - letta_message_index += 1 - letta_message = letta_messages[letta_message_index] - - # Otherwise, we expect even a "send_message" tool call to be a FunctionCallMessage - else: - assert isinstance(letta_message, FunctionCallMessage) - letta_message_index += 1 - letta_message = letta_messages[letta_message_index] - - if message.text is not None: - assert isinstance(letta_message, InternalMonologue) - letta_message_index += 1 - letta_message = letta_messages[letta_message_index] - else: - # If there's no inner thoughts then there needs to be a tool call - assert message.tool_calls is not None - - else: - - if message.text is not None: - assert isinstance(letta_message, InternalMonologue) - letta_message_index += 1 - letta_message = letta_messages[letta_message_index] - else: - # If there's no inner thoughts then there needs to be a tool call - assert message.tool_calls is not None - - # If there are multiple tool calls, we should have multiple back to back FunctionCallMessages - if message.tool_calls is not None: - for tool_call in message.tool_calls: - - # Try to parse the tool call args - try: - func_args = json.loads(tool_call.function.arguments) - except: - warnings.warn(f"Function call arguments are not valid JSON: {tool_call.function.arguments}") - func_args = {} - - # If assistant_message is True, we expect FunctionCallMessage to be AssistantMessage if the tool call is the assistant message tool - if ( - use_assistant_message - and tool_call.function.name == DEFAULT_MESSAGE_TOOL - and DEFAULT_MESSAGE_TOOL_KWARG in func_args - ): - assert isinstance(letta_message, AssistantMessage) - assert func_args[DEFAULT_MESSAGE_TOOL_KWARG] == letta_message.assistant_message - letta_message_index += 1 - letta_message = letta_messages[letta_message_index] - - # Otherwise, we expect even a "send_message" tool call to be a FunctionCallMessage - else: - assert isinstance(letta_message, FunctionCallMessage) - assert tool_call.function.name == letta_message.function_call.name - assert tool_call.function.arguments == letta_message.function_call.arguments - letta_message_index += 1 - letta_message = letta_messages[letta_message_index] - - elif message.role == MessageRole.user: - print(f"i={i}, M=user, MM={type(letta_message)}") - assert isinstance(letta_message, UserMessage) - assert message.text == letta_message.message - letta_message_index += 1 - - elif message.role == MessageRole.system: - print(f"i={i}, M=system, MM={type(letta_message)}") - assert isinstance(letta_message, SystemMessage) - assert message.text == letta_message.message - letta_message_index += 1 - - elif message.role == MessageRole.tool: - print(f"i={i}, M=tool, MM={type(letta_message)}") - assert isinstance(letta_message, FunctionReturn) - # Check the the value in `text` is the same - assert message.text == letta_message.function_return - letta_message_index += 1 - - else: - raise ValueError(f"Unexpected message role: {message.role}") - - # Move to the next message in the original messages list - break - - -def test_get_messages_letta_format(server, user_id, agent_id): - for reverse in [False, True]: - for assistant_message in [False, True]: - _test_get_messages_letta_format(server, user_id, agent_id, reverse=reverse, use_assistant_message=assistant_message) - - def test_agent_rethink_rewrite_retry(server, user_id, agent_id): """Test the /rethink, /rewrite, and /retry commands in the CLI From 0a81276c0cf61099efd8510131c804b743f85c55 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 11:18:36 -0800 Subject: [PATCH 04/11] Fix client tests --- letta/client/client.py | 2 +- tests/test_client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index e950cb9405..da23a6e3a2 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -849,7 +849,7 @@ def user_message(self, agent_id: str, message: str) -> LettaResponse: Returns: response (LettaResponse): Response from the agent """ - return self.send_message(agent_id, message, role="user") + return self.send_message(agent_id=agent_id, message=message, role="user") def save(self): raise NotImplementedError diff --git a/tests/test_client.py b/tests/test_client.py index f9b368e207..710d74aab2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -318,7 +318,7 @@ async def test_send_message_parallel(client: Union[LocalClient, RESTClient], age # Define a coroutine for sending a message using asyncio.to_thread for synchronous calls async def send_message_task(message: str): - response = await asyncio.to_thread(client.send_message, agent.id, message, role="user") + response = await asyncio.to_thread(client.send_message, agent_id=agent.id, message=message, role="user") assert response, f"Sending message '{message}' failed" return response From a8cbd306b65567d90d6c3e372cb7ab94f06139db Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 11:24:07 -0800 Subject: [PATCH 05/11] Fix client test --- letta/client/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index da23a6e3a2..071b073f9c 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -25,6 +25,7 @@ from letta.schemas.enums import JobStatus, MessageRole from letta.schemas.file import FileMetadata from letta.schemas.job import Job +from letta.schemas.letta_message import LettaMessage from letta.schemas.letta_request import LettaRequest from letta.schemas.letta_response import LettaResponse, LettaStreamingResponse from letta.schemas.llm_config import LLMConfig @@ -914,7 +915,7 @@ def delete_archival_memory(self, agent_id: str, memory_id: str): def get_messages( self, agent_id: str, before: Optional[str] = None, after: Optional[str] = None, limit: Optional[int] = 1000 - ) -> List[Message]: + ) -> List[LettaMessage]: """ Get messages from an agent with pagination. @@ -925,14 +926,14 @@ def get_messages( limit (int): Limit number of messages Returns: - messages (List[Message]): List of messages + messages (List[LettaMessage]): List of messages """ params = {"before": before, "after": after, "limit": limit, "msg_object": True} response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/messages", params=params, headers=self.headers) if response.status_code != 200: raise ValueError(f"Failed to get messages: {response.text}") - return [Message(**message) for message in response.json()] + return [LettaMessage(**message) for message in response.json()] def send_message( self, From 7be5485e29cc8cfad96f5f76cee76d3135ce98b5 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 11:34:03 -0800 Subject: [PATCH 06/11] Fix http error bug --- letta/server/rest_api/routers/v1/agents.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index f1f43e8874..39cde42a2f 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -556,10 +556,10 @@ async def send_message_to_agent( # Disable token streaming if not OpenAI # TODO: cleanup this logic llm_config = letta_agent.agent_state.llm_config - if llm_config.model_endpoint_type != "openai" or "inference.memgpt.ai" in llm_config.model_endpoint: + if stream_steps and (llm_config.model_endpoint_type != "openai" or "inference.memgpt.ai" in llm_config.model_endpoint): raise HTTPException( status_code=400, - detail=f"Token streaming is only supported for models with type 'openai': agent has endpoint type {llm_config.model_endpoint_type}.", + detail=f"Token streaming is only supported for models with type 'openai' or `inference.memgpt.ai` in the model_endpoint: agent has endpoint type {llm_config.model_endpoint_type} and {llm_config.model_endpoint}.", ) # Create a new interface per request From cdd7963539f799f0c25095039eb00dab2663d942 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 11:55:28 -0800 Subject: [PATCH 07/11] Restore get message Message object functionality --- letta/client/client.py | 7 +- letta/server/rest_api/routers/v1/agents.py | 5 +- letta/server/server.py | 22 ++- tests/test_server.py | 172 +++++++++++++++++++++ 4 files changed, 190 insertions(+), 16 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index 071b073f9c..da23a6e3a2 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -25,7 +25,6 @@ from letta.schemas.enums import JobStatus, MessageRole from letta.schemas.file import FileMetadata from letta.schemas.job import Job -from letta.schemas.letta_message import LettaMessage from letta.schemas.letta_request import LettaRequest from letta.schemas.letta_response import LettaResponse, LettaStreamingResponse from letta.schemas.llm_config import LLMConfig @@ -915,7 +914,7 @@ def delete_archival_memory(self, agent_id: str, memory_id: str): def get_messages( self, agent_id: str, before: Optional[str] = None, after: Optional[str] = None, limit: Optional[int] = 1000 - ) -> List[LettaMessage]: + ) -> List[Message]: """ Get messages from an agent with pagination. @@ -926,14 +925,14 @@ def get_messages( limit (int): Limit number of messages Returns: - messages (List[LettaMessage]): List of messages + messages (List[Message]): List of messages """ params = {"before": before, "after": after, "limit": limit, "msg_object": True} response = requests.get(f"{self.base_url}/{self.api_prefix}/agents/{agent_id}/messages", params=params, headers=self.headers) if response.status_code != 200: raise ValueError(f"Failed to get messages: {response.text}") - return [LettaMessage(**message) for message in response.json()] + return [Message(**message) for message in response.json()] def send_message( self, diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index 39cde42a2f..470c456bbc 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -401,10 +401,6 @@ def get_agent_messages( limit: int = Query(10, description="Maximum number of messages to retrieve."), msg_object: bool = Query(False, description="If true, returns Message objects. If false, return LettaMessage objects."), # Flags to support the use of AssistantMessage message types - use_assistant_message: bool = Query( - False, - description="[Only applicable if msg_object is False] If true, returns AssistantMessage objects when the agent calls a designated message tool. If false, return FunctionCallMessage objects for all tool calls.", - ), assistant_message_tool_name: str = Query( DEFAULT_MESSAGE_TOOL, description="The name of the designated message tool.", @@ -426,6 +422,7 @@ def get_agent_messages( before=before, limit=limit, reverse=True, + return_message_object=msg_object, assistant_message_tool_name=assistant_message_tool_name, assistant_message_tool_kwarg=assistant_message_tool_kwarg, ) diff --git a/letta/server/server.py b/letta/server/server.py index cc6e18a597..6d54f42339 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -1349,6 +1349,7 @@ def get_agent_recall_cursor( order_by: Optional[str] = "created_at", order: Optional[str] = "asc", reverse: Optional[bool] = False, + return_message_object: bool = True, assistant_message_tool_name: str = constants.DEFAULT_MESSAGE_TOOL, assistant_message_tool_kwarg: str = constants.DEFAULT_MESSAGE_TOOL_KWARG, ) -> Union[List[Message], List[LettaMessage]]: @@ -1367,14 +1368,19 @@ def get_agent_recall_cursor( assert all(isinstance(m, Message) for m in records) - records = [ - msg - for m in records - for msg in m.to_letta_message( - assistant_message_tool_name=assistant_message_tool_name, - assistant_message_tool_kwarg=assistant_message_tool_kwarg, - ) - ] + if not return_message_object: + # If we're GETing messages in reverse, we need to reverse the inner list (generated by to_letta_message) + records = [ + msg + for m in records + for msg in m.to_letta_message( + assistant_message_tool_name=assistant_message_tool_name, + assistant_message_tool_kwarg=assistant_message_tool_kwarg, + ) + ] + + if reverse: + records = records[::-1] return records diff --git a/tests/test_server.py b/tests/test_server.py index b56ff7e311..f1c4cc2c23 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,11 +1,21 @@ import json import uuid +import warnings import pytest import letta.utils as utils from letta.constants import BASE_TOOLS from letta.schemas.enums import MessageRole +from letta.schemas.letta_message import ( + FunctionCallMessage, + FunctionReturn, + InternalMonologue, + LettaMessage, + SystemMessage, + UserMessage, +) +from letta.schemas.message import Message from letta.schemas.user import User from .test_managers import DEFAULT_EMBEDDING_CONFIG @@ -387,3 +397,165 @@ def test_delete_agent_same_org(server: SyncServer, org_id: str, user_id: str): # test that another user in the same org can delete the agent server.delete_agent(another_user.id, agent_state.id) + + +def _test_get_messages_letta_format( + server, + user_id, + agent_id, + reverse=False, +): + """Reverse is off by default, the GET goes in chronological order""" + + messages = server.get_agent_recall_cursor( + user_id=user_id, + agent_id=agent_id, + limit=1000, + reverse=reverse, + return_message_object=True, + ) + # messages = server.get_agent_messages(agent_id=agent_id, start=0, count=1000) + assert all(isinstance(m, Message) for m in messages) + + letta_messages = server.get_agent_recall_cursor( + user_id=user_id, + agent_id=agent_id, + limit=1000, + reverse=reverse, + return_message_object=False, + ) + # letta_messages = server.get_agent_messages(agent_id=agent_id, start=0, count=1000, return_message_object=False) + assert all(isinstance(m, LettaMessage) for m in letta_messages) + + # Loop through `messages` while also looping through `letta_messages` + # Each message in `messages` should have 1+ corresponding messages in `letta_messages` + # If role of message (in `messages`) is `assistant`, + # then there should be two messages in `letta_messages`, one which is type InternalMonologue and one which is type FunctionCallMessage. + # If role of message (in `messages`) is `user`, then there should be one message in `letta_messages` which is type UserMessage. + # If role of message (in `messages`) is `system`, then there should be one message in `letta_messages` which is type SystemMessage. + # If role of message (in `messages`) is `tool`, then there should be one message in `letta_messages` which is type FunctionReturn. + + print("MESSAGES (obj):") + for i, m in enumerate(messages): + # print(m) + print(f"{i}: {m.role}, {m.text[:50]}...") + # print(m.role) + + print("MEMGPT_MESSAGES:") + for i, m in enumerate(letta_messages): + print(f"{i}: {type(m)} ...{str(m)[-50:]}") + + # Collect system messages and their texts + system_messages = [m for m in messages if m.role == MessageRole.system] + system_texts = [m.text for m in system_messages] + + # If there are multiple system messages, print the diff + if len(system_messages) > 1: + print("Differences between system messages:") + for i in range(len(system_texts) - 1): + for j in range(i + 1, len(system_texts)): + import difflib + + diff = difflib.unified_diff( + system_texts[i].splitlines(), + system_texts[j].splitlines(), + fromfile=f"System Message {i+1}", + tofile=f"System Message {j+1}", + lineterm="", + ) + print("\n".join(diff)) + else: + print("There is only one or no system message.") + + letta_message_index = 0 + for i, message in enumerate(messages): + assert isinstance(message, Message) + + print(f"\n\nmessage {i}: {message.role}, {message.text[:50] if message.text else 'null'}") + while letta_message_index < len(letta_messages): + letta_message = letta_messages[letta_message_index] + print(f"letta_message {letta_message_index}: {str(letta_message)[:50]}") + + if message.role == MessageRole.assistant: + print(f"i={i}, M=assistant, MM={type(letta_message)}") + + # If reverse, function call will come first + if reverse: + + # If there are multiple tool calls, we should have multiple back to back FunctionCallMessages + if message.tool_calls is not None: + for tool_call in message.tool_calls: + + # Try to parse the tool call args + try: + json.loads(tool_call.function.arguments) + except: + warnings.warn(f"Function call arguments are not valid JSON: {tool_call.function.arguments}") + + assert isinstance(letta_message, FunctionCallMessage) + letta_message_index += 1 + letta_message = letta_messages[letta_message_index] + + if message.text is not None: + assert isinstance(letta_message, InternalMonologue) + letta_message_index += 1 + letta_message = letta_messages[letta_message_index] + else: + # If there's no inner thoughts then there needs to be a tool call + assert message.tool_calls is not None + + else: + + if message.text is not None: + assert isinstance(letta_message, InternalMonologue) + letta_message_index += 1 + letta_message = letta_messages[letta_message_index] + else: + # If there's no inner thoughts then there needs to be a tool call + assert message.tool_calls is not None + + # If there are multiple tool calls, we should have multiple back to back FunctionCallMessages + if message.tool_calls is not None: + for tool_call in message.tool_calls: + + # Try to parse the tool call args + try: + json.loads(tool_call.function.arguments) + except: + warnings.warn(f"Function call arguments are not valid JSON: {tool_call.function.arguments}") + + assert isinstance(letta_message, FunctionCallMessage) + assert tool_call.function.name == letta_message.function_call.name + assert tool_call.function.arguments == letta_message.function_call.arguments + letta_message_index += 1 + letta_message = letta_messages[letta_message_index] + + elif message.role == MessageRole.user: + print(f"i={i}, M=user, MM={type(letta_message)}") + assert isinstance(letta_message, UserMessage) + assert message.text == letta_message.message + letta_message_index += 1 + + elif message.role == MessageRole.system: + print(f"i={i}, M=system, MM={type(letta_message)}") + assert isinstance(letta_message, SystemMessage) + assert message.text == letta_message.message + letta_message_index += 1 + + elif message.role == MessageRole.tool: + print(f"i={i}, M=tool, MM={type(letta_message)}") + assert isinstance(letta_message, FunctionReturn) + # Check the the value in `text` is the same + assert message.text == letta_message.function_return + letta_message_index += 1 + + else: + raise ValueError(f"Unexpected message role: {message.role}") + + # Move to the next message in the original messages list + break + + +def test_get_messages_letta_format(server, user_id, agent_id): + for reverse in [False, True]: + _test_get_messages_letta_format(server, user_id, agent_id, reverse=reverse) From d6d9cff77ab9ccadb9381219fb12624ae173c0e3 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 13:16:31 -0800 Subject: [PATCH 08/11] Fix server test --- letta/client/client.py | 7 +------ tests/test_server.py | 12 +----------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/letta/client/client.py b/letta/client/client.py index da23a6e3a2..1e6881c55c 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -2262,12 +2262,7 @@ def send_messages( self.save() # format messages - messages = self.interface.to_list() - letta_messages = [] - for m in messages: - letta_messages += m.to_letta_message() - - return LettaResponse(messages=letta_messages, usage=usage) + return LettaResponse(messages=messages, usage=usage) def send_message( self, diff --git a/tests/test_server.py b/tests/test_server.py index f1c4cc2c23..01d6756be7 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -173,23 +173,13 @@ def test_get_recall_memory(server, org_id, user_id, agent_id): messages_2[-1].id messages_3 = server.get_agent_recall_cursor(user_id=user_id, agent_id=agent_id, limit=1000) messages_3[-1].id - assert messages_3[-1].date >= messages_3[0].date + assert messages_3[-1].created_at >= messages_3[0].created_at assert len(messages_3) == len(messages_1) + len(messages_2) messages_4 = server.get_agent_recall_cursor(user_id=user_id, agent_id=agent_id, reverse=True, before=cursor1) assert len(messages_4) == 1 # test in-context message ids - all_messages = server.get_agent_messages(agent_id=agent_id, start=0, count=1000) in_context_ids = server.get_in_context_message_ids(agent_id=agent_id) - # TODO: doesn't pass since recall memory also logs all system message changess - # print("IN CONTEXT:", [m.text for m in server.get_in_context_messages(agent_id=agent_id)]) - # print("ALL:", [m.text for m in all_messages]) - # print() - # for message in all_messages: - # if message.id not in in_context_ids: - # print("NOT IN CONTEXT:", message.id, message.created_at, message.text[-100:]) - # print() - # assert len(in_context_ids) == len(messages_3) message_ids = [m.id for m in messages_3] for message_id in in_context_ids: assert message_id in message_ids, f"{message_id} not in {message_ids}" From fd2b55ccc84f1e0676954961309037c95ef3c552 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 13:17:46 -0800 Subject: [PATCH 09/11] Add self agent quotes" --- letta/functions/function_sets/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letta/functions/function_sets/base.py b/letta/functions/function_sets/base.py index e3e955c8ab..51cfab5daf 100644 --- a/letta/functions/function_sets/base.py +++ b/letta/functions/function_sets/base.py @@ -11,7 +11,7 @@ # If the function fails, throw an exception -def send_message(self: Agent, message: str) -> Optional[str]: +def send_message(self: "Agent", message: str) -> Optional[str]: """ Sends a message to the human user. From ecdca110404b2045b4d96ca37c8fc0ded96a3f43 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 13:18:42 -0800 Subject: [PATCH 10/11] Modify LettaResponse --- letta/schemas/letta_response.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py index db390b9f4c..96fd41781e 100644 --- a/letta/schemas/letta_response.py +++ b/letta/schemas/letta_response.py @@ -1,13 +1,12 @@ import html import json import re -from typing import List, Union +from typing import Union from pydantic import BaseModel, Field from letta.schemas.enums import MessageStreamStatus from letta.schemas.letta_message import LettaMessage, LettaMessageUnion -from letta.schemas.message import Message from letta.schemas.usage import LettaUsageStatistics from letta.utils import json_dumps @@ -24,7 +23,7 @@ class LettaResponse(BaseModel): usage (LettaUsageStatistics): The usage statistics """ - messages: Union[List[Message], List[LettaMessageUnion]] = Field(..., description="The messages returned by the agent.") + messages: Union[LettaMessageUnion] = Field(..., description="The messages returned by the agent.") usage: LettaUsageStatistics = Field(..., description="The usage statistics of the agent.") def __str__(self): From 1657e788c6195a3b9e2c13fe0a29ad5890692cdd Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Wed, 27 Nov 2024 13:22:57 -0800 Subject: [PATCH 11/11] Correct letta response type --- letta/schemas/letta_response.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py index 96fd41781e..58dbf42929 100644 --- a/letta/schemas/letta_response.py +++ b/letta/schemas/letta_response.py @@ -1,7 +1,7 @@ import html import json import re -from typing import Union +from typing import List, Union from pydantic import BaseModel, Field @@ -23,7 +23,7 @@ class LettaResponse(BaseModel): usage (LettaUsageStatistics): The usage statistics """ - messages: Union[LettaMessageUnion] = Field(..., description="The messages returned by the agent.") + messages: List[LettaMessageUnion] = Field(..., description="The messages returned by the agent.") usage: LettaUsageStatistics = Field(..., description="The usage statistics of the agent.") def __str__(self):