@artmate/chat
Version:
借鉴字节开源react库AntX,通过vue实现的版本
49 lines (48 loc) • 1.23 kB
JavaScript
import { computed as h, unref as p } from "vue";
import f from "../artRequest/index.js";
let u = 0;
class q {
constructor(s) {
this.requestingMap = {}, this.request = (e, n) => {
const { request: r } = this.config, { onUpdate: c, onSuccess: a, onError: g } = n, t = u;
u += 1, this.requestingMap[t] = !0, r == null || r(e, {
// Status should be unique.
// One get success or error should not get more message
onUpdate: (i) => {
this.requestingMap[t] && c(i);
},
onSuccess: (i) => {
this.requestingMap[t] && (a(i), this.finishRequest(t));
},
onError: (i) => {
this.requestingMap[t] && (g(i), this.finishRequest(t));
}
});
}, this.config = s;
}
finishRequest(s) {
delete this.requestingMap[s];
}
isRequesting() {
return Object.keys(this.requestingMap).length > 0;
}
}
function m(o) {
const { request: s, ...e } = o, n = h(
() => [
new q({
request: s || f({
baseURL: e.baseURL,
model: e.model,
dangerouslyApiKey: e.dangerouslyApiKey
}).create,
...e
})
]
);
return p(n);
}
export {
q as ArtAgent,
m as default
};