@zimtsui/typechat 0.0.138 → 0.0.140
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/build/adaptor.js +1 -1
- package/build/throttle.d.ts +2 -2
- package/build/throttle.js +66 -7
- package/build/throttle.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/build/adaptor.js
CHANGED
|
@@ -20,7 +20,7 @@ export class Adaptor {
|
|
|
20
20
|
}
|
|
21
21
|
[Symbol.dispose]() {
|
|
22
22
|
for (const throttle of this.throttles.values())
|
|
23
|
-
throttle.
|
|
23
|
+
throttle.abort(new Error('Adaptor disposed'));
|
|
24
24
|
}
|
|
25
25
|
makeEngine(adaptorOptions) {
|
|
26
26
|
const endpointConfig = this.config.endpoints[adaptorOptions.endpoint];
|
package/build/throttle.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { InferenceContext } from './inference-context.ts';
|
|
|
2
2
|
import { Mutex } from '@zimtsui/typelocks';
|
|
3
3
|
export declare class Throttle {
|
|
4
4
|
protected rpm: number;
|
|
5
|
-
protected valve: Mutex
|
|
5
|
+
protected valve: Mutex.Void;
|
|
6
6
|
protected timer: NodeJS.Timeout | null;
|
|
7
7
|
protected interval: number;
|
|
8
8
|
constructor(rpm: number);
|
|
9
9
|
requests(wfctx: InferenceContext): Promise<void>;
|
|
10
|
-
|
|
10
|
+
abort(e: unknown): void;
|
|
11
11
|
}
|
package/build/throttle.js
CHANGED
|
@@ -1,7 +1,59 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { Mutex } from '@zimtsui/typelocks';
|
|
2
54
|
export class Throttle {
|
|
3
55
|
rpm;
|
|
4
|
-
valve = Mutex.
|
|
56
|
+
valve = new Mutex.Void();
|
|
5
57
|
timer = null;
|
|
6
58
|
interval;
|
|
7
59
|
constructor(rpm) {
|
|
@@ -9,10 +61,11 @@ export class Throttle {
|
|
|
9
61
|
this.interval = Math.ceil(60 * 1000 / this.rpm);
|
|
10
62
|
}
|
|
11
63
|
async requests(wfctx) {
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
await wfctx.busy?.acquireRead();
|
|
64
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
15
65
|
try {
|
|
66
|
+
if (this.interval === 0)
|
|
67
|
+
return;
|
|
68
|
+
const busyRaii = __addDisposableResource(env_1, await wfctx.busy?.acquireReadRaii(wfctx.signal), true);
|
|
16
69
|
wfctx.signal?.throwIfAborted();
|
|
17
70
|
const waiting = this.valve.acquire()
|
|
18
71
|
.then(() => {
|
|
@@ -26,14 +79,20 @@ export class Throttle {
|
|
|
26
79
|
wfctx.signal?.addEventListener('abort', reject, { signal: wfctx.signal });
|
|
27
80
|
});
|
|
28
81
|
}
|
|
82
|
+
catch (e_1) {
|
|
83
|
+
env_1.error = e_1;
|
|
84
|
+
env_1.hasError = true;
|
|
85
|
+
}
|
|
29
86
|
finally {
|
|
30
|
-
|
|
87
|
+
const result_1 = __disposeResources(env_1);
|
|
88
|
+
if (result_1)
|
|
89
|
+
await result_1;
|
|
31
90
|
}
|
|
32
91
|
}
|
|
33
|
-
|
|
92
|
+
abort(e) {
|
|
34
93
|
if (this.timer)
|
|
35
94
|
clearTimeout(this.timer);
|
|
36
|
-
this.valve.
|
|
95
|
+
this.valve.abort(e);
|
|
37
96
|
}
|
|
38
97
|
}
|
|
39
98
|
//# sourceMappingURL=throttle.js.map
|
package/build/throttle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../src/throttle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,OAAO,QAAQ;IAIY;IAHnB,KAAK,GAAG,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../src/throttle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,OAAO,QAAQ;IAIY;IAHnB,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;IACzB,KAAK,GAA0B,IAAI,CAAC;IACpC,QAAQ,CAAS;IAC3B,YAA6B,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;QACpC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,KAAuB;;;YACzC,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC;gBAAE,OAAO;YAEhC,MAAY,QAAQ,kCAAG,MAAM,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,OAAA,CAAC;YAEvE,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YAE/B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;iBAC/B,IAAI,CAAC,GAAG,EAAE;gBACP,IAAI,CAAC,KAAK,GAAG,UAAU,CACnB,GAAG,EAAE;oBACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;oBAClB,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC9B,CAAC,EACD,IAAI,CAAC,QAAQ,CAChB,CAAC;YACN,CAAC,CAAC,CAAC;YAEP,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACxC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC9B,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;;;;;;;;;;;KAEN;IAEM,KAAK,CAAC,CAAU;QACnB,IAAI,IAAI,CAAC,KAAK;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;CACJ"}
|