ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
60 lines (59 loc) • 1.58 kB
JavaScript
class _ {
constructor(s = {}) {
var n;
if (this.config = s, s.request) {
const r = typeof s.request == "function" ? s.request() : s.request;
if (!r.manual)
throw new Error("request must be manual");
this._request = r, this._originalCallbacks = (n = r.options) == null ? void 0 : n.callbacks;
}
}
get request() {
return this._request;
}
get hasRequest() {
return !!this._request;
}
getMessages() {
var s;
return ((s = this._getMessagesFn) == null ? void 0 : s.call(this)) ?? [];
}
injectGetMessages(s) {
this._getMessagesFn = s;
}
/**
* Wire useXChat stream handlers into the owned manual request callbacks.
*/
injectRequest({
onUpdate: s,
onSuccess: n,
onError: r
}) {
var c, l, g;
if (!this._request)
throw new Error("provider.request is not configured");
const a = (c = this._originalCallbacks) == null ? void 0 : c.onUpdate, o = (l = this._originalCallbacks) == null ? void 0 : l.onSuccess, u = (g = this._originalCallbacks) == null ? void 0 : g.onError;
this._request.options.callbacks = {
onUpdate: (t, e) => {
const i = s(t, e);
a && a(t, e, i);
},
onSuccess: (t, e) => {
const i = n(t, e);
o && o(t, e, i);
},
onError: (t, e, i) => {
const h = r(t, e);
u && u(t, e, i, h);
}
};
}
/** Ready-to-use transformMessage for useXChat */
asTransformMessage() {
return (s) => this.transformMessage(s);
}
}
export {
_ as AbstractChatProvider,
_ as default
};