@kivox/client 0.1.0-beta.13 → 0.1.0-beta.15
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 +25 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ type Agent = {
|
|
|
69
69
|
template_id: string
|
|
70
70
|
config: AgentConfig
|
|
71
71
|
blueprint: AgentBlueprint
|
|
72
|
+
variables: AgentVariable[]
|
|
72
73
|
status: AgentStatus
|
|
73
74
|
created_at: Date
|
|
74
75
|
updated_at: Date
|
|
@@ -89,8 +90,15 @@ type AgentBlueprint<
|
|
|
89
90
|
nodes: NodeType[]
|
|
90
91
|
edges: EdgeType[]
|
|
91
92
|
};
|
|
92
|
-
type
|
|
93
|
-
|
|
93
|
+
type AgentVariable = {
|
|
94
|
+
key: string
|
|
95
|
+
value: string
|
|
96
|
+
kind: "static" | "dynamic"
|
|
97
|
+
is_secret: boolean
|
|
98
|
+
description: string
|
|
99
|
+
};
|
|
100
|
+
type AgentCreate = Partial<Pick<Agent, "config" | "blueprint" | "variables" | "status" | "template_id">>;
|
|
101
|
+
type AgentUpdate = Partial<Pick<AgentCreate, "config" | "blueprint" | "variables">>;
|
|
94
102
|
type NodeType = "entry" | "thread" | "tool" | "exit";
|
|
95
103
|
type Node = {
|
|
96
104
|
id: string
|
|
@@ -803,4 +811,18 @@ declare class KivoxClient {
|
|
|
803
811
|
readonly messages: MessageClient;
|
|
804
812
|
constructor(config: KivoxConfig);
|
|
805
813
|
}
|
|
806
|
-
|
|
814
|
+
import { AgentBlueprint as AgentBlueprint2, AgentConfig as AgentConfig2, AgentVariable as AgentVariable2 } from "@kivox/client";
|
|
815
|
+
declare const REGEX_VARIABLE: RegExp;
|
|
816
|
+
/**
|
|
817
|
+
* Extracts all variable references from config and blueprint.
|
|
818
|
+
*/
|
|
819
|
+
declare function extractAllVariables(config: AgentConfig2, blueprint: AgentBlueprint2<Record<string, unknown>, Record<string, unknown>>): string[];
|
|
820
|
+
/**
|
|
821
|
+
* Replaces variable references with their values
|
|
822
|
+
*/
|
|
823
|
+
declare function interpolateVariables(text: string, variables: AgentVariable2[]): string;
|
|
824
|
+
/**
|
|
825
|
+
* Checks if a string contains any variable references.
|
|
826
|
+
*/
|
|
827
|
+
declare function hasVariables(text: string): boolean;
|
|
828
|
+
export { interpolateVariables, hasVariables, extractAllVariables, TemplateUpdate, TemplateCreate, Template, SessionConnectionLostEvent, ServerSpeechStart, ServerSpeechEnd, ServerSessionTimeout, ServerSessionTick, ServerSessionStart, ServerSessionLifecycleMessage, ServerSessionHandshakeReject, ServerSessionHandshakeAccept, ServerSessionEvent, ServerSessionEnd, ServerSessionActivityMessage, ServerResponseError, ServerResponseDeltaText, ServerResponseDeltaAudio, ServerResponseComplete, ServerResponseCancel, ServerMessage, ServerConnectionMessage, REGEX_VARIABLE, Paginated, NodeType, NodePosition, NodeDimensions, Node, MessageRole, Message, KivoxConfig, KivoxClient, HttpTransportError, Edge, ConversationTransportError, ConversationSessionConfig, ConversationSession, Conversation, ClientSessionHandshakeOffer, ClientSessionEnd, ClientRequestCancel, ClientMessage, ClientInputText, ClientInputAudioStream, ClientInputAudio, AgentVariable, AgentUpdate, AgentStatus, AgentCreate, AgentConfig, AgentBlueprint, Agent };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class Z{http;constructor(K){this.http=K}async list(K={}){let J={limit:(K.limit??10).toString(),page:(K.page??1).toString()};if(K.search)J.search=K.search;let Q=await this.http.get("/agents",J);return{...Q,items:Z.parseAgents(Q.items)}}async listLive(K={}){let J={limit:(K.limit??10).toString(),page:(K.page??1).toString()};if(K.search)J.search=K.search;let Q=await this.http.get("/agents/live",J);return{...Q,items:Z.parseAgents(Q.items)}}async listDraft(K={}){let J={limit:(K.limit??10).toString(),page:(K.page??1).toString()};if(K.search)J.search=K.search;let Q=await this.http.get("/agents/draft",J);return{...Q,items:Z.parseAgents(Q.items)}}async listArchived(K={}){let J={limit:(K.limit??10).toString(),page:(K.page??1).toString()};if(K.search)J.search=K.search;let Q=await this.http.get("/agents/archived",J);return{...Q,items:Z.parseAgents(Q.items)}}async get(K){let J=await this.http.get(`/agents/${K}`);return Z.parseAgent(J)}async create(K){let J=await this.http.post("/agents",K);return Z.parseAgent(J)}async update(K,J){let Q=await this.http.put(`/agents/${K}`,J);return Z.parseAgent(Q)}async markAsLive(K){let J=await this.http.patch(`/agents/${K}/live`);return Z.parseAgent(J)}async markAsDraft(K){let J=await this.http.patch(`/agents/${K}/draft`);return Z.parseAgent(J)}async markAsArchived(K){let J=await this.http.patch(`/agents/${K}/archived`);return Z.parseAgent(J)}async delete(K){let J=await this.http.delete(`/agents/${K}`);return Z.parseAgent(J)}static parseAgents(K){return K.map(Z.parseAgent)}static parseAgent(K){return{...K,config:JSON.parse(K.config),blueprint:JSON.parse(K.blueprint),variables:JSON.parse(K.variables)}}}class G{_transport;_conversationId;_maxDurationMs;_startTime;_endTime;_closed=!1;_pendingAudioMetadata=null;_onEvent;get conversationId(){return this._conversationId}get maxDurationMs(){return this._maxDurationMs}get startTime(){return this._startTime}get endTime(){return this._endTime}get closed(){return this._closed}constructor(K,J,Q,Y,$,N){this._transport=K,this._conversationId=J,this._maxDurationMs=Q,this._startTime=Y,this._endTime=$,this._onEvent=N.onEvent,this.#K()}sendText(K){if(this._closed){console.warn("Cannot send text: session is closed");return}this._transport.send({type:"input.text",conversation_id:this._conversationId,text:K})}sendAudio(K){if(this._closed){console.warn("Cannot send audio: session is closed");return}this._transport.send({type:"input.audio",conversation_id:this._conversationId}),this._transport.sendBinary(K)}streamAudio(K){if(this._closed){console.warn("Cannot stream audio: session is closed");return}this._transport.send({type:"input.audio.stream",conversation_id:this._conversationId}),this._transport.sendBinary(K)}cancelRequest(){if(this._closed){console.warn("Cannot cancel session: session is closed");return}this._transport.send({type:"request.cancel",conversation_id:this._conversationId})}end(){if(this._closed){console.warn("Cannot end session: session is closed");return}this._transport.send({type:"session.end",conversation_id:this._conversationId})}close(){if(this._closed)return;this._closed=!0,this._transport.close()}#K(){this._transport.onMessage((K)=>{let J=K;if(J.type==="response.delta.audio"){this._pendingAudioMetadata={conversation_id:J.conversation_id,size:J.size};return}if(J.type==="session.end"||J.type==="session.timeout"||J.type==="session.connection.lost")this._closed=!0;this._onEvent?.(J)}),this._transport.onBinary((K)=>{if(this._pendingAudioMetadata){let J={type:"response.delta.audio",conversation_id:this._pendingAudioMetadata.conversation_id,size:this._pendingAudioMetadata.size,audio:K};this._pendingAudioMetadata=null,this._onEvent?.(J)}}),this._transport.onClose(()=>{if(this._closed)return;this._closed=!0,this._onEvent?.({type:"session.connection.lost",conversation_id:this._conversationId,reason:"socket_closed"})}),this._transport.onError(()=>{if(this._closed)return;this._closed=!0,this._onEvent?.({type:"session.connection.lost",conversation_id:this._conversationId,reason:"socket_error"})})}}class B extends Error{code;constructor(K,J="TRANSPORT_ERROR"){super(K);this.code=J;this.name="ConversationTransportError"}}class H{_ws;_closed=!1;_onMessage=null;_onBinary=null;_onError=null;_onClose=null;constructor(K){this._ws=K}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((K,J)=>{let Q=()=>{this._ws.removeEventListener("open",Q),this._ws.removeEventListener("error",Y),this.#K(),K()},Y=()=>{this._ws.removeEventListener("open",Q),this._ws.removeEventListener("error",Y),J(new B("Connection failed","CONNECTION_FAILED"))};this._ws.addEventListener("open",Q),this._ws.addEventListener("error",Y)})}send(K){if(this._ws.readyState!==WebSocket.OPEN)throw new B("Not connected","NOT_CONNECTED");this._ws.send(JSON.stringify(K))}async sendBinary(K){if(this._ws.readyState!==WebSocket.OPEN)throw new B("Not connected","NOT_CONNECTED");let J=await K.arrayBuffer();this._ws.send(J)}onMessage(K){this._onMessage=K}onBinary(K){this._onBinary=K}onError(K){this._onError=K}onClose(K){this._onClose=K}close(){if(this._closed)return;if(this._closed=!0,this._ws.readyState===WebSocket.OPEN||this._ws.readyState===WebSocket.CONNECTING)this._ws.close();this._onClose?.()}#K(){this._ws.addEventListener("message",(K)=>{if(K.data instanceof Blob)this._onBinary?.(K.data);else if(K.data instanceof ArrayBuffer)this._onBinary?.(new Blob([K.data]));else try{let J=JSON.parse(K.data);this._onMessage?.(J)}catch(J){console.warn("Failed to parse message:",K.data,J)}}),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 O{http;ws;constructor(K,J){this.http=K;this.ws=J}async list(K){let J={limit:(K.limit??20).toString(),page:(K.page??1).toString()};return this.http.get(`/agents/${K.agentId}/conversations`,J)}async get(K){return this.http.get(`/conversations/${K}`)}async connect(K){let J=this.ws.connect("/conversations/websocket"),Q=new H(J);return await Q.connect(),Q.send({type:"session.handshake.offer",agent_id:K.agentId}),new Promise((Y,$)=>{let N=!1;Q.onMessage((z)=>{switch(z.type){case"session.handshake.accept":K.onConnection?.(z);break;case"session.handshake.reject":N=!0,K.onConnection?.(z),Q.close(),$(Error(`Handshake rejected: ${z.reason}`));break;case"session.start":{N=!0,K.onConnection?.(z);let M=new G(Q,z.conversation_id,z.max_duration_ms,z.start_time,z.end_time,K);Y(M);break}default:break}}),Q.onError((z)=>{if(!N)$(z)}),Q.onClose(()=>{if(!N)$(Error("WebSocket connection lost during handshake"))})})}}function D(K){let J=new URL(K),Q=J.protocol==="https:"?"wss:":"ws:";return{rest:`${J.origin}/v1`,ws:`${Q}//${J.host}/v1`}}class X extends Error{status;statusText;body;constructor(K,J,Q,Y){super(K);this.status=J;this.statusText=Q;this.body=Y;this.name="HttpTransportError"}}class U{config;constructor(K){this.config=K}async request(K,J){let Q=`${this.config.baseUrl}${K}`,Y=await fetch(Q,{...J,headers:{"Content-Type":"application/json",...this.config.headers,...J?.headers}});if(!Y.ok){let $=await Y.text();throw new X(`HTTP ${Y.status}: ${Y.statusText}`,Y.status,Y.statusText,$)}return Y.json()}async get(K,J){let Q=new URL(`${this.config.baseUrl}${K}`);if(J){let Y=Object.entries(J);for(let[$,N]of Y)Q.searchParams.set($,N)}return this.request(K+Q.search,{method:"GET"})}async post(K,J){return this.request(K,{method:"POST",body:J?JSON.stringify(J):void 0})}async put(K,J){return this.request(K,{method:"PUT",body:J?JSON.stringify(J):void 0})}async patch(K,J){return this.request(K,{method:"PATCH",body:J?JSON.stringify(J):void 0})}async delete(K){return this.request(K,{method:"DELETE"})}}class F{config;constructor(K){this.config=K}connect(K){let J=`${this.config.baseUrl}${K}`;return new WebSocket(J)}}class L{http;constructor(K){this.http=K}async list(K={}){let J={limit:(K.limit??50).toString(),page:(K.page??1).toString()};if(K.conversationId)J.conversation_id=K.conversationId;return this.http.get("/messages",J)}async get(K){return this.http.get(`/messages/${K}`)}}class W{http;constructor(K){this.http=K}async list(K={}){let J={limit:(K.limit??10).toString(),page:(K.page??1).toString()};return this.http.get("/templates",J)}async get(K){return this.http.get(`/templates/${K}`)}async create(K){return this.http.post("/templates",K)}async update(K,J){return this.http.put(`/templates/${K}`,J)}async delete(K){return this.http.delete(`/templates/${K}`)}}class j{agents;conversations;templates;messages;constructor(K){let J=D(K.baseUrl),Q=new U({baseUrl:J.rest,headers:K.headers}),Y=new F({baseUrl:J.ws,headers:K.headers});this.agents=new Z(Q),this.templates=new W(Q),this.conversations=new O(Q,Y),this.messages=new L(Q)}}var x=/\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g;function S(K){let J=new Set,Q;while((Q=x.exec(K))!==null){let Y=Q[1];if(!Y)continue;J.add(Y)}return J}function _(K,J){if(typeof K==="string"){let Q=S(K);for(let Y of Q)J.add(Y)}else if(Array.isArray(K))for(let Q of K)_(Q,J);else if(typeof K==="object"&&K!==null){let Q=Object.values(K);for(let Y of Q)_(Y,J)}}function d(K,J){let Q=new Set;_(K,Q);for(let Y of J.nodes)if(Y.data)_(Y.data,Q);for(let Y of J.edges)if(Y.data)_(Y.data,Q);return Array.from(Q).toSorted()}function m(K,J){let Q=new Map(J.map((Y)=>[Y.key,Y.value]));return K.replace(x,(Y,$)=>{return Q.get($)??Y})}function l(K){return x.test(K)}export{m as interpolateVariables,l as hasVariables,d as extractAllVariables,x as REGEX_VARIABLE,j as KivoxClient,X as HttpTransportError,B as ConversationTransportError,G as ConversationSession};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kivox/client",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.15",
|
|
4
4
|
"description": "JavaScript/TypeScript client for KIVOX",
|
|
5
5
|
"homepage": "https://github.com/ekisa-team/kivox#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public",
|
|
46
|
-
"tag": "
|
|
46
|
+
"tag": "latest"
|
|
47
47
|
}
|
|
48
48
|
}
|