@kivox/client 0.1.0-beta.19 → 0.1.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -41
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -68,30 +68,31 @@ type Agent = {
|
|
|
68
68
|
id: string
|
|
69
69
|
template_id: string
|
|
70
70
|
config: AgentConfig
|
|
71
|
-
|
|
71
|
+
secrets: AgentSecret[]
|
|
72
72
|
ork_source: string
|
|
73
73
|
status: AgentStatus
|
|
74
74
|
created_at: Date
|
|
75
75
|
updated_at: Date
|
|
76
76
|
};
|
|
77
77
|
type AgentConfig = {
|
|
78
|
-
avatar_url
|
|
78
|
+
avatar_url?: string
|
|
79
79
|
name: string
|
|
80
|
-
description
|
|
81
|
-
language
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
description?: string
|
|
81
|
+
language?: string
|
|
82
|
+
global_system_prompt?: string
|
|
83
|
+
max_session_duration_minutes?: number
|
|
84
|
+
max_silence_timeout_seconds?: number
|
|
85
|
+
allow_interruptions?: boolean
|
|
86
|
+
llm_engine?: string
|
|
87
|
+
llm_model?: string
|
|
88
|
+
};
|
|
89
|
+
type AgentSecret = {
|
|
87
90
|
key: string
|
|
88
91
|
value: string
|
|
89
|
-
kind: "static" | "dynamic"
|
|
90
|
-
is_secret: boolean
|
|
91
92
|
description: string
|
|
92
93
|
};
|
|
93
|
-
type AgentCreate = Partial<Pick<Agent, "config" | "
|
|
94
|
-
type AgentUpdate = Partial<Pick<AgentCreate, "config" | "
|
|
94
|
+
type AgentCreate = Partial<Pick<Agent, "config" | "secrets" | "ork_source" | "status" | "template_id">>;
|
|
95
|
+
type AgentUpdate = Partial<Pick<AgentCreate, "config" | "secrets" | "ork_source">>;
|
|
95
96
|
type AgentCompilationDiagnostic = {
|
|
96
97
|
errors: string[]
|
|
97
98
|
warnings: string[]
|
|
@@ -330,7 +331,6 @@ type ServerAudioDelta = {
|
|
|
330
331
|
*/
|
|
331
332
|
type ServerTurnComplete = {
|
|
332
333
|
type: "turn_complete"
|
|
333
|
-
stats: UsageStats
|
|
334
334
|
};
|
|
335
335
|
/**
|
|
336
336
|
* Signals that the conversation flow reached its exit node.
|
|
@@ -338,7 +338,6 @@ type ServerTurnComplete = {
|
|
|
338
338
|
*/
|
|
339
339
|
type ServerFlowComplete = {
|
|
340
340
|
type: "flow_complete"
|
|
341
|
-
stats: UsageStats
|
|
342
341
|
};
|
|
343
342
|
/**
|
|
344
343
|
* Represents a non-fatal execution or protocol error.
|
|
@@ -365,18 +364,6 @@ type ServerTick = {
|
|
|
365
364
|
type ServerSessionClosed = {
|
|
366
365
|
type: "session_closed"
|
|
367
366
|
reason: string
|
|
368
|
-
stats: UsageStats
|
|
369
|
-
};
|
|
370
|
-
/**
|
|
371
|
-
* Snapshot of runtime resource consumption.
|
|
372
|
-
*/
|
|
373
|
-
type UsageStats = {
|
|
374
|
-
http_calls: number
|
|
375
|
-
http_limit: number
|
|
376
|
-
llm_calls: number
|
|
377
|
-
llm_limit: number
|
|
378
|
-
steps: number
|
|
379
|
-
steps_limit: number
|
|
380
367
|
};
|
|
381
368
|
/**
|
|
382
369
|
* Union type for all messages sent from the server to the client.
|
|
@@ -799,17 +786,4 @@ declare class KivoxClient {
|
|
|
799
786
|
readonly messages: MessageClient;
|
|
800
787
|
constructor(config: KivoxConfig);
|
|
801
788
|
}
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* Extracts all variable references from config and blueprint.
|
|
805
|
-
*/
|
|
806
|
-
declare function extractAllVariables(config: AgentConfig): string[];
|
|
807
|
-
/**
|
|
808
|
-
* Replaces variable references with their values
|
|
809
|
-
*/
|
|
810
|
-
declare function interpolateVariables(text: string, variables: AgentVariable[]): string;
|
|
811
|
-
/**
|
|
812
|
-
* Checks if a string contains any variable references.
|
|
813
|
-
*/
|
|
814
|
-
declare function hasVariables(text: string): boolean;
|
|
815
|
-
export { interpolateVariables, hasVariables, extractAllVariables, UsageStats, TemplateUpdate, TemplateCreate, Template, SessionConnectionLostEvent, ServerTurnComplete, ServerTick, ServerTextFull, ServerTextDelta, ServerSessionEvent, ServerSessionClosed, ServerMessage, ServerHandshakeOK, ServerHandshakeError, ServerFlowComplete, ServerError, ServerConnectionMessage, ServerAudioDelta, REGEX_VARIABLE, Paginated, MessageRole, Message, KivoxConfig, KivoxClient, HttpTransportError, ConversationTransportError, ConversationSessionConfig, ConversationSession, Conversation, ClientMessage, ClientInputText, ClientInputAudioStream, ClientInputAudio, ClientHandshake, ClientEndSession, ClientCancel, AgentVariable, AgentUpdate, AgentStatus, AgentCreate, AgentConfig, AgentCompilationDiagnostic, Agent };
|
|
789
|
+
export { TemplateUpdate, TemplateCreate, Template, SessionConnectionLostEvent, ServerTurnComplete, ServerTick, ServerTextFull, ServerTextDelta, ServerSessionEvent, ServerSessionClosed, ServerMessage, ServerHandshakeOK, ServerHandshakeError, ServerFlowComplete, ServerError, ServerConnectionMessage, ServerAudioDelta, Paginated, MessageRole, Message, KivoxConfig, KivoxClient, HttpTransportError, ConversationTransportError, ConversationSessionConfig, ConversationSession, Conversation, ClientMessage, ClientInputText, ClientInputAudioStream, ClientInputAudio, ClientHandshake, ClientEndSession, ClientCancel, AgentUpdate, AgentStatus, AgentSecret, AgentCreate, AgentConfig, AgentCompilationDiagnostic, Agent };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class z{http;constructor(_){this.http=_}async list(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents",x);return{...D,items:z.parseAgents(D.items)}}async listLive(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents/live",x);return{...D,items:z.parseAgents(D.items)}}async listDraft(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents/draft",x);return{...D,items:z.parseAgents(D.items)}}async listArchived(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents/archived",x);return{...D,items:z.parseAgents(D.items)}}async get(_){let x=await this.http.get(`/agents/${_}`);return z.parseAgent(x)}async create(_){let x=await this.http.post("/agents",_);return z.parseAgent(x)}async update(_,x){let D=await this.http.put(`/agents/${_}`,x);return z.parseAgent(D)}async markAsLive(_){let x=await this.http.patch(`/agents/${_}/live`);return z.parseAgent(x)}async markAsDraft(_){let x=await this.http.patch(`/agents/${_}/draft`);return z.parseAgent(x)}async markAsArchived(_){let x=await this.http.patch(`/agents/${_}/archived`);return z.parseAgent(x)}async delete(_){let x=await this.http.delete(`/agents/${_}`);return z.parseAgent(x)}async compile(_,x){return await this.http.post(`/agents/${_}/compile`,{ork_source:x})}static parseAgents(_){return _.map(z.parseAgent)}static parseAgent(_){return{..._,config:JSON.parse(_.config),
|
|
1
|
+
class z{http;constructor(_){this.http=_}async list(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents",x);return{...D,items:z.parseAgents(D.items)}}async listLive(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents/live",x);return{...D,items:z.parseAgents(D.items)}}async listDraft(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents/draft",x);return{...D,items:z.parseAgents(D.items)}}async listArchived(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};if(_.search)x.search=_.search;let D=await this.http.get("/agents/archived",x);return{...D,items:z.parseAgents(D.items)}}async get(_){let x=await this.http.get(`/agents/${_}`);return z.parseAgent(x)}async create(_){let x=await this.http.post("/agents",_);return z.parseAgent(x)}async update(_,x){let D=await this.http.put(`/agents/${_}`,x);return z.parseAgent(D)}async markAsLive(_){let x=await this.http.patch(`/agents/${_}/live`);return z.parseAgent(x)}async markAsDraft(_){let x=await this.http.patch(`/agents/${_}/draft`);return z.parseAgent(x)}async markAsArchived(_){let x=await this.http.patch(`/agents/${_}/archived`);return z.parseAgent(x)}async delete(_){let x=await this.http.delete(`/agents/${_}`);return z.parseAgent(x)}async compile(_,x){return await this.http.post(`/agents/${_}/compile`,{ork_source:x})}static parseAgents(_){return _.map(z.parseAgent)}static parseAgent(_){return{..._,config:JSON.parse(_.config),secrets:JSON.parse(_.secrets)}}}class Q{_transport;_conversationId;_closed=!1;_onEvent;_pendingAudioMetadata=null;_remainingMs=0;_elapsedMs=0;get conversationId(){return this._conversationId}get remainingMs(){return this._remainingMs}get elapsedMs(){return this._elapsedMs}get closed(){return this._closed}constructor(_,x,D){this._transport=_,this._conversationId=x,this._onEvent=D.onEvent,this.#_()}sendText(_){if(this._closed){console.warn("Cannot send text: session is closed");return}this._transport.send({type:"input_text",text:_})}sendAudio(_){if(this._closed){console.warn("Cannot send audio: session is closed");return}this._transport.send({type:"input_audio"}),this._transport.sendBinary(_)}streamAudio(_){if(this._closed){console.warn("Cannot stream audio: session is closed");return}this._transport.send({type:"input_audio_stream"}),this._transport.sendBinary(_)}cancelRequest(){if(this._closed){console.warn("Cannot cancel request: session is closed");return}this._transport.send({type:"cancel"})}end(){if(this._closed){console.warn("Cannot end session: session is closed");return}this._transport.send({type:"end"})}close(){if(this._closed)return;this._closed=!0,this._transport.close()}#_(){this._transport.onMessage((_)=>{let x=_;if(x.type==="audio_delta"){this._pendingAudioMetadata={size:x.size};return}if(x.type==="tick")this._remainingMs=x.remaining_ms,this._elapsedMs=x.elapsed_ms;if(x.type==="session_closed")this._closed=!0;this._onEvent?.(x)}),this._transport.onBinary((_)=>{if(this._pendingAudioMetadata){let x={type:"audio_delta",size:this._pendingAudioMetadata.size,audio:_};this._pendingAudioMetadata=null,this._onEvent?.(x)}}),this._transport.onClose(()=>{if(this._closed)return;this._closed=!0,this._onEvent?.({type:"connection_lost",reason:"socket_closed"})}),this._transport.onError(()=>{if(this._closed)return;this._closed=!0,this._onEvent?.({type:"connection_lost",reason:"socket_error"})})}}class B extends Error{code;constructor(_,x="TRANSPORT_ERROR"){super(_);this.code=x;this.name="ConversationTransportError"}}class V{_ws;_closed=!1;_onMessage=null;_onBinary=null;_onError=null;_onClose=null;constructor(_){this._ws=_}async connect(){if(this._ws.readyState===WebSocket.OPEN)throw new B("Already connected","ALREADY_CONNECTED");if(this._ws.readyState===WebSocket.CLOSING||this._ws.readyState===WebSocket.CLOSED)throw new B("Socket is closing or closed","SOCKET_CLOSED");return new Promise((_,x)=>{let D=()=>{this._ws.removeEventListener("open",D),this._ws.removeEventListener("error",K),this.#_(),_()},K=()=>{this._ws.removeEventListener("open",D),this._ws.removeEventListener("error",K),x(new B("Connection failed","CONNECTION_FAILED"))};this._ws.addEventListener("open",D),this._ws.addEventListener("error",K)})}send(_){if(this._ws.readyState!==WebSocket.OPEN)throw new B("Not connected","NOT_CONNECTED");this._ws.send(JSON.stringify(_))}async sendBinary(_){if(this._ws.readyState!==WebSocket.OPEN)throw new B("Not connected","NOT_CONNECTED");let x=await _.arrayBuffer();this._ws.send(x)}onMessage(_){this._onMessage=_}onBinary(_){this._onBinary=_}onError(_){this._onError=_}onClose(_){this._onClose=_}close(){if(this._closed)return;if(this._closed=!0,this._ws.readyState===WebSocket.OPEN||this._ws.readyState===WebSocket.CONNECTING)this._ws.close();this._onClose?.()}#_(){this._ws.addEventListener("message",(_)=>{if(_.data instanceof Blob)this._onBinary?.(_.data);else if(_.data instanceof ArrayBuffer)this._onBinary?.(new Blob([_.data]));else if(typeof _.data==="string")try{let x=JSON.parse(_.data);this._onMessage?.(x)}catch(x){console.warn("Failed to parse JSON message:",_.data,x)}}),this._ws.addEventListener("error",()=>{if(this._closed)return;this._onError?.(new B("WebSocket error")),this.close()}),this._ws.addEventListener("close",()=>{if(this._closed)return;this.close()})}}class X{http;ws;constructor(_,x){this.http=_;this.ws=x}async list(_){let x={limit:(_.limit??20).toString(),page:(_.page??1).toString()};return this.http.get(`/agents/${_.agentId}/conversations`,x)}async get(_){return this.http.get(`/conversations/${_}`)}async connect(_){let x=this.ws.connect("/conversations/websocket"),D=new V(x);return await D.connect(),D.send({type:"handshake",agent_id:_.agentId}),new Promise((K,F)=>{let N=!1;D.onMessage((J)=>{switch(J.type){case"handshake_ok":N=!0,_.onConnection?.(J),K(new Q(D,J.conversation_id,_));break;case"handshake_error":N=!0,_.onConnection?.(J),D.close(),F(Error(`Handshake rejected: ${J.reason}`));break;default:break}}),D.onError((J)=>{if(!N)F(J)}),D.onClose(()=>{if(!N)F(Error("WebSocket connection lost during handshake"))})})}}function L(_){let x=new URL(_),D=x.protocol==="https:"?"wss:":"ws:";return{rest:`${x.origin}/v1`,ws:`${D}//${x.host}/v1`}}class Y extends Error{status;statusText;body;constructor(_,x,D,K){super(_);this.status=x;this.statusText=D;this.body=K;this.name="HttpTransportError"}}class Z{config;constructor(_){this.config=_}async request(_,x){let D=`${this.config.baseUrl}${_}`,K=await fetch(D,{...x,headers:{"Content-Type":"application/json",...this.config.headers,...x?.headers}});if(!K.ok){let F=await K.text();throw new Y(`HTTP ${K.status}: ${K.statusText}`,K.status,K.statusText,F)}return K.json()}async get(_,x){let D=new URL(`${this.config.baseUrl}${_}`);if(x){let K=Object.entries(x);for(let[F,N]of K)D.searchParams.set(F,N)}return this.request(_+D.search,{method:"GET"})}async post(_,x){return this.request(_,{method:"POST",body:x?JSON.stringify(x):void 0})}async put(_,x){return this.request(_,{method:"PUT",body:x?JSON.stringify(x):void 0})}async patch(_,x){return this.request(_,{method:"PATCH",body:x?JSON.stringify(x):void 0})}async delete(_){return this.request(_,{method:"DELETE"})}}class ${config;constructor(_){this.config=_}connect(_){let x=`${this.config.baseUrl}${_}`;return new WebSocket(x)}}class G{http;constructor(_){this.http=_}async list(_={}){let x={limit:(_.limit??50).toString(),page:(_.page??1).toString()};if(_.conversationId)x.conversation_id=_.conversationId;return this.http.get("/messages",x)}async get(_){return this.http.get(`/messages/${_}`)}}class M{http;constructor(_){this.http=_}async list(_={}){let x={limit:(_.limit??10).toString(),page:(_.page??1).toString()};return this.http.get("/templates",x)}async get(_){return this.http.get(`/templates/${_}`)}async create(_){return this.http.post("/templates",_)}async update(_,x){return this.http.put(`/templates/${_}`,x)}async delete(_){return this.http.delete(`/templates/${_}`)}}class O{agents;conversations;templates;messages;constructor(_){let x=L(_.baseUrl),D=new Z({baseUrl:x.rest,headers:_.headers}),K=new $({baseUrl:x.ws,headers:_.headers});this.agents=new z(D),this.templates=new M(D),this.conversations=new X(D,K),this.messages=new G(D)}}export{O as KivoxClient,Y as HttpTransportError,B as ConversationTransportError,Q as ConversationSession};
|