@keemakr/agent-sdk 0.10.0 → 0.12.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
@@ -19,13 +19,21 @@ Peer dependencies (match your eve agent): `eve@0.13.0`, `jose@^6.2.3`.
19
19
 
20
20
  Set these in your deployed agent's environment:
21
21
 
22
- | Variable | Purpose |
23
- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
24
- | `KEE_CORE_JWKS_URL` | keemakr-core's JWKS endpoint, e.g. `https://app.keemakr.com/.well-known/jwks.json`. Enables grant verification. |
25
- | `KEE_AGENT_AUDIENCE` | This deployment's audience — your runtime URL's origin, e.g. `https://my-agent.example.com`. Must match the audience the operator mints. |
26
- | `KEE_CORE_URL` | keemakr-core's base URL for capability calls, e.g. `https://app.keemakr.com`. (Derived from `KEE_CORE_JWKS_URL` if unset.) |
27
-
28
- If `KEE_CORE_JWKS_URL` is unset, `grantAuth()` skips entirely useful during local development.
22
+ | Variable | Purpose |
23
+ | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | `KEE_CORE_URL` | **Required.** The keemakr platform you installed on, e.g. `https://dash.dev.keemakr.ai`. Used both to verify grants and to call the capability API. |
25
+ | `KEE_AGENT_AUDIENCE` | This deployment's audience — your runtime URL's origin, e.g. `https://my-agent.example.com`. Must match the audience the operator mints. |
26
+ | `KEE_CORE_JWKS_URL` | Only when the JWKS is not at `<KEE_CORE_URL>/.well-known/jwks.json`. Takes precedence over `KEE_CORE_URL` for verification. |
27
+
28
+ **There is no default platform, deliberately.** `KEE_CORE_URL` names the keys your
29
+ agent trusts and the host it sends the tenant's grant token to. A compiled-in
30
+ default would mean this package picking your trust anchor for you — and since the
31
+ same published SDK is installed against dev, staging and production, whichever
32
+ origin it named would be wrong for the others. Set one variable per deployment.
33
+
34
+ With neither set, `grantAuth()` refuses every grant and logs once explaining why,
35
+ and `coreBaseUrl()` throws rather than posting a live credential somewhere you did
36
+ not choose. Both name the variables in their message.
29
37
 
30
38
  ## 1. Verify the grant in your channel
31
39
 
@@ -142,13 +150,17 @@ via `kee.kb`.
142
150
 
143
151
  ```ts
144
152
  const hits = await kee.kb.search('what is our refund policy?', { k: 5 });
145
- // → [{ text, score, provenance: { title, source_uri, … } }]
153
+ // → [{ text, score, artifact_id, version_id, chunk_id, title,
154
+ // audience, visibility, provenance }]
146
155
  ```
147
156
 
148
- Scoped server-side to the collections bound to your agent + the tenant's
149
- default corpus + the shared platform KB (`kb:retrieve` scope, granted to every
150
- install). Hybrid retrieval, reranked in core; `text` may be a wider parent
151
- context for clause-level documents.
157
+ Core derives the retrieval actor from the verified grant. A Kee acting for a
158
+ user can retrieve that user's Personal Knowledge plus Organization and Platform
159
+ Knowledge. A System Kee can retrieve Organization and Platform Knowledge but
160
+ never Personal Knowledge. External Kees are additionally restricted to External
161
+ Safe knowledge. Collections organize artifacts but never grant access
162
+ (`kb:retrieve` scope, granted to every install). Retrieval is hybrid and may be
163
+ reranked in Core; `text` may be a wider parent context.
152
164
 
153
165
  ### Platform tools
154
166
 
