@jazzmine-ui/sdk 0.1.4 → 0.1.5
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/client/JazzmineClient.d.ts +2 -1
- package/dist/client/JazzmineClient.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +158 -131
- package/dist/types/conversation.d.ts +28 -0
- package/dist/types/conversation.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/info.d.ts +1 -1
- package/dist/types/info.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JazzmineEndpoints } from '../discovery';
|
|
2
|
-
import { ChatRequestPayload, ChatResponse, ConversationCreateRequest, ConversationCreateResponse, ConversationDeleteResponse, ConversationListParams, ConversationPage, ConversationSearchParams, ConversationUpdateRequest, ConversationUpdateResponse, HealthResponse, InfoResponse, JazzmineClientOptions, RequestOptions, StreamHandlers } from '../types';
|
|
2
|
+
import { ChatRequestPayload, ChatResponse, ConversationCreateRequest, ConversationCreateResponse, ConversationDeleteResponse, ConversationListParams, ConversationMessagesPage, ConversationMessagesParams, ConversationPage, ConversationSearchParams, ConversationUpdateRequest, ConversationUpdateResponse, HealthResponse, InfoResponse, JazzmineClientOptions, RequestOptions, StreamHandlers } from '../types';
|
|
3
3
|
export declare class JazzmineClient {
|
|
4
4
|
private readonly baseUrl;
|
|
5
5
|
private readonly apiKey?;
|
|
@@ -19,6 +19,7 @@ export declare class JazzmineClient {
|
|
|
19
19
|
listConversations(params: ConversationListParams, requestOptions?: RequestOptions): Promise<ConversationPage>;
|
|
20
20
|
searchConversations(params: ConversationSearchParams, requestOptions?: RequestOptions): Promise<ConversationPage>;
|
|
21
21
|
updateConversation(conversationId: string, payload: ConversationUpdateRequest, requestOptions?: RequestOptions): Promise<ConversationUpdateResponse>;
|
|
22
|
+
getConversationMessages(params: ConversationMessagesParams, requestOptions?: RequestOptions): Promise<ConversationMessagesPage>;
|
|
22
23
|
chat(payload: ChatRequestPayload, requestOptions?: RequestOptions): Promise<ChatResponse>;
|
|
23
24
|
chatStream(payload: ChatRequestPayload, handlers?: StreamHandlers, requestOptions?: RequestOptions): Promise<ChatResponse>;
|
|
24
25
|
sendMessage(message: string, options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JazzmineClient.d.ts","sourceRoot":"","sources":["../../src/client/JazzmineClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAYtB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"JazzmineClient.d.ts","sourceRoot":"","sources":["../../src/client/JazzmineClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAYtB,OAAO,KAAK,EAEV,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EAEtB,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,cAAc,EAEd,cAAc,EACf,MAAM,UAAU,CAAC;AAYlB,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAU;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IAEvC,OAAO,CAAC,SAAS,CAAo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AAE,CAAC;QAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,cAAc,CAAC,EAAE,cAAc,CAAC;KAC5B,GACL,OAAO,CAAC;QAAE,QAAQ,EAAE,YAAY,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IA0BxD,sBAAsB,CAAC,cAAc,GAAE,cAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAmB/E,eAAe;IAS7B,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,YAAY;CAMrB;AAED,eAAe,cAAc,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const I={chat:"/chat",stream:"/chat/stream",conversations:"/conversations",health:"/health",info:"/info"};async function
|
|
2
|
-
`);if(!
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const I={chat:"/chat",stream:"/chat/stream",conversations:"/conversations",health:"/health",info:"/info"};async function U(r){if(r.endpointsResolved||!r.autoDiscoverEndpoints)return r.endpointsResolved;try{return await r.resolveServerEndpoints(r.requestOptions),!0}catch{return!0}}function x(r,t){const e={},n=r==null?void 0:r.endpoints;if(!n||typeof n!="object")return e;const i=m(n.chat,"POST",t),s=m(n.stream,"POST",t),a=m(n.conversations_create,"POST",t),u=m(n.health,"GET",t),h=m(n.info,"GET",t);return i&&(e.chat=i),s?e.stream=s:i&&(e.stream=`${i.replace(/\/+$/,"")}/stream`),a&&(e.conversations=a),u&&(e.health=u),h&&(e.info=h),e}function m(r,t,e){if(typeof r!="string")return null;const n=r.match(/^([A-Z]+)\s+(.+)$/i);if(!n)return null;const i=n[1].toUpperCase(),s=n[2].trim();if(i!==t.toUpperCase())return null;try{const a=new URL(s,e);return`${a.pathname}${a.search}`}catch{return null}}class o extends Error{constructor(t,e){super(t),this.name="JazzmineClientError",this.status=e==null?void 0:e.status,this.code=e==null?void 0:e.code,this.details=e==null?void 0:e.details}}function M(r,t){if(!r&&!t)return;if(!r)return t;if(!t)return r;const e=AbortSignal.any;if(typeof e=="function")return e([r,t]);const n=new AbortController,i=()=>{n.abort()};return r.aborted||t.aborted?(n.abort(),n.signal):(r.addEventListener("abort",i,{once:!0}),t.addEventListener("abort",i,{once:!0}),n.signal)}function R(r){return r instanceof DOMException&&(r.name==="AbortError"||r.name==="TimeoutError")}function A(r){const t=r.trim().replace(/\/+$/,"");let e;try{e=new URL(t)}catch{throw new o("Invalid baseEndpoint. Provide a full URL like https://api.example.com or http://127.0.0.1:8010.")}if(!e.protocol.startsWith("http"))throw new o("baseEndpoint must use http or https.");return`${e.protocol}//${e.host}${e.pathname.replace(/\/+$/,"")}`}function J(r,t){const e=t.startsWith("/")?t:`/${t}`;return`${r}${e}`}function E(r){const t=r==null?void 0:r.message;if(typeof t!="string"||!t.trim())throw new o("chat payload requires a non-empty message string.");if(r.explicit_context&&!Array.isArray(r.explicit_context))throw new o("explicit_context must be an array of strings.");if(Array.isArray(r.explicit_context)&&r.explicit_context.some(n=>typeof n!="string"))throw new o("explicit_context must contain only strings.");if(r.metadata!==void 0&&(r.metadata===null||typeof r.metadata!="object"))throw new o("metadata must be an object when provided.")}function P(r,t,e){if(r===void 0)return t;if(!Number.isFinite(r)||r<=0)throw new o(`${e} must be a positive number.`);return Math.round(r)}function b(r,t,e,n,i){if(r===void 0)return t;if(!Number.isInteger(r)||r<n||r>i)throw new o(`${e} must be an integer between ${n} and ${i}.`);return r}async function k(r,t){const e=r*(t+1);e<=0||await new Promise(n=>setTimeout(n,e))}async function N(r){let t;for(let e=0;e<=r.retries;e+=1)try{return await r.runAttempt(e)}catch(n){if(t=n,r.allowRetry&&e<r.retries&&r.shouldRetry(n)){await k(r.retryBackoffMs,e);continue}throw n}throw t}class p extends Error{constructor(t){const e=`Request timed out after ${t} ms.`;super(e),this.name="RetryableTimeoutError",this.finalError=new o(e)}}class y extends Error{constructor(t){super(t),this.name="RetryableNetworkError",this.finalError=new o(t)}}async function z(r,t){try{return await N({retries:t.retries,allowRetry:t.allowRetry,retryBackoffMs:r.retryBackoffMs,runAttempt:async()=>{const e=new AbortController,n=setTimeout(()=>{e.abort()},t.timeoutMs),i=M(t.signal,e.signal);try{const s=await r.fetchFn(_(r.baseUrl,t.path),{method:t.method,headers:T(r.apiKey,{accept:"application/json",contentType:t.body!==void 0?"application/json":void 0}),body:t.body!==void 0?JSON.stringify(t.body):void 0,signal:i});if(!s.ok)throw await S(s,t.path);const a=await s.text();if(!a.trim())return{};try{return JSON.parse(a)}catch{throw new o(`Expected JSON response from ${t.path}, but received invalid JSON.`)}}catch(s){throw R(s)?new p(t.timeoutMs):s instanceof o?s:s instanceof TypeError?new y(v(s,"Network request failed.")):new o(v(s,"Network request failed."))}finally{clearTimeout(n)}},shouldRetry:e=>{if(e instanceof p||e instanceof y)return!0;if(e instanceof o){const n=e.status??0;return n===429||n>=500}return!1}})}catch(e){throw e instanceof p||e instanceof y?e.finalError:e instanceof o?e:new o(v(e,"Network request failed."))}}async function S(r,t){const e=await r.text();let n;if(e.trim())try{n=JSON.parse(e)}catch{n=e}const i=D(n),s=`HTTP ${r.status} on ${t}${i?`: ${i}`:""}`;return new o(s,{status:r.status,details:n})}function T(r,t){const e={};return t.accept&&(e.Accept=t.accept),t.contentType&&(e["Content-Type"]=t.contentType),r&&(e.Authorization=`Bearer ${r}`),e}function _(r,t){return J(r,t)}function D(r){if(!r)return"";if(typeof r=="string")return r.slice(0,300);if(typeof r=="object"){const t=r,e=t.detail,n=t.error;if(typeof e=="string")return e.slice(0,300);if(typeof n=="string")return n.slice(0,300)}return""}function v(r,t){return r instanceof Error&&r.message?r.message:t}function j(r){const t=r.split(/\r?\n/).map(s=>s.trimEnd()).filter(s=>s.length>0&&!s.startsWith(":"));if(t.length===0)return null;let e="message";const n=[];for(const s of t){if(s.startsWith("event:")){e=s.slice(6).trim()||"message";continue}s.startsWith("data:")&&n.push(s.slice(5).trim())}const i=n.join(`
|
|
2
|
+
`);if(!i)return{event:e,data:null};try{return{event:e,data:JSON.parse(i)}}catch{return{event:e,data:i}}}async function L(r){var a,u,h,c;const t=r.handlers??{},e=r.body.getReader(),n=new TextDecoder("utf-8");let i="",s=null;for(;;){const{done:d,value:w}=await e.read();if(d)break;i+=n.decode(w,{stream:!0});const g=i.split(/\n\n/);i=g.pop()??"";for(const $ of g){const l=j($);if(l){if((a=t.onRawEvent)==null||a.call(t,l.event,l.data),l.event==="intermediate"){(u=t.onIntermediate)==null||u.call(t,l.data);continue}if(l.event==="done"){s=r.expectChatResponse(l.data),(h=t.onDone)==null||h.call(t,s);continue}if(l.event==="error"){const f=r.toStreamError(l.data);throw(c=t.onErrorEvent)==null||c.call(t,f),new o(f.detail||f.error||"Stream error event received.",{code:f.error,details:f})}}}}if(!s)throw new o("Stream ended without a final done event containing ChatResponse.");return s}const F=2e4,B=2,q=350;class C{constructor(t,e={}){if(this.endpointsResolved=!1,!t||!t.trim())throw new o("baseEndpoint is required.");if(typeof fetch!="function"&&!e.fetchImpl)throw new o("fetch is not available in this runtime. Provide options.fetchImpl.");this.baseUrl=A(t),this.apiKey=e.apiKey,this.timeoutMs=P(e.timeoutMs,F,"timeoutMs"),this.retries=b(e.retries,B,"retries",0,10),this.retryBackoffMs=b(e.retryBackoffMs,q,"retryBackoffMs",0,6e4),this.autoDiscoverEndpoints=e.autoDiscoverEndpoints!==!1,this.defaultUserId=(e.defaultUserId??"user").trim()||"user",this.fetchFn=e.fetchImpl??fetch.bind(globalThis),this.endpoints={...I}}async getHealth(t={}){return await this.ensureEndpoints(t),this.requestJson({method:"GET",path:this.endpoints.health,timeoutMs:t.timeoutMs??this.timeoutMs,retries:t.retries??this.retries,signal:t.signal,allowRetry:!0})}async getInfo(t={}){return await this.ensureEndpoints(t),this.requestJson({method:"GET",path:this.endpoints.info,timeoutMs:t.timeoutMs??this.timeoutMs,retries:t.retries??this.retries,signal:t.signal,allowRetry:!0})}async createConversation(t={},e={}){return await this.ensureEndpoints(e),this.requestJson({method:"POST",path:this.endpoints.conversations,body:{conversation_id:t.conversation_id??"",user_id:t.user_id??this.defaultUserId,title:t.title??"New conversation"},timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??0,signal:e.signal,allowRetry:!1})}async deleteConversation(t,e={}){const n=t==null?void 0:t.trim();if(!n)throw new o("conversationId is required.");return await this.ensureEndpoints(e),this.requestJson({method:"DELETE",path:`${this.endpoints.conversations}/${encodeURIComponent(n)}`,timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??this.retries,signal:e.signal,allowRetry:!0})}async listConversations(t,e={}){var h;const n=(h=t.userId)==null?void 0:h.trim();if(!n)throw new o("userId is required.");const i=t.limit??100,s=t.offset??0;await this.ensureEndpoints(e);const a=new URLSearchParams({user_id:n,limit:String(i),offset:String(s)}).toString(),u=await this.requestJson({method:"GET",path:`${this.endpoints.conversations}?${a}`,timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??this.retries,signal:e.signal,allowRetry:!0});return{conversations:u.conversations,total:u.total,limit:u.limit,offset:u.offset,hasMore:u.total>s+u.conversations.length}}async searchConversations(t,e={}){var d,w;const n=(d=t.userId)==null?void 0:d.trim(),i=(w=t.query)==null?void 0:w.trim();if(!n)throw new o("userId is required.");if(!i)throw new o("query is required.");const s=t.limit??100,a=t.offset??0;await this.ensureEndpoints(e);const u=new URLSearchParams({user_id:n,query:i,limit:String(s),offset:String(a)}).toString(),h=`${this.endpoints.conversations}/search?${u}`,c=await this.requestJson({method:"GET",path:h,timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??this.retries,signal:e.signal,allowRetry:!0});return{conversations:c.conversations,total:c.total,limit:c.limit,offset:c.offset,hasMore:c.total>a+c.conversations.length,query:c.query}}async updateConversation(t,e,n={}){var a;const i=t==null?void 0:t.trim();if(!i)throw new o("conversationId is required.");const s=(a=e.title)==null?void 0:a.trim();if(!s)throw new o("title is required.");return await this.ensureEndpoints(n),this.requestJson({method:"PATCH",path:`${this.endpoints.conversations}/${encodeURIComponent(i)}`,body:{title:s},timeoutMs:n.timeoutMs??this.timeoutMs,retries:n.retries??0,signal:n.signal,allowRetry:!1})}async getConversationMessages(t,e={}){var c;const n=(c=t.conversationId)==null?void 0:c.trim();if(!n)throw new o("conversationId is required.");const i=t.limit??200,s=t.offset??0;await this.ensureEndpoints(e);const a=new URLSearchParams({limit:String(i),offset:String(s)}).toString(),u=`${this.endpoints.conversations}/${encodeURIComponent(n)}/messages?${a}`,h=await this.requestJson({method:"GET",path:u,timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??this.retries,signal:e.signal,allowRetry:!0});return{conversation_id:h.conversation_id,messages:h.messages,total:h.total,limit:h.limit,offset:h.offset,hasMore:h.total>s+h.messages.length}}async chat(t,e={}){return E(t),await this.ensureEndpoints(e),this.requestJson({method:"POST",path:this.endpoints.chat,body:{message:t.message,conversation_id:t.conversation_id??"",user_id:t.user_id??this.defaultUserId,explicit_context:t.explicit_context,metadata:t.metadata??{}},timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??0,signal:e.signal,allowRetry:!1})}async chatStream(t,e={},n={}){E(t),await this.ensureEndpoints(n);const i=n.timeoutMs??this.timeoutMs,s=n.signal,a=new AbortController,u=setTimeout(()=>{a.abort()},i),h=M(s,a.signal);try{const c=await this.fetchFn(_(this.baseUrl,this.endpoints.stream),{method:"POST",headers:T(this.apiKey,{accept:"text/event-stream",contentType:"application/json"}),body:JSON.stringify({message:t.message,conversation_id:t.conversation_id??"",user_id:t.user_id??this.defaultUserId,explicit_context:t.explicit_context,metadata:t.metadata??{}}),signal:h});if(!c.ok)throw await S(c,this.endpoints.stream);if(!c.body)throw new o("Streaming response body is missing.");return await L({body:c.body,handlers:e,expectChatResponse:d=>this.expectChatResponse(d),toStreamError:d=>this.toStreamError(d)})}catch(c){throw R(c)?new o(`Streaming request timed out after ${i} ms.`):c instanceof o?c:new o(this.errorMessage(c,"Streaming request failed."))}finally{clearTimeout(u)}}async sendMessage(t,e={}){var a;const n={message:t,conversation_id:e.conversationId,user_id:e.userId,explicit_context:e.explicitContext,metadata:e.metadata};let i=(a=e.conversationId)==null?void 0:a.trim();!i&&e.autoCreateConversation&&(i=(await this.createConversation({user_id:e.userId??this.defaultUserId,title:e.conversationTitle??"New conversation"},e.requestOptions)).conversation_id,n.conversation_id=i);const s=await this.chat(n,e.requestOptions);return{response:s,conversationId:s.conversation_id||i||""}}async resolveServerEndpoints(t={}){const e=await this.requestJson({method:"GET",path:this.endpoints.info,timeoutMs:t.timeoutMs??this.timeoutMs,retries:t.retries??this.retries,signal:t.signal,allowRetry:!0}),n=x(e,this.baseUrl);return this.endpoints={...this.endpoints,...n},this.endpointsResolved=!0,{...this.endpoints}}async ensureEndpoints(t={}){this.endpointsResolved=await U({endpointsResolved:this.endpointsResolved,autoDiscoverEndpoints:this.autoDiscoverEndpoints,requestOptions:t,resolveServerEndpoints:e=>this.resolveServerEndpoints(e)})}requestJson(t){return z({baseUrl:this.baseUrl,apiKey:this.apiKey,fetchFn:this.fetchFn,retryBackoffMs:this.retryBackoffMs},t)}expectChatResponse(t){if(!t||typeof t!="object")throw new o("Invalid stream done payload: expected ChatResponse object.");const e=t;if(typeof e.response!="string"||typeof e.conversation_id!="string")throw new o("Invalid ChatResponse payload: missing required fields response/conversation_id.");return e}toStreamError(t){if(!t||typeof t!="object")return{error:"stream_error",detail:"Unknown stream error payload."};const e=t;return{error:typeof e.error=="string"?e.error:"stream_error",detail:typeof e.detail=="string"?e.detail:void 0}}errorMessage(t,e){return t instanceof Error&&t.message?t.message:e}}exports.JazzmineClient=C;exports.JazzmineClientError=o;exports.default=C;
|
package/dist/index.js
CHANGED
|
@@ -14,24 +14,24 @@ async function I(r) {
|
|
|
14
14
|
return !0;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const e = {},
|
|
19
|
-
if (!
|
|
17
|
+
function U(r, t) {
|
|
18
|
+
const e = {}, s = r == null ? void 0 : r.endpoints;
|
|
19
|
+
if (!s || typeof s != "object")
|
|
20
20
|
return e;
|
|
21
|
-
const
|
|
22
|
-
return
|
|
21
|
+
const i = m(s.chat, "POST", t), n = m(s.stream, "POST", t), a = m(s.conversations_create, "POST", t), u = m(s.health, "GET", t), h = m(s.info, "GET", t);
|
|
22
|
+
return i && (e.chat = i), n ? e.stream = n : i && (e.stream = `${i.replace(/\/+$/, "")}/stream`), a && (e.conversations = a), u && (e.health = u), h && (e.info = h), e;
|
|
23
23
|
}
|
|
24
24
|
function m(r, t, e) {
|
|
25
25
|
if (typeof r != "string")
|
|
26
26
|
return null;
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
27
|
+
const s = r.match(/^([A-Z]+)\s+(.+)$/i);
|
|
28
|
+
if (!s)
|
|
29
29
|
return null;
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
30
|
+
const i = s[1].toUpperCase(), n = s[2].trim();
|
|
31
|
+
if (i !== t.toUpperCase())
|
|
32
32
|
return null;
|
|
33
33
|
try {
|
|
34
|
-
const a = new URL(
|
|
34
|
+
const a = new URL(n, e);
|
|
35
35
|
return `${a.pathname}${a.search}`;
|
|
36
36
|
} catch {
|
|
37
37
|
return null;
|
|
@@ -52,15 +52,15 @@ function M(r, t) {
|
|
|
52
52
|
const e = AbortSignal.any;
|
|
53
53
|
if (typeof e == "function")
|
|
54
54
|
return e([r, t]);
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const s = new AbortController(), i = () => {
|
|
56
|
+
s.abort();
|
|
57
57
|
};
|
|
58
|
-
return r.aborted || t.aborted ? (
|
|
58
|
+
return r.aborted || t.aborted ? (s.abort(), s.signal) : (r.addEventListener("abort", i, { once: !0 }), t.addEventListener("abort", i, { once: !0 }), s.signal);
|
|
59
59
|
}
|
|
60
60
|
function R(r) {
|
|
61
61
|
return r instanceof DOMException && (r.name === "AbortError" || r.name === "TimeoutError");
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function x(r) {
|
|
64
64
|
const t = r.trim().replace(/\/+$/, "");
|
|
65
65
|
let e;
|
|
66
66
|
try {
|
|
@@ -84,7 +84,7 @@ function E(r) {
|
|
|
84
84
|
throw new o("chat payload requires a non-empty message string.");
|
|
85
85
|
if (r.explicit_context && !Array.isArray(r.explicit_context))
|
|
86
86
|
throw new o("explicit_context must be an array of strings.");
|
|
87
|
-
if (Array.isArray(r.explicit_context) && r.explicit_context.some((
|
|
87
|
+
if (Array.isArray(r.explicit_context) && r.explicit_context.some((s) => typeof s != "string"))
|
|
88
88
|
throw new o("explicit_context must contain only strings.");
|
|
89
89
|
if (r.metadata !== void 0 && (r.metadata === null || typeof r.metadata != "object"))
|
|
90
90
|
throw new o("metadata must be an object when provided.");
|
|
@@ -96,28 +96,28 @@ function J(r, t, e) {
|
|
|
96
96
|
throw new o(`${e} must be a positive number.`);
|
|
97
97
|
return Math.round(r);
|
|
98
98
|
}
|
|
99
|
-
function b(r, t, e,
|
|
99
|
+
function b(r, t, e, s, i) {
|
|
100
100
|
if (r === void 0)
|
|
101
101
|
return t;
|
|
102
|
-
if (!Number.isInteger(r) || r <
|
|
103
|
-
throw new o(`${e} must be an integer between ${
|
|
102
|
+
if (!Number.isInteger(r) || r < s || r > i)
|
|
103
|
+
throw new o(`${e} must be an integer between ${s} and ${i}.`);
|
|
104
104
|
return r;
|
|
105
105
|
}
|
|
106
106
|
async function k(r, t) {
|
|
107
107
|
const e = r * (t + 1);
|
|
108
|
-
e <= 0 || await new Promise((
|
|
108
|
+
e <= 0 || await new Promise((s) => setTimeout(s, e));
|
|
109
109
|
}
|
|
110
110
|
async function P(r) {
|
|
111
111
|
let t;
|
|
112
112
|
for (let e = 0; e <= r.retries; e += 1)
|
|
113
113
|
try {
|
|
114
114
|
return await r.runAttempt(e);
|
|
115
|
-
} catch (
|
|
116
|
-
if (t =
|
|
115
|
+
} catch (s) {
|
|
116
|
+
if (t = s, r.allowRetry && e < r.retries && r.shouldRetry(s)) {
|
|
117
117
|
await k(r.retryBackoffMs, e);
|
|
118
118
|
continue;
|
|
119
119
|
}
|
|
120
|
-
throw
|
|
120
|
+
throw s;
|
|
121
121
|
}
|
|
122
122
|
throw t;
|
|
123
123
|
}
|
|
@@ -139,22 +139,22 @@ async function N(r, t) {
|
|
|
139
139
|
allowRetry: t.allowRetry,
|
|
140
140
|
retryBackoffMs: r.retryBackoffMs,
|
|
141
141
|
runAttempt: async () => {
|
|
142
|
-
const e = new AbortController(),
|
|
142
|
+
const e = new AbortController(), s = setTimeout(() => {
|
|
143
143
|
e.abort();
|
|
144
|
-
}, t.timeoutMs),
|
|
144
|
+
}, t.timeoutMs), i = M(t.signal, e.signal);
|
|
145
145
|
try {
|
|
146
|
-
const
|
|
146
|
+
const n = await r.fetchFn(_(r.baseUrl, t.path), {
|
|
147
147
|
method: t.method,
|
|
148
148
|
headers: T(r.apiKey, {
|
|
149
149
|
accept: "application/json",
|
|
150
150
|
contentType: t.body !== void 0 ? "application/json" : void 0
|
|
151
151
|
}),
|
|
152
152
|
body: t.body !== void 0 ? JSON.stringify(t.body) : void 0,
|
|
153
|
-
signal:
|
|
153
|
+
signal: i
|
|
154
154
|
});
|
|
155
|
-
if (!
|
|
156
|
-
throw await S(
|
|
157
|
-
const a = await
|
|
155
|
+
if (!n.ok)
|
|
156
|
+
throw await S(n, t.path);
|
|
157
|
+
const a = await n.text();
|
|
158
158
|
if (!a.trim())
|
|
159
159
|
return {};
|
|
160
160
|
try {
|
|
@@ -164,18 +164,18 @@ async function N(r, t) {
|
|
|
164
164
|
`Expected JSON response from ${t.path}, but received invalid JSON.`
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
|
-
} catch (
|
|
168
|
-
throw R(
|
|
167
|
+
} catch (n) {
|
|
168
|
+
throw R(n) ? new p(t.timeoutMs) : n instanceof o ? n : n instanceof TypeError ? new y(v(n, "Network request failed.")) : new o(v(n, "Network request failed."));
|
|
169
169
|
} finally {
|
|
170
|
-
clearTimeout(
|
|
170
|
+
clearTimeout(s);
|
|
171
171
|
}
|
|
172
172
|
},
|
|
173
173
|
shouldRetry: (e) => {
|
|
174
174
|
if (e instanceof p || e instanceof y)
|
|
175
175
|
return !0;
|
|
176
176
|
if (e instanceof o) {
|
|
177
|
-
const
|
|
178
|
-
return
|
|
177
|
+
const s = e.status ?? 0;
|
|
178
|
+
return s === 429 || s >= 500;
|
|
179
179
|
}
|
|
180
180
|
return !1;
|
|
181
181
|
}
|
|
@@ -186,17 +186,17 @@ async function N(r, t) {
|
|
|
186
186
|
}
|
|
187
187
|
async function S(r, t) {
|
|
188
188
|
const e = await r.text();
|
|
189
|
-
let
|
|
189
|
+
let s;
|
|
190
190
|
if (e.trim())
|
|
191
191
|
try {
|
|
192
|
-
|
|
192
|
+
s = JSON.parse(e);
|
|
193
193
|
} catch {
|
|
194
|
-
|
|
194
|
+
s = e;
|
|
195
195
|
}
|
|
196
|
-
const
|
|
197
|
-
return new o(
|
|
196
|
+
const i = D(s), n = `HTTP ${r.status} on ${t}${i ? `: ${i}` : ""}`;
|
|
197
|
+
return new o(n, {
|
|
198
198
|
status: r.status,
|
|
199
|
-
details:
|
|
199
|
+
details: s
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
202
|
function T(r, t) {
|
|
@@ -212,64 +212,64 @@ function D(r) {
|
|
|
212
212
|
if (typeof r == "string")
|
|
213
213
|
return r.slice(0, 300);
|
|
214
214
|
if (typeof r == "object") {
|
|
215
|
-
const t = r, e = t.detail,
|
|
215
|
+
const t = r, e = t.detail, s = t.error;
|
|
216
216
|
if (typeof e == "string")
|
|
217
217
|
return e.slice(0, 300);
|
|
218
|
-
if (typeof
|
|
219
|
-
return
|
|
218
|
+
if (typeof s == "string")
|
|
219
|
+
return s.slice(0, 300);
|
|
220
220
|
}
|
|
221
221
|
return "";
|
|
222
222
|
}
|
|
223
223
|
function v(r, t) {
|
|
224
224
|
return r instanceof Error && r.message ? r.message : t;
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const t = r.split(/\r?\n/).map((
|
|
226
|
+
function L(r) {
|
|
227
|
+
const t = r.split(/\r?\n/).map((n) => n.trimEnd()).filter((n) => n.length > 0 && !n.startsWith(":"));
|
|
228
228
|
if (t.length === 0)
|
|
229
229
|
return null;
|
|
230
230
|
let e = "message";
|
|
231
|
-
const
|
|
232
|
-
for (const
|
|
233
|
-
if (
|
|
234
|
-
e =
|
|
231
|
+
const s = [];
|
|
232
|
+
for (const n of t) {
|
|
233
|
+
if (n.startsWith("event:")) {
|
|
234
|
+
e = n.slice(6).trim() || "message";
|
|
235
235
|
continue;
|
|
236
236
|
}
|
|
237
|
-
|
|
237
|
+
n.startsWith("data:") && s.push(n.slice(5).trim());
|
|
238
238
|
}
|
|
239
|
-
const
|
|
239
|
+
const i = s.join(`
|
|
240
240
|
`);
|
|
241
|
-
if (!
|
|
241
|
+
if (!i)
|
|
242
242
|
return { event: e, data: null };
|
|
243
243
|
try {
|
|
244
|
-
return { event: e, data: JSON.parse(
|
|
244
|
+
return { event: e, data: JSON.parse(i) };
|
|
245
245
|
} catch {
|
|
246
|
-
return { event: e, data:
|
|
246
|
+
return { event: e, data: i };
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
async function
|
|
250
|
-
var a,
|
|
251
|
-
const t = r.handlers ?? {}, e = r.body.getReader(),
|
|
252
|
-
let
|
|
249
|
+
async function j(r) {
|
|
250
|
+
var a, u, h, c;
|
|
251
|
+
const t = r.handlers ?? {}, e = r.body.getReader(), s = new TextDecoder("utf-8");
|
|
252
|
+
let i = "", n = null;
|
|
253
253
|
for (; ; ) {
|
|
254
|
-
const { done:
|
|
255
|
-
if (
|
|
254
|
+
const { done: d, value: w } = await e.read();
|
|
255
|
+
if (d)
|
|
256
256
|
break;
|
|
257
|
-
|
|
258
|
-
const g =
|
|
259
|
-
|
|
257
|
+
i += s.decode(w, { stream: !0 });
|
|
258
|
+
const g = i.split(/\n\n/);
|
|
259
|
+
i = g.pop() ?? "";
|
|
260
260
|
for (const $ of g) {
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
if ((a = t.onRawEvent) == null || a.call(t,
|
|
264
|
-
(
|
|
261
|
+
const l = L($);
|
|
262
|
+
if (l) {
|
|
263
|
+
if ((a = t.onRawEvent) == null || a.call(t, l.event, l.data), l.event === "intermediate") {
|
|
264
|
+
(u = t.onIntermediate) == null || u.call(t, l.data);
|
|
265
265
|
continue;
|
|
266
266
|
}
|
|
267
|
-
if (
|
|
268
|
-
|
|
267
|
+
if (l.event === "done") {
|
|
268
|
+
n = r.expectChatResponse(l.data), (h = t.onDone) == null || h.call(t, n);
|
|
269
269
|
continue;
|
|
270
270
|
}
|
|
271
|
-
if (
|
|
272
|
-
const f = r.toStreamError(
|
|
271
|
+
if (l.event === "error") {
|
|
272
|
+
const f = r.toStreamError(l.data);
|
|
273
273
|
throw (c = t.onErrorEvent) == null || c.call(t, f), new o(f.detail || f.error || "Stream error event received.", {
|
|
274
274
|
code: f.error,
|
|
275
275
|
details: f
|
|
@@ -278,13 +278,13 @@ async function F(r) {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
if (!
|
|
281
|
+
if (!n)
|
|
282
282
|
throw new o(
|
|
283
283
|
"Stream ended without a final done event containing ChatResponse."
|
|
284
284
|
);
|
|
285
|
-
return
|
|
285
|
+
return n;
|
|
286
286
|
}
|
|
287
|
-
const
|
|
287
|
+
const F = 2e4, B = 2, z = 350;
|
|
288
288
|
class q {
|
|
289
289
|
constructor(t, e = {}) {
|
|
290
290
|
if (this.endpointsResolved = !1, !t || !t.trim())
|
|
@@ -293,7 +293,7 @@ class q {
|
|
|
293
293
|
throw new o(
|
|
294
294
|
"fetch is not available in this runtime. Provide options.fetchImpl."
|
|
295
295
|
);
|
|
296
|
-
this.baseUrl =
|
|
296
|
+
this.baseUrl = x(t), this.apiKey = e.apiKey, this.timeoutMs = J(e.timeoutMs, F, "timeoutMs"), this.retries = b(e.retries, B, "retries", 0, 10), this.retryBackoffMs = b(
|
|
297
297
|
e.retryBackoffMs,
|
|
298
298
|
z,
|
|
299
299
|
"retryBackoffMs",
|
|
@@ -337,12 +337,12 @@ class q {
|
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
async deleteConversation(t, e = {}) {
|
|
340
|
-
const
|
|
341
|
-
if (!
|
|
340
|
+
const s = t == null ? void 0 : t.trim();
|
|
341
|
+
if (!s)
|
|
342
342
|
throw new o("conversationId is required.");
|
|
343
343
|
return await this.ensureEndpoints(e), this.requestJson({
|
|
344
344
|
method: "DELETE",
|
|
345
|
-
path: `${this.endpoints.conversations}/${encodeURIComponent(
|
|
345
|
+
path: `${this.endpoints.conversations}/${encodeURIComponent(s)}`,
|
|
346
346
|
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
347
347
|
retries: e.retries ?? this.retries,
|
|
348
348
|
signal: e.signal,
|
|
@@ -350,17 +350,17 @@ class q {
|
|
|
350
350
|
});
|
|
351
351
|
}
|
|
352
352
|
async listConversations(t, e = {}) {
|
|
353
|
-
var
|
|
354
|
-
const
|
|
355
|
-
if (!
|
|
353
|
+
var h;
|
|
354
|
+
const s = (h = t.userId) == null ? void 0 : h.trim();
|
|
355
|
+
if (!s)
|
|
356
356
|
throw new o("userId is required.");
|
|
357
|
-
const
|
|
357
|
+
const i = t.limit ?? 100, n = t.offset ?? 0;
|
|
358
358
|
await this.ensureEndpoints(e);
|
|
359
359
|
const a = new URLSearchParams({
|
|
360
|
-
user_id:
|
|
361
|
-
limit: String(
|
|
362
|
-
offset: String(
|
|
363
|
-
}).toString(),
|
|
360
|
+
user_id: s,
|
|
361
|
+
limit: String(i),
|
|
362
|
+
offset: String(n)
|
|
363
|
+
}).toString(), u = await this.requestJson({
|
|
364
364
|
method: "GET",
|
|
365
365
|
path: `${this.endpoints.conversations}?${a}`,
|
|
366
366
|
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
@@ -369,30 +369,30 @@ class q {
|
|
|
369
369
|
allowRetry: !0
|
|
370
370
|
});
|
|
371
371
|
return {
|
|
372
|
-
conversations:
|
|
373
|
-
total:
|
|
374
|
-
limit:
|
|
375
|
-
offset:
|
|
376
|
-
hasMore:
|
|
372
|
+
conversations: u.conversations,
|
|
373
|
+
total: u.total,
|
|
374
|
+
limit: u.limit,
|
|
375
|
+
offset: u.offset,
|
|
376
|
+
hasMore: u.total > n + u.conversations.length
|
|
377
377
|
};
|
|
378
378
|
}
|
|
379
379
|
async searchConversations(t, e = {}) {
|
|
380
|
-
var
|
|
381
|
-
const
|
|
382
|
-
if (!n)
|
|
383
|
-
throw new o("userId is required.");
|
|
380
|
+
var d, w;
|
|
381
|
+
const s = (d = t.userId) == null ? void 0 : d.trim(), i = (w = t.query) == null ? void 0 : w.trim();
|
|
384
382
|
if (!s)
|
|
383
|
+
throw new o("userId is required.");
|
|
384
|
+
if (!i)
|
|
385
385
|
throw new o("query is required.");
|
|
386
|
-
const
|
|
386
|
+
const n = t.limit ?? 100, a = t.offset ?? 0;
|
|
387
387
|
await this.ensureEndpoints(e);
|
|
388
|
-
const
|
|
389
|
-
user_id:
|
|
390
|
-
query:
|
|
391
|
-
limit: String(
|
|
388
|
+
const u = new URLSearchParams({
|
|
389
|
+
user_id: s,
|
|
390
|
+
query: i,
|
|
391
|
+
limit: String(n),
|
|
392
392
|
offset: String(a)
|
|
393
|
-
}).toString(),
|
|
393
|
+
}).toString(), h = `${this.endpoints.conversations}/search?${u}`, c = await this.requestJson({
|
|
394
394
|
method: "GET",
|
|
395
|
-
path:
|
|
395
|
+
path: h,
|
|
396
396
|
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
397
397
|
retries: e.retries ?? this.retries,
|
|
398
398
|
signal: e.signal,
|
|
@@ -407,24 +407,51 @@ class q {
|
|
|
407
407
|
query: c.query
|
|
408
408
|
};
|
|
409
409
|
}
|
|
410
|
-
async updateConversation(t, e,
|
|
410
|
+
async updateConversation(t, e, s = {}) {
|
|
411
411
|
var a;
|
|
412
|
-
const
|
|
413
|
-
if (!s)
|
|
414
|
-
throw new o("conversationId is required.");
|
|
415
|
-
const i = (a = e.title) == null ? void 0 : a.trim();
|
|
412
|
+
const i = t == null ? void 0 : t.trim();
|
|
416
413
|
if (!i)
|
|
414
|
+
throw new o("conversationId is required.");
|
|
415
|
+
const n = (a = e.title) == null ? void 0 : a.trim();
|
|
416
|
+
if (!n)
|
|
417
417
|
throw new o("title is required.");
|
|
418
|
-
return await this.ensureEndpoints(
|
|
418
|
+
return await this.ensureEndpoints(s), this.requestJson({
|
|
419
419
|
method: "PATCH",
|
|
420
|
-
path: `${this.endpoints.conversations}/${encodeURIComponent(
|
|
421
|
-
body: { title:
|
|
422
|
-
timeoutMs:
|
|
423
|
-
retries:
|
|
424
|
-
signal:
|
|
420
|
+
path: `${this.endpoints.conversations}/${encodeURIComponent(i)}`,
|
|
421
|
+
body: { title: n },
|
|
422
|
+
timeoutMs: s.timeoutMs ?? this.timeoutMs,
|
|
423
|
+
retries: s.retries ?? 0,
|
|
424
|
+
signal: s.signal,
|
|
425
425
|
allowRetry: !1
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
+
async getConversationMessages(t, e = {}) {
|
|
429
|
+
var c;
|
|
430
|
+
const s = (c = t.conversationId) == null ? void 0 : c.trim();
|
|
431
|
+
if (!s)
|
|
432
|
+
throw new o("conversationId is required.");
|
|
433
|
+
const i = t.limit ?? 200, n = t.offset ?? 0;
|
|
434
|
+
await this.ensureEndpoints(e);
|
|
435
|
+
const a = new URLSearchParams({
|
|
436
|
+
limit: String(i),
|
|
437
|
+
offset: String(n)
|
|
438
|
+
}).toString(), u = `${this.endpoints.conversations}/${encodeURIComponent(s)}/messages?${a}`, h = await this.requestJson({
|
|
439
|
+
method: "GET",
|
|
440
|
+
path: u,
|
|
441
|
+
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
442
|
+
retries: e.retries ?? this.retries,
|
|
443
|
+
signal: e.signal,
|
|
444
|
+
allowRetry: !0
|
|
445
|
+
});
|
|
446
|
+
return {
|
|
447
|
+
conversation_id: h.conversation_id,
|
|
448
|
+
messages: h.messages,
|
|
449
|
+
total: h.total,
|
|
450
|
+
limit: h.limit,
|
|
451
|
+
offset: h.offset,
|
|
452
|
+
hasMore: h.total > n + h.messages.length
|
|
453
|
+
};
|
|
454
|
+
}
|
|
428
455
|
async chat(t, e = {}) {
|
|
429
456
|
return E(t), await this.ensureEndpoints(e), this.requestJson({
|
|
430
457
|
method: "POST",
|
|
@@ -442,11 +469,11 @@ class q {
|
|
|
442
469
|
allowRetry: !1
|
|
443
470
|
});
|
|
444
471
|
}
|
|
445
|
-
async chatStream(t, e = {},
|
|
446
|
-
E(t), await this.ensureEndpoints(
|
|
447
|
-
const
|
|
472
|
+
async chatStream(t, e = {}, s = {}) {
|
|
473
|
+
E(t), await this.ensureEndpoints(s);
|
|
474
|
+
const i = s.timeoutMs ?? this.timeoutMs, n = s.signal, a = new AbortController(), u = setTimeout(() => {
|
|
448
475
|
a.abort();
|
|
449
|
-
},
|
|
476
|
+
}, i), h = M(n, a.signal);
|
|
450
477
|
try {
|
|
451
478
|
const c = await this.fetchFn(_(this.baseUrl, this.endpoints.stream), {
|
|
452
479
|
method: "POST",
|
|
@@ -461,43 +488,43 @@ class q {
|
|
|
461
488
|
explicit_context: t.explicit_context,
|
|
462
489
|
metadata: t.metadata ?? {}
|
|
463
490
|
}),
|
|
464
|
-
signal:
|
|
491
|
+
signal: h
|
|
465
492
|
});
|
|
466
493
|
if (!c.ok)
|
|
467
494
|
throw await S(c, this.endpoints.stream);
|
|
468
495
|
if (!c.body)
|
|
469
496
|
throw new o("Streaming response body is missing.");
|
|
470
|
-
return await
|
|
497
|
+
return await j({
|
|
471
498
|
body: c.body,
|
|
472
499
|
handlers: e,
|
|
473
|
-
expectChatResponse: (
|
|
474
|
-
toStreamError: (
|
|
500
|
+
expectChatResponse: (d) => this.expectChatResponse(d),
|
|
501
|
+
toStreamError: (d) => this.toStreamError(d)
|
|
475
502
|
});
|
|
476
503
|
} catch (c) {
|
|
477
|
-
throw R(c) ? new o(`Streaming request timed out after ${
|
|
504
|
+
throw R(c) ? new o(`Streaming request timed out after ${i} ms.`) : c instanceof o ? c : new o(this.errorMessage(c, "Streaming request failed."));
|
|
478
505
|
} finally {
|
|
479
|
-
clearTimeout(
|
|
506
|
+
clearTimeout(u);
|
|
480
507
|
}
|
|
481
508
|
}
|
|
482
509
|
async sendMessage(t, e = {}) {
|
|
483
510
|
var a;
|
|
484
|
-
const
|
|
511
|
+
const s = {
|
|
485
512
|
message: t,
|
|
486
513
|
conversation_id: e.conversationId,
|
|
487
514
|
user_id: e.userId,
|
|
488
515
|
explicit_context: e.explicitContext,
|
|
489
516
|
metadata: e.metadata
|
|
490
517
|
};
|
|
491
|
-
let
|
|
492
|
-
!
|
|
518
|
+
let i = (a = e.conversationId) == null ? void 0 : a.trim();
|
|
519
|
+
!i && e.autoCreateConversation && (i = (await this.createConversation(
|
|
493
520
|
{
|
|
494
521
|
user_id: e.userId ?? this.defaultUserId,
|
|
495
522
|
title: e.conversationTitle ?? "New conversation"
|
|
496
523
|
},
|
|
497
524
|
e.requestOptions
|
|
498
|
-
)).conversation_id,
|
|
499
|
-
const
|
|
500
|
-
return { response:
|
|
525
|
+
)).conversation_id, s.conversation_id = i);
|
|
526
|
+
const n = await this.chat(s, e.requestOptions);
|
|
527
|
+
return { response: n, conversationId: n.conversation_id || i || "" };
|
|
501
528
|
}
|
|
502
529
|
async resolveServerEndpoints(t = {}) {
|
|
503
530
|
const e = await this.requestJson({
|
|
@@ -507,10 +534,10 @@ class q {
|
|
|
507
534
|
retries: t.retries ?? this.retries,
|
|
508
535
|
signal: t.signal,
|
|
509
536
|
allowRetry: !0
|
|
510
|
-
}),
|
|
537
|
+
}), s = U(e, this.baseUrl);
|
|
511
538
|
return this.endpoints = {
|
|
512
539
|
...this.endpoints,
|
|
513
|
-
...
|
|
540
|
+
...s
|
|
514
541
|
}, this.endpointsResolved = !0, { ...this.endpoints };
|
|
515
542
|
}
|
|
516
543
|
async ensureEndpoints(t = {}) {
|
|
@@ -57,4 +57,32 @@ export interface ConversationPage {
|
|
|
57
57
|
hasMore: boolean;
|
|
58
58
|
query?: string;
|
|
59
59
|
}
|
|
60
|
+
export type MessageRole = "user" | "assistant" | "colleague_assistant" | "system";
|
|
61
|
+
export interface BackendMessage {
|
|
62
|
+
id: string;
|
|
63
|
+
conversation_id: string;
|
|
64
|
+
user_id: string;
|
|
65
|
+
role: MessageRole;
|
|
66
|
+
original_content: string;
|
|
67
|
+
enhanced_message: string;
|
|
68
|
+
explicit_context: string[] | null;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
invoked_flows: string[] | null;
|
|
71
|
+
invoked_tools: string[] | null;
|
|
72
|
+
errors: string[] | null;
|
|
73
|
+
is_flagged: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface ConversationMessagesParams {
|
|
76
|
+
conversationId: string;
|
|
77
|
+
limit?: number;
|
|
78
|
+
offset?: number;
|
|
79
|
+
}
|
|
80
|
+
export interface ConversationMessagesPage {
|
|
81
|
+
conversation_id: string;
|
|
82
|
+
messages: BackendMessage[];
|
|
83
|
+
total: number;
|
|
84
|
+
limit: number;
|
|
85
|
+
offset: number;
|
|
86
|
+
hasMore: boolean;
|
|
87
|
+
}
|
|
60
88
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/types/conversation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,C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CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/types/conversation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO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C;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './chat';
|
|
2
|
-
export type { ConversationCreateRequest, ConversationCreateResponse, ConversationDeleteResponse, ConversationListParams, ConversationSearchParams, ConversationUpdateRequest, ConversationUpdateResponse, ConversationListResponse, ConversationPage, } from './conversation';
|
|
2
|
+
export type { ConversationCreateRequest, ConversationCreateResponse, ConversationDeleteResponse, ConversationListParams, ConversationSearchParams, ConversationUpdateRequest, ConversationUpdateResponse, ConversationListResponse, ConversationPage, MessageRole, BackendMessage, ConversationMessagesParams, ConversationMessagesPage, } from './conversation';
|
|
3
3
|
export * from './health';
|
|
4
4
|
export * from './info';
|
|
5
5
|
export * from './options';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,YAAY,EACX,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,YAAY,EACX,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,GACxB,MAAM,gBAAgB,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
package/dist/types/info.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type InfoEndpointsMap = Partial<Record<"chat" | "stream" | "conversations_create" | "conversations_list" | "conversations_search" | "conversations_update" | "conversations_delete" | "health" | "info", string>>;
|
|
1
|
+
export type InfoEndpointsMap = Partial<Record<"chat" | "stream" | "conversations_create" | "conversations_list" | "conversations_search" | "conversations_update" | "conversations_delete" | "conversation_messages" | "health" | "info", string>>;
|
|
2
2
|
export interface InfoResponse {
|
|
3
3
|
agent_name: string;
|
|
4
4
|
agent_id: string;
|
package/dist/types/info.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../src/types/info.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,OAAO,CACpC,MAAM,CACF,MAAM,GACN,QAAQ,GACR,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,GACtB,sBAAsB,GACtB,sBAAsB,GACtB,QAAQ,GACR,MAAM,EACR,MAAM,CACP,CACF,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,gBAAgB,CAAC;CAC7B"}
|
|
1
|
+
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../src/types/info.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,OAAO,CACpC,MAAM,CACF,MAAM,GACN,QAAQ,GACR,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,GACtB,sBAAsB,GACtB,sBAAsB,GACtB,uBAAuB,GACvB,QAAQ,GACR,MAAM,EACR,MAAM,CACP,CACF,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,gBAAgB,CAAC;CAC7B"}
|