@kivox/client 0.1.0-beta.5 → 0.1.0-beta.51
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/README.md +7 -83
- package/dist/index.cjs +5 -0
- package/dist/index.d.ts +3688 -780
- package/dist/index.mjs +5 -0
- package/package.json +12 -9
- package/dist/index.js +0 -1
package/README.md
CHANGED
|
@@ -1,91 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# typescript
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Unified client for the Kivox API
|
|
8
|
-
- Conversation and voice session management
|
|
9
|
-
- WebSockets, events, and real-time state
|
|
10
|
-
- Audio recording and playback
|
|
11
|
-
- Strongly typed contracts and types in TypeScript
|
|
12
|
-
- Framework-agnostic (Svelte, React, Angular, Vue, Vanilla, etc.)
|
|
13
|
-
|
|
14
|
-
## Documentation
|
|
15
|
-
|
|
16
|
-
<https://kivox.ju4n97.workers.dev/docs/clients/kivox-js>
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
3
|
+
To install dependencies:
|
|
19
4
|
|
|
20
5
|
```bash
|
|
21
|
-
|
|
22
|
-
npm install @kivox/client
|
|
23
|
-
|
|
24
|
-
# PNPM
|
|
25
|
-
pnpm add @kivox/client
|
|
26
|
-
|
|
27
|
-
# Yarn
|
|
28
|
-
yarn add @kivox/client
|
|
29
|
-
|
|
30
|
-
# Bun
|
|
31
|
-
bun add @kivox/client
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Basic example
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
import { KivoxClient } from '@kivox/client';
|
|
38
|
-
|
|
39
|
-
const kivox = new KivoxClient({
|
|
40
|
-
baseUrl: 'http://localhost:8787',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// List agents
|
|
44
|
-
const agents = await kivox.agents.list();
|
|
45
|
-
|
|
46
|
-
// Connect to an agent
|
|
47
|
-
const session = await kivox.conversations.connect({
|
|
48
|
-
agentId: '019bb51e-e45f-75e3-b828-94fdf231711e',
|
|
49
|
-
onEvent: (event) => {
|
|
50
|
-
switch (event.type) {
|
|
51
|
-
case 'response.delta.text':
|
|
52
|
-
console.log('Text:', event.chunk);
|
|
53
|
-
break;
|
|
54
|
-
case 'response.delta.audio':
|
|
55
|
-
audioPlayer.enqueue(event.audio);
|
|
56
|
-
break;
|
|
57
|
-
case 'response.complete':
|
|
58
|
-
console.log('Response complete');
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Send a message
|
|
65
|
-
session.sendText('Hello, how can you help me?');
|
|
6
|
+
bun install
|
|
66
7
|
```
|
|
67
8
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
import { KivoxClient } from '@kivox/client';
|
|
9
|
+
To run:
|
|
72
10
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
headers: {
|
|
76
|
-
Authorization: 'Bearer token',
|
|
77
|
-
},
|
|
78
|
-
});
|
|
11
|
+
```bash
|
|
12
|
+
bun run index.ts
|
|
79
13
|
```
|
|
80
14
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- [alpine-chat-app](https://github.com/ekisa-team/kivox/tree/main/examples/alpine-chat-app)
|
|
84
|
-
|
|
85
|
-
## Contributing
|
|
86
|
-
|
|
87
|
-
[https://github.com/ekisa-team/kivox/blob/main/CONTRIBUTING.md](https://github.com/ekisa-team/kivox/blob/main/CONTRIBUTING.md)
|
|
88
|
-
|
|
89
|
-
## License
|
|
90
|
-
|
|
91
|
-
[LICENSE](https://github.com/ekisa-team/kivox/blob/main/LICENSE)
|
|
15
|
+
This project was created using `bun init` in bun v1.3.10. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var{defineProperty:b,getOwnPropertyNames:KG,getOwnPropertyDescriptor:VG}=Object,WG=Object.prototype.hasOwnProperty;function XG(V){return this[V]}var YG=(V)=>{var G=(m??=new WeakMap).get(V),K;if(G)return G;if(G=b({},"__esModule",{value:!0}),V&&typeof V==="object"||typeof V==="function"){for(var X of KG(V))if(!WG.call(G,X))b(G,X,{get:XG.bind(V,X),enumerable:!(K=VG(V,X))||K.enumerable})}return m.set(V,G),G},m;var ZG=(V)=>V;function $G(V,G){this[V]=ZG.bind(null,G)}var JG=(V,G)=>{for(var K in G)b(V,K,{get:G[K],enumerable:!0,configurable:!0,set:$G.bind(G,K)})};var BG={};JG(BG,{readSSE:()=>QG,createSessionClient:()=>OG,createBearerClient:()=>HG});module.exports=YG(BG);var DG=/\{[^{}]+\}/g,NG=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function _G(){return Math.random().toString(36).slice(2,11)}function l(V){let{baseUrl:G="",Request:K=globalThis.Request,fetch:X=globalThis.fetch,querySerializer:W,bodySerializer:Y,pathSerializer:J,headers:D,requestInitExt:k=void 0,...F}={...V};k=NG()?k:void 0,G=o(G);let E=[];async function I(Z,$){let{baseUrl:O,fetch:P=X,Request:f=K,headers:y,params:B={},parseAs:M="json",querySerializer:g,bodySerializer:v=Y??TG,pathSerializer:r,body:c,middleware:a=[],...U}=$||{},q=G;if(O)q=o(O)??G;let S=typeof W==="function"?W:p(W);if(g)S=typeof g==="function"?g:p({...typeof W==="object"?W:{},...g});let h=r||J||IG,w=c===void 0?void 0:v(c,u(D,y,B.header)),e=u(w===void 0||w instanceof FormData?{}:{"Content-Type":"application/json"},D,y,B.header),j=[...E,...a],GG={redirect:"follow",...F,...U,body:w,headers:e},x,A,Q=new f(EG(Z,{baseUrl:q,params:B,querySerializer:S,pathSerializer:h}),GG),N;for(let T in U)if(!(T in Q))Q[T]=U[T];if(j.length){x=_G(),A=Object.freeze({baseUrl:q,fetch:P,parseAs:M,querySerializer:S,bodySerializer:v,pathSerializer:h});for(let T of j)if(T&&typeof T==="object"&&typeof T.onRequest==="function"){let _=await T.onRequest({request:Q,schemaPath:Z,params:B,options:A,id:x});if(_)if(_ instanceof f)Q=_;else if(_ instanceof Response){N=_;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!N){try{N=await P(Q,k)}catch(T){let _=T;if(j.length)for(let H=j.length-1;H>=0;H--){let L=j[H];if(L&&typeof L==="object"&&typeof L.onError==="function"){let C=await L.onError({request:Q,error:_,schemaPath:Z,params:B,options:A,id:x});if(C){if(C instanceof Response){_=void 0,N=C;break}if(C instanceof Error){_=C;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(_)throw _}if(j.length)for(let T=j.length-1;T>=0;T--){let _=j[T];if(_&&typeof _==="object"&&typeof _.onResponse==="function"){let H=await _.onResponse({request:Q,response:N,schemaPath:Z,params:B,options:A,id:x});if(H){if(!(H instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");N=H}}}}let d=N.headers.get("Content-Length");if(N.status===204||Q.method==="HEAD"||d==="0"&&!N.headers.get("Transfer-Encoding")?.includes("chunked"))return N.ok?{data:void 0,response:N}:{error:void 0,response:N};if(N.ok)return{data:await(async()=>{if(M==="stream")return N.body;if(M==="json"&&!d){let _=await N.text();return _?JSON.parse(_):void 0}return await N[M]()})(),response:N};let z=await N.text();try{z=JSON.parse(z)}catch{}return{error:z,response:N}}return{request(Z,$,O){return I($,{...O,method:Z.toUpperCase()})},GET(Z,$){return I(Z,{...$,method:"GET"})},PUT(Z,$){return I(Z,{...$,method:"PUT"})},POST(Z,$){return I(Z,{...$,method:"POST"})},DELETE(Z,$){return I(Z,{...$,method:"DELETE"})},OPTIONS(Z,$){return I(Z,{...$,method:"OPTIONS"})},HEAD(Z,$){return I(Z,{...$,method:"HEAD"})},PATCH(Z,$){return I(Z,{...$,method:"PATCH"})},TRACE(Z,$){return I(Z,{...$,method:"TRACE"})},use(...Z){for(let $ of Z){if(!$)continue;if(typeof $!=="object"||!(("onRequest"in $)||("onResponse"in $)||("onError"in $)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");E.push($)}},eject(...Z){for(let $ of Z){let O=E.indexOf($);if(O!==-1)E.splice(O,1)}}}}function R(V,G,K){if(G===void 0||G===null)return"";if(typeof G==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${V}=${K?.allowReserved===!0?G:encodeURIComponent(G)}`}function n(V,G,K){if(!G||typeof G!=="object")return"";let X=[],W={simple:",",label:".",matrix:";"}[K.style]||"&";if(K.style!=="deepObject"&&K.explode===!1){for(let D in G)X.push(D,K.allowReserved===!0?G[D]:encodeURIComponent(G[D]));let J=X.join(",");switch(K.style){case"form":return`${V}=${J}`;case"label":return`.${J}`;case"matrix":return`;${V}=${J}`;default:return J}}for(let J in G){let D=K.style==="deepObject"?`${V}[${J}]`:J;X.push(R(D,G[J],K))}let Y=X.join(W);return K.style==="label"||K.style==="matrix"?`${W}${Y}`:Y}function s(V,G,K){if(!Array.isArray(G))return"";if(K.explode===!1){let Y={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[K.style]||",",J=(K.allowReserved===!0?G:G.map((D)=>encodeURIComponent(D))).join(Y);switch(K.style){case"simple":return J;case"label":return`.${J}`;case"matrix":return`;${V}=${J}`;default:return`${V}=${J}`}}let X={simple:",",label:".",matrix:";"}[K.style]||"&",W=[];for(let Y of G)if(K.style==="simple"||K.style==="label")W.push(K.allowReserved===!0?Y:encodeURIComponent(Y));else W.push(R(V,Y,K));return K.style==="label"||K.style==="matrix"?`${X}${W.join(X)}`:W.join(X)}function p(V){return function(K){let X=[];if(K&&typeof K==="object")for(let W in K){let Y=K[W];if(Y===void 0||Y===null)continue;if(Array.isArray(Y)){if(Y.length===0)continue;X.push(s(W,Y,{style:"form",explode:!0,...V?.array,allowReserved:V?.allowReserved||!1}));continue}if(typeof Y==="object"){X.push(n(W,Y,{style:"deepObject",explode:!0,...V?.object,allowReserved:V?.allowReserved||!1}));continue}X.push(R(W,Y,V))}return X.join("&")}}function IG(V,G){let K=V;for(let X of V.match(DG)??[]){let W=X.substring(1,X.length-1),Y=!1,J="simple";if(W.endsWith("*"))Y=!0,W=W.substring(0,W.length-1);if(W.startsWith("."))J="label",W=W.substring(1);else if(W.startsWith(";"))J="matrix",W=W.substring(1);if(!G||G[W]===void 0||G[W]===null)continue;let D=G[W];if(Array.isArray(D)){K=K.replace(X,s(W,D,{style:J,explode:Y}));continue}if(typeof D==="object"){K=K.replace(X,n(W,D,{style:J,explode:Y}));continue}if(J==="matrix"){K=K.replace(X,`;${R(W,D)}`);continue}K=K.replace(X,J==="label"?`.${encodeURIComponent(D)}`:encodeURIComponent(D))}return K}function TG(V,G){if(V instanceof FormData)return V;if(G){if((G.get instanceof Function?G.get("Content-Type")??G.get("content-type"):G["Content-Type"]??G["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(V).toString()}return JSON.stringify(V)}function EG(V,G){let K=`${G.baseUrl}${V}`;if(G.params?.path)K=G.pathSerializer(K,G.params.path);let X=G.querySerializer(G.params.query??{});if(X.startsWith("?"))X=X.substring(1);if(X)K+=`?${X}`;return K}function u(...V){let G=new Headers;for(let K of V){if(!K||typeof K!=="object")continue;let X=K instanceof Headers?K.entries():Object.entries(K);for(let[W,Y]of X)if(Y===null)G.delete(W);else if(Array.isArray(Y))for(let J of Y)G.append(W,J);else if(Y!==void 0)G.set(W,Y)}return G}function o(V){if(V.endsWith("/"))return V.substring(0,V.length-1);return V}function jG(V,G){if(!G)return{};try{return JSON.parse(G)}catch{return G}}async function*QG(V){let G=V.getReader(),K=new TextDecoder,X="";try{while(!0){let{done:W,value:Y}=await G.read();if(W)break;X+=K.decode(Y,{stream:!0});let J=X.split(`
|
|
2
|
+
|
|
3
|
+
`);X=J.pop()??"";for(let D of J){let k=D.split(`
|
|
4
|
+
`),F="message",E=[];for(let I of k)if(I.startsWith("event:"))F=I.slice(6).trim();else if(I.startsWith("data:")){let Z=I.slice(5);E.push(Z.startsWith(" ")?Z.slice(1):Z)}if(E.length>0){let I=E.join(`
|
|
5
|
+
`);yield{event:F,data:jG(F,I)}}}}}finally{G.releaseLock()}}var t="https://server.kivox.com.co";function i(V){return l(V)}function OG(V={}){let{baseUrl:G=t,version:K="v1",headers:X={}}=V;return{api:i({baseUrl:`${G}/${K}`,credentials:"include",headers:X})}}function HG(V){let{baseUrl:G=t,version:K="v1",headers:X={},bearerToken:W}=V;return{api:i({baseUrl:`${G}/${K}`,headers:{...X,Authorization:`Bearer ${W}`}})}}
|