@keemakr/agent-sdk 0.1.0 → 0.2.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/dist/client.d.ts CHANGED
@@ -20,6 +20,33 @@ export interface KeeConnection {
20
20
  account_label: string | null;
21
21
  }>;
22
22
  }
23
+ /** One stored memory entry. */
24
+ export interface MemoryEntry {
25
+ namespace: string;
26
+ key: string;
27
+ value: unknown;
28
+ written_by_agent: string | null;
29
+ created_at: string;
30
+ updated_at: string;
31
+ }
32
+ /**
33
+ * Cross-session, tenant-owned key-value memory. TENANT-SHARED: any of the
34
+ * tenant's installed agents can read/write any namespace. For per-session working
35
+ * memory use eve's defineState instead — this is for state that must outlive the
36
+ * session. Requires the `memory:rw` scope.
37
+ */
38
+ export interface KeeMemory {
39
+ /** Read a key's value, or null if absent. */
40
+ get(namespace: string, key: string): Promise<unknown | null>;
41
+ /** Read the full entry (value + provenance + timestamps), or null. */
42
+ getEntry(namespace: string, key: string): Promise<MemoryEntry | null>;
43
+ /** Write a key. Returns the stored entry. */
44
+ set(namespace: string, key: string, value: unknown): Promise<MemoryEntry>;
45
+ /** Delete a key. Returns whether it existed. */
46
+ delete(namespace: string, key: string): Promise<boolean>;
47
+ /** List every entry in a namespace (tenant-wide). */
48
+ list(namespace: string): Promise<MemoryEntry[]>;
49
+ }
23
50
  export interface Kee {
24
51
  tenantId: string;
25
52
  scopes: string[];
@@ -27,6 +54,7 @@ export interface Kee {
27
54
  /** Explicit accessor (equivalent to kee.connections[provider]). */
28
55
  get(provider: string): KeeConnection;
29
56
  };
57
+ memory: KeeMemory;
30
58
  }
31
59
  /**
32
60
  * Build a tenant-scoped capability client from a tool's context. Call inside a
package/dist/client.js CHANGED
@@ -32,16 +32,17 @@ function coreBaseUrl() {
32
32
  return jwks.replace(/\/\.well-known\/jwks\.json\/?$/, '');
33
33
  throw keeError('KEE_CORE_URL (or KEE_CORE_JWKS_URL) must be set to reach the Capability API');
34
34
  }
35
- async function capabilityFetch(grant, path, body) {
35
+ async function capabilityFetch(grant, path, body, method = 'POST') {
36
36
  const url = `${coreBaseUrl()}/api/capability/${path}`;
37
+ const hasBody = method !== 'GET' && method !== 'DELETE';
37
38
  const res = await fetch(url, {
38
- method: 'POST',
39
+ method,
39
40
  headers: {
40
- 'content-type': 'application/json',
41
+ ...(hasBody ? { 'content-type': 'application/json' } : {}),
41
42
  authorization: `Bearer ${grant.token}`,
42
43
  ...(grant.traceId ? { 'x-keemakr-trace-id': grant.traceId } : {}),
43
44
  },
44
- body: JSON.stringify(body ?? {}),
45
+ ...(hasBody ? { body: JSON.stringify(body ?? {}) } : {}),
45
46
  });
46
47
  const json = (await res.json().catch(() => ({})));
47
48
  if (!res.ok) {
@@ -74,5 +75,35 @@ export function useKee(ctx) {
74
75
  return connectionFor(prop);
75
76
  },
76
77
  });
77
- return { tenantId: grant.tenantId, scopes: grant.scopes, connections };
78
+ const enc = encodeURIComponent;
79
+ const memory = {
80
+ async getEntry(namespace, key) {
81
+ try {
82
+ const json = (await capabilityFetch(grant, `memory/${enc(namespace)}/${enc(key)}`, undefined, 'GET'));
83
+ return json.entry ?? null;
84
+ }
85
+ catch (e) {
86
+ if (e.status === 404)
87
+ return null;
88
+ throw e;
89
+ }
90
+ },
91
+ async get(namespace, key) {
92
+ const entry = await this.getEntry(namespace, key);
93
+ return entry ? entry.value : null;
94
+ },
95
+ async set(namespace, key, value) {
96
+ const json = (await capabilityFetch(grant, `memory/${enc(namespace)}/${enc(key)}`, { value }, 'PUT'));
97
+ return json.entry;
98
+ },
99
+ async delete(namespace, key) {
100
+ const json = (await capabilityFetch(grant, `memory/${enc(namespace)}/${enc(key)}`, undefined, 'DELETE'));
101
+ return !!json.deleted;
102
+ },
103
+ async list(namespace) {
104
+ const json = (await capabilityFetch(grant, `memory/${enc(namespace)}`, undefined, 'GET'));
105
+ return json.entries ?? [];
106
+ },
107
+ };
108
+ return { tenantId: grant.tenantId, scopes: grant.scopes, connections, memory };
78
109
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { grantAuth } from './grant-auth.js';
2
- export { useKee, type Kee, type KeeConnection, type KeeContext, type KeeError } from './client.js';
2
+ export { useKee, type Kee, type KeeConnection, type KeeContext, type KeeError, type KeeMemory, type MemoryEntry, } from './client.js';
package/dist/index.js CHANGED
@@ -9,4 +9,4 @@
9
9
  // const kee = useKee(ctx);
10
10
  // const r = await kee.connections.hunter.call('email-finder', { domain, first_name, last_name });
11
11
  export { grantAuth } from './grant-auth.js';
12
- export { useKee } from './client.js';
12
+ export { useKee, } from './client.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/agent-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "The floor for keemakr marketplace agents: verify the capability grant and reach tenant connections (and, soon, memory and shared tools) through keemakr-core — without holding raw secrets or resolving the tenant yourself.",
5
5
  "license": "MIT",
6
6
  "type": "module",