package/dist/client.d.ts CHANGED
@@ -112,13 +112,17 @@ export interface KeeMemory {
112
112
  export interface KBHit {
113
113
  text: string;
114
114
  score: number;
115
+ artifact_id: string;
116
+ version_id: string;
117
+ chunk_id: string;
118
+ title: string;
119
+ audience: 'personal' | 'organization' | 'platform';
120
+ visibility: 'internal_only' | 'external_safe';
115
121
  provenance: Record<string, unknown>;
116
122
  }
117
123
  /**
118
- * Tenant knowledge-base retrieval. The agent sees the collections bound to it
119
- * plus the tenant's default corpus plus the shared platform KB — scoping is
120
- * enforced server-side from the grant. Requires the `kb:retrieve` scope
121
- * (granted to every install).
124
+ * Governed Company Brain retrieval. Core derives User, System, or External Kee access from the
125
+ * verified grant and returns source identities suitable for citations. Requires `kb:retrieve`.
122
126
  */
123
127
  export interface KeeKb {
124
128
  /** Semantic + lexical + reranked search over the agent-visible knowledge. */
@@ -182,6 +186,31 @@ export interface KeeTools {
182
186
  /** Run a registry tool by name and return its result. Requires `tools:run`. */
183
187
  run(name: string, args?: Record<string, unknown>): Promise<unknown>;
184
188
  }
189
+ /**
190
+ * The entry's STAFF-SET platform settings — one value per `kind:'env'`
191
+ * dependency it declares. Requires the `config:read` scope, which that same
192
+ * declaration mints.
193
+ *
194
+ * These are operator settings (a destination address, a shared endpoint), not
195
+ * tenant data and not secrets the agent may change: the surface is read-only by
196
+ * design. An operator sets them once in the platform console and they apply to
197
+ * every install of the entry.
198
+ */
199
+ export interface KeeConfig {
200
+ /** One setting, or null when staff have not set it yet. */
201
+ get(key: string): Promise<string | null>;
202
+ /**
203
+ * Every declared setting at once — `{ config, declared }`. `declared` lists
204
+ * the keys this entry asks for, so "staff haven't set it" (declared, missing
205
+ * from config) stays distinguishable from "this entry has no such setting"
206
+ * (absent from declared). Collapsing those two is what makes a configuration
207
+ * gap look like a runtime bug.
208
+ */
209
+ all(): Promise<{
210
+ config: Record<string, string>;
211
+ declared: string[];
212
+ }>;
213
+ }
185
214
  export interface Kee {
186
215
  tenantId: string;
187
216
  scopes: string[];
@@ -193,6 +222,7 @@ export interface Kee {
193
222
  records: KeeRecords;
194
223
  kb: KeeKb;
195
224
  tools: KeeTools;
225
+ config: KeeConfig;
196
226
  }
197
227
  /**
198
228
  * Build a tenant-scoped capability client from a tool's context. Call inside a
package/dist/client.js CHANGED
@@ -278,7 +278,7 @@ export function useKee(ctx) {
278
278
  async search(query, opts) {
279
279
  const json = (await capabilityFetch(grant, 'kb/retrieve', {
280
280
  query,
281
- k: opts?.k,
281
+ limit: opts?.k,
282
282
  }));
283
283
  return json.hits ?? [];
284
284
  },
@@ -295,6 +295,30 @@ export function useKee(ctx) {
295
295
  return json.result;
296
296
  },
297
297
  };
298
+ // One fetch serves both accessors, and the result is cached for the life of
299
+ // this client: settings change at operator pace, not per tool call, and a
300
+ // `get()` per setting inside one tool would re-fetch the same map N times.
301
+ let configOnce = null;
302
+ const config = {
303
+ async all() {
304
+ configOnce ??= (async () => {
305
+ const json = (await capabilityFetch(grant, 'config', undefined, 'GET'));
306
+ return { config: json.config ?? {}, declared: json.declared ?? [] };
307
+ })();
308
+ try {
309
+ return await configOnce;
310
+ }
311
+ catch (e) {
312
+ // Don't cache a failure — a transient error must not poison every later
313
+ // read for the rest of the session.
314
+ configOnce = null;
315
+ throw e;
316
+ }
317
+ },
318
+ async get(key) {
319
+ return (await this.all()).config[key] ?? null;
320
+ },
321
+ };
298
322
  return {
299
323
  tenantId: grant.tenantId,
300
324
  scopes: grant.scopes,
@@ -303,5 +327,6 @@ export function useKee(ctx) {
303
327
  records,
304
328
  kb,
305
329
  tools,
330
+ config,
306
331
  };
307
332
  }