@aidenhq/sdk 0.4.3 → 0.5.0

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 CHANGED
@@ -4,11 +4,16 @@ The code AidenHQ modules share, one copy on npm. MIT. Entry points: `types`, `en
4
4
  `caller` and `fence` (every module server: the kernel's caller assertion and the untrusted-text fence), `executor` (write
5
5
  kinds), `reviewer` (reviewer@1), `judge` (the judges' model call), `responses` and `provider` (the one streaming Responses reader, the roles a caller names and the error kinds), `paperclip` (the Paperclip HTTP client), `source-store` (source writers; `pg` is a peer
6
6
  dependency) and `vendor/proxy`, `vendor/oauth`, `vendor/needs` (vendor connections; the MCP SDK, zod and pino are peer dependencies).
7
+ Also exported (0.5.0): `kernel-client` (the module-to-kernel client), `tools-client` (the box's MCP client), `tiers` (risk tiers), `checks`
8
+ (how check results are read), `repeat` (a repeat read's "unchanged" answer and size-bounded pages), `owner-day`, `attribution`,
9
+ `maintained-repos`, `instance-paths`, `instance-details`, `pass-rule`, `box-bundle`, `pin-owner`, `churn`, `closed-event`, `for-others`,
10
+ `model-text`, `quality`, `task-state-types` and `agent-paused`.
7
11
 
8
12
  Every module imports it, the official ones in this repo included: a service depends on an exact version
9
13
  (`"@aidenhq/sdk": "X.Y.Z"`), its `bun.lock` pins the integrity, and its `bunfig.toml` names `minimumReleaseAgeExcludes =
10
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
11
- is on that path yet: the files `scripts/sync-shared.ts` still copies are not imported from npm.
15
+ is on that path yet: the files `scripts/sync-shared.ts` still copies (the AI reviewer's service and the check recipes, which run with no
16
+ install step; the code host, still being moved) are not imported from npm.
12
17
 
13
18
  ## Releasing
14
19
 
@@ -1,3 +1,4 @@
1
+ const RESTART_WAIT_MS = 20_000;
1
2
  export class PaperclipError extends Error {
2
3
  status;
3
4
  body;
@@ -22,12 +23,47 @@ function errorMessage(text) {
22
23
  export function paperclipClient({ url, token, lane, headers, timeoutMs = 20_000, fetcher = fetch }) {
23
24
  const prefix = (method) => (lane === "owner" ? (method === "GET" ? "/v1/cp/read" : "/v1/cp/owner") : lane === "agent" ? "/v1/cp/agent" : "");
24
25
  /** The raw response, for a body that isn't JSON (an upload's form, a file's bytes). */
25
- const send = (method, path, init = {}) => fetcher(new URL(`${prefix(method)}${path}`, url), {
26
+ const once = (method, path, init) => fetcher(new URL(`${prefix(method)}${path}`, url), {
26
27
  method,
27
28
  headers: { authorization: `Bearer ${token}`, accept: "application/json", ...(init.type ? { "content-type": init.type } : {}), ...headers?.(method) },
28
29
  body: init.body,
29
30
  signal: AbortSignal.timeout(init.timeoutMs ?? timeoutMs),
30
31
  });
32
+ // A read rides out a Paperclip restart (an apply): a 503 or a refused connection is retried for up to RESTART_WAIT_MS,
33
+ // honouring retry-after. A write is sent once. The caller's own timeout is the first attempt's; each retry's attempt is bounded
34
+ // by what is left of the deadline, so a stalled request can't outlast it.
35
+ const send = async (method, path, init = {}) => {
36
+ const until = Date.now() + RESTART_WAIT_MS;
37
+ for (let attempt = init.timeoutMs;;) {
38
+ let res, down;
39
+ try {
40
+ res = await once(method, path, attempt === undefined ? init : { ...init, timeoutMs: attempt });
41
+ }
42
+ catch (e) {
43
+ if (method !== "GET" || !(e instanceof TypeError))
44
+ throw e;
45
+ down = e;
46
+ }
47
+ if (res && (res.status !== 503 || method !== "GET"))
48
+ return res;
49
+ const ra = Number(res?.headers.get("retry-after") ?? "");
50
+ const wait = Math.max(200, (res?.headers.get("retry-after") && ra >= 0 ? ra : 1) * 1000);
51
+ if (Date.now() + wait >= until) {
52
+ if (res)
53
+ return res;
54
+ throw down;
55
+ }
56
+ await res?.body?.cancel();
57
+ await new Promise((r) => setTimeout(r, wait));
58
+ const left = until - Date.now();
59
+ if (left <= 0) {
60
+ if (res)
61
+ return res;
62
+ throw down;
63
+ }
64
+ attempt = Math.min(init.timeoutMs ?? timeoutMs, left);
65
+ }
66
+ };
31
67
  const fail = async (res, method, path) => {
32
68
  const text = await res.text();
33
69
  let body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidenhq/sdk",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
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": {
@@ -31,6 +31,26 @@
31
31
  "./source-store": "./dist/src/source-store.js",
32
32
  "./vendor/proxy": "./dist/src/vendor/proxy.js",
33
33
  "./vendor/oauth": "./dist/src/vendor/oauth.js",
34
+ "./agent-paused": "./dist/src/agent-paused.js",
35
+ "./attribution": "./dist/src/attribution.js",
36
+ "./box-bundle": "./dist/src/box-bundle.js",
37
+ "./checks": "./dist/src/checks.js",
38
+ "./churn": "./dist/src/churn.js",
39
+ "./closed-event": "./dist/src/closed-event.js",
40
+ "./for-others": "./dist/src/for-others.js",
41
+ "./instance-details": "./dist/src/instance-details.js",
42
+ "./instance-paths": "./dist/src/instance-paths.js",
43
+ "./kernel-client": "./dist/src/kernel-client.js",
44
+ "./maintained-repos": "./dist/src/maintained-repos.js",
45
+ "./model-text": "./dist/src/model-text.js",
46
+ "./owner-day": "./dist/src/owner-day.js",
47
+ "./pass-rule": "./dist/src/pass-rule.js",
48
+ "./pin-owner": "./dist/src/pin-owner.js",
49
+ "./quality": "./dist/src/quality.js",
50
+ "./repeat": "./dist/src/repeat.js",
51
+ "./task-state-types": "./dist/src/task-state-types.js",
52
+ "./tiers": "./dist/src/tiers.js",
53
+ "./tools-client": "./dist/src/tools-client.js",
34
54
  "./vendor/needs": "./dist/src/vendor/needs.js"
35
55
  },
36
56
  "files": ["dist", "LICENSE"],