@keemakr/agent-sdk 0.1.0 → 0.3.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,44 @@ 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
+ }
50
+ /** Platform registry tools (Shape B) — defined in core, run server-side. */
51
+ export interface KeeTools {
52
+ /** List the registry tools this grant is entitled to. */
53
+ list(): Promise<Array<{
54
+ name: string;
55
+ description: string;
56
+ requiredScope?: string;
57
+ }>>;
58
+ /** Run a registry tool by name and return its result. Requires `tools:run`. */
59
+ run(name: string, args?: Record<string, unknown>): Promise<unknown>;
60
+ }
23
61
  export interface Kee {
24
62
  tenantId: string;
25
63
  scopes: string[];
@@ -27,6 +65,8 @@ export interface Kee {
27
65
  /** Explicit accessor (equivalent to kee.connections[provider]). */
28
66
  get(provider: string): KeeConnection;
29
67
  };
68
+ memory: KeeMemory;
69
+ tools: KeeTools;
30
70
  }
31
71
  /**
32
72
  * 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,47 @@ 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
+ const tools = {
109
+ async list() {
110
+ const json = (await capabilityFetch(grant, 'tools', undefined, 'GET'));
111
+ return json.tools ?? [];
112
+ },
113
+ async run(name, args) {
114
+ const json = (await capabilityFetch(grant, `tools/${encodeURIComponent(name)}`, {
115
+ args: args ?? {},
116
+ }));
117
+ return json.result;
118
+ },
119
+ };
120
+ return { tenantId: grant.tenantId, scopes: grant.scopes, connections, memory, tools };
78
121
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
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 KeeTools, type MemoryEntry, } from './client.js';
3
+ export { keemakrToolDirectory } from './tool-directory.js';
package/dist/index.js CHANGED
@@ -9,4 +9,5 @@
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';
13
+ export { keemakrToolDirectory } from './tool-directory.js';
@@ -0,0 +1 @@
1
+ export declare const keemakrToolDirectory: import("eve/tools").DynamicSentinel;
@@ -0,0 +1,61 @@
1
+ // keemakrToolDirectory — a defineDynamic file that surfaces the platform's
2
+ // registry tools (Shape B) to an agent at session start, with NO redeploy.
3
+ //
4
+ // Drop it into your agent in one line:
5
+ // // agent/tools/keemakr-directory.ts
6
+ // export { keemakrToolDirectory as default } from '@keemakr/agent-sdk/tool-directory';
7
+ //
8
+ // On session.started it reads the verified grant off the session, asks
9
+ // keemakr-core which registry tools this install is entitled to, and synthesizes
10
+ // one delegation tool per entry. Each synthesized tool's execute calls
11
+ // useKee(ctx).tools.run(name, args) — so the tool runs IN CORE, governed
12
+ // centrally: a fix or a new tool in core's registry reaches every agent next
13
+ // session, no redeploy here. Mirrors keemakr-core's marketplace-dispatch.ts.
14
+ import { defineDynamic, defineTool } from 'eve/tools';
15
+ import { z } from 'zod';
16
+ import { useKee } from './client.js';
17
+ export const keemakrToolDirectory = defineDynamic({
18
+ events: {
19
+ 'session.started': async (_event, ctx) => {
20
+ // No grant on the session (e.g. local dev without grantAuth) → no tools.
21
+ let kee;
22
+ try {
23
+ kee = useKee(ctx);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ let entries;
29
+ try {
30
+ entries = await kee.tools.list();
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ if (!entries.length)
36
+ return null;
37
+ // One delegation tool per entitled registry tool. The args are passed
38
+ // through as a generic object; core validates them against the tool's real
39
+ // schema and returns a typed error if they don't fit. (Names are namespaced
40
+ // `kee__<name>` to avoid colliding with the agent's own tools.)
41
+ const pairs = entries.map((t) => {
42
+ const name = t.name;
43
+ const tool = defineTool({
44
+ description: `${t.description} (keemakr platform tool, runs server-side)`,
45
+ inputSchema: z.object({
46
+ args: z
47
+ .record(z.string(), z.unknown())
48
+ .optional()
49
+ .describe('Arguments for the tool, per its description.'),
50
+ }),
51
+ execute: async ({ args }) => {
52
+ const result = await useKee(ctx).tools.run(name, args ?? {});
53
+ return { ok: true, tool: name, result };
54
+ },
55
+ });
56
+ return [`kee__${name.replace(/[^a-z0-9]+/gi, '_')}`, tool];
57
+ });
58
+ return Object.fromEntries(pairs);
59
+ },
60
+ },
61
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@keemakr/agent-sdk",
3
- "version": "0.1.0",
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.",
3
+ "version": "0.3.0",
4
+ "description": "The floor for keemakr marketplace agents: verify the capability grant and reach tenant connections, memory, and shared platform tools through keemakr-core — without holding raw secrets or resolving the tenant yourself.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -10,6 +10,10 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js"
13
+ },
14
+ "./tool-directory": {
15
+ "types": "./dist/tool-directory.d.ts",
16
+ "import": "./dist/tool-directory.js"
13
17
  }
14
18
  },
15
19
  "files": [