@kindgi/capabilities 0.1.8-rc.0 → 0.1.9-rc.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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * An adapter's SDK clients, one per key it was called with. Calls that
3
+ * take turns with two keys (a run in each of two projects, each project
4
+ * with a key of its own) each reuse their own client, and whatever it
5
+ * holds (an auth client, a token), where a single slot would build a client
6
+ * on every turn. A rotated key builds a new client; the old one goes once
7
+ * `max` newer keys are used.
8
+ *
9
+ * Held by a SHA-256 of the key, never the key itself. At most `max`
10
+ * clients (default 16), the least recently used dropped first.
11
+ *
12
+ * Node only (`node:crypto`): it's the `@kindgi/capabilities/clients-by-key`
13
+ * entry, apart from the package's runtime-neutral main entry.
14
+ */
15
+ export interface ClientsByKey<C> {
16
+ /** The client for `key`: the one built for it before, else `build()`'s, kept. */
17
+ get(key: string, build: () => C): C;
18
+ }
19
+ export declare function createClientsByKey<C>(max?: number): ClientsByKey<C>;
20
+ //# sourceMappingURL=clients-by-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clients-by-key.d.ts","sourceRoot":"","sources":["../src/clients-by-key.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,iFAAiF;IACjF,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CACrC;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,GAAG,SAAK,GAAG,YAAY,CAAC,CAAC,CAAC,CAwB/D"}
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { createHash } from 'node:crypto';
4
+ export function createClientsByKey(max = 16) {
5
+ if (!Number.isInteger(max) || max < 1) {
6
+ throw new RangeError(`createClientsByKey: max must be a whole number, 1 or more, not ${max}`);
7
+ }
8
+ // A Map keeps insertion order: an entry set again is the newest.
9
+ const clients = new Map();
10
+ return {
11
+ get(key, build) {
12
+ const id = createHash('sha256').update(key).digest('base64url');
13
+ const known = clients.get(id);
14
+ if (known !== undefined) {
15
+ clients.delete(id);
16
+ clients.set(id, known);
17
+ return known;
18
+ }
19
+ const client = build();
20
+ clients.set(id, client);
21
+ if (clients.size > max) {
22
+ const oldest = clients.keys().next();
23
+ if (oldest.done !== true)
24
+ clients.delete(oldest.value);
25
+ }
26
+ return client;
27
+ },
28
+ };
29
+ }
30
+ //# sourceMappingURL=clients-by-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clients-by-key.js","sourceRoot":"","sources":["../src/clients-by-key.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqBzC,MAAM,UAAU,kBAAkB,CAAI,GAAG,GAAG,EAAE;IAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CAAC,kEAAkE,GAAG,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,iEAAiE;IACjE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAa,CAAC;IACrC,OAAO;QACL,GAAG,CAAC,GAAG,EAAE,KAAK;YACZ,MAAM,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAChE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBACnB,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YACxB,IAAI,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC;gBACvB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;gBACrC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;oBAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kindgi/capabilities",
3
- "version": "0.1.8-rc.0",
3
+ "version": "0.1.9-rc.0",
4
4
  "description": "Capability declarations + provider router for Kindgi™. Agents declare what they need from a model (features such as structured-output or tool-use, context window, cost, region, latency, provider and model allow/deny lists) and what they prefer; the router picks a registered (provider, model) pair that satisfies every hard constraint plus tenant policy, ranked by soft preferences, and reports per requirement which candidates it rejected when none qualify. Also the provider-neutral ModelProvider contract, a tenant-scoped provider registry, and an adapter-factory registry. Capability kinds are open strings matched by equality; llm-inference is the default.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -26,6 +26,11 @@
26
26
  "import": "./dist/attempts.js",
27
27
  "default": "./dist/attempts.js"
28
28
  },
29
+ "./clients-by-key": {
30
+ "types": "./dist/clients-by-key.d.ts",
31
+ "import": "./dist/clients-by-key.js",
32
+ "default": "./dist/clients-by-key.js"
33
+ },
29
34
  "./tool-names": {
30
35
  "types": "./dist/tool-names.d.ts",
31
36
  "import": "./dist/tool-names.js",
@@ -40,12 +45,12 @@
40
45
  "type-manifest.json"
41
46
  ],
42
47
  "dependencies": {
43
- "@kindgi/platform": "0.1.8-rc.0",
44
- "@kindgi/schema": "0.1.8-rc.0",
45
- "@kindgi/types": "0.1.8-rc.0"
48
+ "@kindgi/platform": "0.1.9-rc.0",
49
+ "@kindgi/schema": "0.1.9-rc.0",
50
+ "@kindgi/types": "0.1.9-rc.0"
46
51
  },
47
52
  "devDependencies": {
48
- "@kindgi/specs": "0.1.8-rc.0",
53
+ "@kindgi/specs": "0.1.9-rc.0",
49
54
  "@types/node": "^22.10.5",
50
55
  "typescript": "^5.7.3",
51
56
  "vitest": "^2.1.8"
@@ -0,0 +1,49 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import { createHash } from 'node:crypto';
5
+
6
+ /**
7
+ * An adapter's SDK clients, one per key it was called with. Calls that
8
+ * take turns with two keys (a run in each of two projects, each project
9
+ * with a key of its own) each reuse their own client, and whatever it
10
+ * holds (an auth client, a token), where a single slot would build a client
11
+ * on every turn. A rotated key builds a new client; the old one goes once
12
+ * `max` newer keys are used.
13
+ *
14
+ * Held by a SHA-256 of the key, never the key itself. At most `max`
15
+ * clients (default 16), the least recently used dropped first.
16
+ *
17
+ * Node only (`node:crypto`): it's the `@kindgi/capabilities/clients-by-key`
18
+ * entry, apart from the package's runtime-neutral main entry.
19
+ */
20
+ export interface ClientsByKey<C> {
21
+ /** The client for `key`: the one built for it before, else `build()`'s, kept. */
22
+ get(key: string, build: () => C): C;
23
+ }
24
+
25
+ export function createClientsByKey<C>(max = 16): ClientsByKey<C> {
26
+ if (!Number.isInteger(max) || max < 1) {
27
+ throw new RangeError(`createClientsByKey: max must be a whole number, 1 or more, not ${max}`);
28
+ }
29
+ // A Map keeps insertion order: an entry set again is the newest.
30
+ const clients = new Map<string, C>();
31
+ return {
32
+ get(key, build) {
33
+ const id = createHash('sha256').update(key).digest('base64url');
34
+ const known = clients.get(id);
35
+ if (known !== undefined) {
36
+ clients.delete(id);
37
+ clients.set(id, known);
38
+ return known;
39
+ }
40
+ const client = build();
41
+ clients.set(id, client);
42
+ if (clients.size > max) {
43
+ const oldest = clients.keys().next();
44
+ if (oldest.done !== true) clients.delete(oldest.value);
45
+ }
46
+ return client;
47
+ },
48
+ };
49
+ }