@keemakr/agent-sdk 0.2.0 → 0.4.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 +19 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +21 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/tool-directory.d.ts +1 -0
- package/dist/tool-directory.js +61 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -82,6 +82,25 @@ await kee.connections.get("hunter").call("email-finder", { ... }); // equivalent
|
|
|
82
82
|
const { access_token } = await kee.connections.hunter.token();
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
### Memory (cross-session, tenant-shared)
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
await kee.memory.set("prefs", "tone", { tone: "formal" });
|
|
89
|
+
await kee.memory.get("prefs", "tone"); // → { tone: "formal" }
|
|
90
|
+
await kee.memory.list("prefs"); // → entries in the namespace
|
|
91
|
+
await kee.memory.delete("prefs", "tone");
|
|
92
|
+
// Semantic search by meaning (embeddings):
|
|
93
|
+
const hits = await kee.memory.search("how should I speak to the user?", { limit: 5 });
|
|
94
|
+
// → [{ namespace, key, value, score, … }] (score 0–1, nearest first)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Platform tools
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
await kee.tools.list(); // tools this grant is entitled to
|
|
101
|
+
await kee.tools.run("current-time"); // run one in keemakr-core
|
|
102
|
+
```
|
|
103
|
+
|
|
85
104
|
A call whose grant lacks the required scope returns a `KeeError` with `status: 403`; an expired/invalid grant returns `status: 401`.
|
|
86
105
|
|
|
87
106
|
## Security model
|
package/dist/client.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ export interface MemoryEntry {
|
|
|
35
35
|
* memory use eve's defineState instead — this is for state that must outlive the
|
|
36
36
|
* session. Requires the `memory:rw` scope.
|
|
37
37
|
*/
|
|
38
|
+
/** A semantic-search hit — a memory entry with its similarity score. */
|
|
39
|
+
export interface MemorySearchHit extends MemoryEntry {
|
|
40
|
+
/** Cosine similarity in [0,1] (1 = identical). */
|
|
41
|
+
score: number;
|
|
42
|
+
}
|
|
38
43
|
export interface KeeMemory {
|
|
39
44
|
/** Read a key's value, or null if absent. */
|
|
40
45
|
get(namespace: string, key: string): Promise<unknown | null>;
|
|
@@ -46,6 +51,22 @@ export interface KeeMemory {
|
|
|
46
51
|
delete(namespace: string, key: string): Promise<boolean>;
|
|
47
52
|
/** List every entry in a namespace (tenant-wide). */
|
|
48
53
|
list(namespace: string): Promise<MemoryEntry[]>;
|
|
54
|
+
/** Semantic search by meaning. Optionally scope to a namespace. */
|
|
55
|
+
search(query: string, opts?: {
|
|
56
|
+
namespace?: string;
|
|
57
|
+
limit?: number;
|
|
58
|
+
}): Promise<MemorySearchHit[]>;
|
|
59
|
+
}
|
|
60
|
+
/** Platform registry tools (Shape B) — defined in core, run server-side. */
|
|
61
|
+
export interface KeeTools {
|
|
62
|
+
/** List the registry tools this grant is entitled to. */
|
|
63
|
+
list(): Promise<Array<{
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
requiredScope?: string;
|
|
67
|
+
}>>;
|
|
68
|
+
/** Run a registry tool by name and return its result. Requires `tools:run`. */
|
|
69
|
+
run(name: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
49
70
|
}
|
|
50
71
|
export interface Kee {
|
|
51
72
|
tenantId: string;
|
|
@@ -55,6 +76,7 @@ export interface Kee {
|
|
|
55
76
|
get(provider: string): KeeConnection;
|
|
56
77
|
};
|
|
57
78
|
memory: KeeMemory;
|
|
79
|
+
tools: KeeTools;
|
|
58
80
|
}
|
|
59
81
|
/**
|
|
60
82
|
* Build a tenant-scoped capability client from a tool's context. Call inside a
|
package/dist/client.js
CHANGED
|
@@ -104,6 +104,26 @@ export function useKee(ctx) {
|
|
|
104
104
|
const json = (await capabilityFetch(grant, `memory/${enc(namespace)}`, undefined, 'GET'));
|
|
105
105
|
return json.entries ?? [];
|
|
106
106
|
},
|
|
107
|
+
async search(query, opts) {
|
|
108
|
+
const json = (await capabilityFetch(grant, 'memory/search', {
|
|
109
|
+
query,
|
|
110
|
+
namespace: opts?.namespace,
|
|
111
|
+
limit: opts?.limit,
|
|
112
|
+
}));
|
|
113
|
+
return json.hits ?? [];
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
const tools = {
|
|
117
|
+
async list() {
|
|
118
|
+
const json = (await capabilityFetch(grant, 'tools', undefined, 'GET'));
|
|
119
|
+
return json.tools ?? [];
|
|
120
|
+
},
|
|
121
|
+
async run(name, args) {
|
|
122
|
+
const json = (await capabilityFetch(grant, `tools/${encodeURIComponent(name)}`, {
|
|
123
|
+
args: args ?? {},
|
|
124
|
+
}));
|
|
125
|
+
return json.result;
|
|
126
|
+
},
|
|
107
127
|
};
|
|
108
|
-
return { tenantId: grant.tenantId, scopes: grant.scopes, connections, memory };
|
|
128
|
+
return { tenantId: grant.tenantId, scopes: grant.scopes, connections, memory, tools };
|
|
109
129
|
}
|
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, type KeeMemory, type MemoryEntry, } from './client.js';
|
|
2
|
+
export { useKee, type Kee, type KeeConnection, type KeeContext, type KeeError, type KeeMemory, type KeeTools, type MemoryEntry, type MemorySearchHit, } from './client.js';
|
|
3
|
+
export { keemakrToolDirectory } from './tool-directory.js';
|
package/dist/index.js
CHANGED
|
@@ -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.
|
|
4
|
-
"description": "The floor for keemakr marketplace agents: verify the capability grant and reach tenant connections
|
|
3
|
+
"version": "0.4.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": [
|