@aidenhq/sdk 0.5.5 → 0.5.7
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 +1 -1
- package/dist/src/event-send.d.ts +4 -2
- package/dist/src/event-send.js +28 -10
- package/dist/src/provider.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Every module imports it, the official ones in this repo included: a service depe
|
|
|
13
13
|
(`"@aidenhq/sdk": "X.Y.Z"`), its `bun.lock` pins the integrity, and its `bunfig.toml` names `minimumReleaseAgeExcludes =
|
|
14
14
|
["@aidenhq/sdk"]` (our own scope is exempt from the 7-day rule, so a pin may be the day it is published). Not everything here
|
|
15
15
|
is on that path: the AI reviewer's service (its eval runs from a bare snapshot), the check recipes and the engineer image (no install step) and
|
|
16
|
-
the engines' `sdk/` folders (each runs from its module folder alone) and two files the kernel loads from the checkout (code review's `config.ts`, the merge gate) still hold copies (`scripts/sync-shared.ts`).
|
|
16
|
+
the engines' `sdk/` folders (each runs from its module folder alone) and two files the kernel loads from the checkout (code review's `config.ts`, the merge gate) still hold copies (`scripts/sync-shared.ts`). The kernel and compile import the SDK's source by path.
|
|
17
17
|
|
|
18
18
|
## Releasing
|
|
19
19
|
|
package/dist/src/event-send.d.ts
CHANGED
|
@@ -25,8 +25,10 @@ export type SendResult = {
|
|
|
25
25
|
export declare const SEND_EVENTS = 500, SEND_BYTES = 1000000;
|
|
26
26
|
/**
|
|
27
27
|
* Sends `events` oldest first. A 200 answers each event: a refusal (the kernel's schema refused it) is returned, every other
|
|
28
|
-
* event is sent (logged, or a duplicate of one logged).
|
|
29
|
-
*
|
|
28
|
+
* event is sent (logged, or a duplicate of one logged). An event that cannot fit a batch on its own is refused up front as
|
|
29
|
+
* `too large` and never posted, so it cannot hold back the events after it. Any other answer (no answer, a whole-batch 4xx,
|
|
30
|
+
* 429, 5xx) sends and refuses nothing from that batch on: the caller keeps them and tries again (after `retryAfterMs` when the
|
|
31
|
+
* kernel said so).
|
|
30
32
|
*/
|
|
31
33
|
export declare function sendEvents(post: EventPost, events: SourceEventLike[]): Promise<SendResult>;
|
|
32
34
|
/** A small durable store for a source with none of its own: a JSON file, replaced whole by an atomic rename. */
|
package/dist/src/event-send.js
CHANGED
|
@@ -3,14 +3,29 @@
|
|
|
3
3
|
// (scripts/sync-shared.ts: edit this one and run it). Node built-ins only.
|
|
4
4
|
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
5
|
export const SEND_EVENTS = 500, SEND_BYTES = 1_000_000;
|
|
6
|
-
/**
|
|
6
|
+
/** An event's serialized size in a batch: its JSON and the comma after it. */
|
|
7
|
+
function size(e) { return Buffer.byteLength(JSON.stringify(e)) + 1; }
|
|
8
|
+
/**
|
|
9
|
+
* An event's own batch as the kernel limits it: `events.ingest` refuses a list over `SEND_BYTES` (`kernel/src/events.ts`), so a
|
|
10
|
+
* singleton array is the smallest request that can carry the event. The JSON envelope around it is inside the kernel's body cap.
|
|
11
|
+
*/
|
|
12
|
+
function alone(e) { return Buffer.byteLength(JSON.stringify([e])); }
|
|
13
|
+
/**
|
|
14
|
+
* `events` cut into the kernel's batch limits, in order. An event the kernel would refuse as a batch of one is refused here,
|
|
15
|
+
* never batched: the kernel refuses the whole request it is in, so batching it would block every event behind it. The test is
|
|
16
|
+
* against the kernel's list limit, not the batching cushion: an event too big to group is still sent alone, as before.
|
|
17
|
+
*/
|
|
7
18
|
function chunks(events) {
|
|
8
|
-
const
|
|
19
|
+
const batches = [], refused = [];
|
|
9
20
|
let cur = [], bytes = 0;
|
|
10
21
|
for (const e of events) {
|
|
11
|
-
const n =
|
|
22
|
+
const n = size(e);
|
|
23
|
+
if (alone(e) > SEND_BYTES) {
|
|
24
|
+
refused.push({ id: e.id, why: "too large" });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
12
27
|
if (cur.length && (cur.length >= SEND_EVENTS || bytes + n > SEND_BYTES - 100)) {
|
|
13
|
-
|
|
28
|
+
batches.push(cur);
|
|
14
29
|
cur = [];
|
|
15
30
|
bytes = 0;
|
|
16
31
|
}
|
|
@@ -18,17 +33,20 @@ function chunks(events) {
|
|
|
18
33
|
bytes += n;
|
|
19
34
|
}
|
|
20
35
|
if (cur.length)
|
|
21
|
-
|
|
22
|
-
return
|
|
36
|
+
batches.push(cur);
|
|
37
|
+
return { batches, refused };
|
|
23
38
|
}
|
|
24
39
|
/**
|
|
25
40
|
* Sends `events` oldest first. A 200 answers each event: a refusal (the kernel's schema refused it) is returned, every other
|
|
26
|
-
* event is sent (logged, or a duplicate of one logged).
|
|
27
|
-
*
|
|
41
|
+
* event is sent (logged, or a duplicate of one logged). An event that cannot fit a batch on its own is refused up front as
|
|
42
|
+
* `too large` and never posted, so it cannot hold back the events after it. Any other answer (no answer, a whole-batch 4xx,
|
|
43
|
+
* 429, 5xx) sends and refuses nothing from that batch on: the caller keeps them and tries again (after `retryAfterMs` when the
|
|
44
|
+
* kernel said so).
|
|
28
45
|
*/
|
|
29
46
|
export async function sendEvents(post, events) {
|
|
30
|
-
const
|
|
31
|
-
|
|
47
|
+
const { batches, refused } = chunks(events);
|
|
48
|
+
const out = { sent: [], refused };
|
|
49
|
+
for (const batch of batches) {
|
|
32
50
|
const r = await post({ events: batch }).catch(() => ({ status: 0, json: undefined, retryAfterS: undefined }));
|
|
33
51
|
if (r.status !== 200) {
|
|
34
52
|
if (r.retryAfterS !== undefined)
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -44,10 +44,14 @@ export type ProviderState = {
|
|
|
44
44
|
privacy_ack?: string;
|
|
45
45
|
/** When the model step finished: the provider was signed in and its probe passed. Latched: a quota stop or an expired sign-in never clears it. */
|
|
46
46
|
ready?: string;
|
|
47
|
+
/** A pause of `kind` that began `at`: `credential` is the login generation the failing attempt ran under, so a pause from a
|
|
48
|
+
* superseded login is ignored and a late unpause from that login can't clear the current one. Absent: the switch pause, or one no
|
|
49
|
+
* credential names, which clears as before. */
|
|
47
50
|
paused?: {
|
|
48
51
|
kind: "quota" | "auth" | "switch";
|
|
49
52
|
until?: string;
|
|
50
53
|
at: string;
|
|
54
|
+
credential?: string;
|
|
51
55
|
};
|
|
52
56
|
};
|
|
53
57
|
/** Which engine conversation a resumable session belongs to: one from another provider, account or engine never resumes. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidenhq/sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "The shared code of AidenHQ modules: contract types, engine IO, the caller check and fence, write executors, the reviewer side, the judges' models and call, the source writer and the vendor MCP pass-through.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|