@muhkoo/connect 0.4.0-alpha.1 → 0.6.0-alpha.1
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 +40 -10
- package/dist/browser/index.js +268 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/connect.d.ts +263 -4
- package/dist/server/index.js +268 -3
- package/dist/server/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Client SDK for the Muhkoo Accelerator. The headline surface is a single
|
|
4
4
|
**`Client`** that hangs everything off its namespaces —
|
|
5
|
-
`client.auth` / `client.kv` / `client.
|
|
6
|
-
`client.space` / `client.agents` / `client.functions` —
|
|
5
|
+
`client.auth` / `client.kv` / `client.db` / `client.storage` /
|
|
6
|
+
`client.message` / `client.space` / `client.agents` / `client.functions` —
|
|
7
|
+
backed by
|
|
7
8
|
end-to-end-encrypted messaging (fan-out group channels with history, plus Double
|
|
8
9
|
Ratchet + ECDH P-384 for direct messages), ZK identity + personal/shared spaces,
|
|
9
|
-
server-side Programmable Agents, developer-authored serverless functions, and
|
|
10
|
-
|
|
10
|
+
server-side Programmable Agents, developer-authored serverless functions, and an
|
|
11
|
+
edge-compatible Groth16 verifier — all bundled from a single
|
|
11
12
|
TypeScript source tree.
|
|
12
13
|
|
|
13
14
|
See [`CHANGELOG.md`](./CHANGELOG.md) for what's new.
|
|
@@ -18,10 +19,17 @@ See [`CHANGELOG.md`](./CHANGELOG.md) for what's new.
|
|
|
18
19
|
## What's in the box
|
|
19
20
|
|
|
20
21
|
- **`Client`** — the unified entry point. `new Client({ apiKey, baseUrl })`
|
|
21
|
-
exposes `auth` (ZK register/login), `
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
exposes, over one shared session: `auth` (ZK register/login), `kv` (per-user
|
|
23
|
+
encrypted key/value), `db` (the app's scalable database), `storage` (encrypted
|
|
24
|
+
files), `message` (pub/sub + E2E direct messages), `space` (fan-out group
|
|
25
|
+
channels with history), `agents` (server-side Programmable Agents), and
|
|
26
|
+
`functions` (developer-authored serverless functions). This is the supported
|
|
27
|
+
surface; everything below is a building block it composes.
|
|
28
|
+
|
|
29
|
+
- **App-describing decorators** — `@MuhkooAgent` / `@MuhkooSpace` / `@MuhkooDB` /
|
|
30
|
+
`@MuhkooFunction` annotate a plain class with your app's agent-facing surface;
|
|
31
|
+
`ejectAgentPrompt()` / `ejectAgentTools()` turn that into a `systemPrompt` +
|
|
32
|
+
tool allowlist for a Programmable Agent. See the [agents reference](https://docs.muhkoo.dev/reference/agents/).
|
|
25
33
|
|
|
26
34
|
- **`BroadcastChannel`** — multi-peer end-to-end-encrypted "room". Wires
|
|
27
35
|
`WSTransport` (socket lifecycle, reconnect, offline queue) together with
|
|
@@ -191,7 +199,7 @@ await client.space.roster(space.id); // member identity pubkeys
|
|
|
191
199
|
```
|
|
192
200
|
|
|
193
201
|
**Programmable Agents (`client.agents`).** Server-side "virtual users" backed by
|
|
194
|
-
|
|
202
|
+
the edge AI runtime: an app editor gives an agent a persona (system prompt), a
|
|
195
203
|
model, and **triggers** (e.g. reply on @-mention), then enables it per-Space;
|
|
196
204
|
members chat with it inside that Space. Management is session-authed (owner or
|
|
197
205
|
Space editor) and **paid-tier-only**. Enabling an agent on a Space makes that
|
|
@@ -202,7 +210,7 @@ blind.
|
|
|
202
210
|
const { config } = await client.agents.create(appId, {
|
|
203
211
|
handle: "@assistant",
|
|
204
212
|
displayName: "Assistant",
|
|
205
|
-
model: "
|
|
213
|
+
model: "meta/llama-3.1-8b-instruct",
|
|
206
214
|
systemPrompt: "You are a concise, friendly teammate in this Space.",
|
|
207
215
|
triggers: [{ type: "mention" }],
|
|
208
216
|
});
|
|
@@ -210,6 +218,28 @@ await client.agents.enable(appId, config.agentId, space.id); // per-Space opt-i
|
|
|
210
218
|
// list / update / delete / disable also available.
|
|
211
219
|
```
|
|
212
220
|
|
|
221
|
+
Give the agent **tools** (a function-calling loop over the app's database,
|
|
222
|
+
functions, and channels) by passing `tools` — requires a function-calling
|
|
223
|
+
`model`. Generate both the prompt and the tool allowlist from decorators:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { MuhkooAgent, MuhkooSpace, MuhkooDB, ejectAgentPrompt, ejectAgentTools } from "@muhkoo/connect";
|
|
227
|
+
|
|
228
|
+
@MuhkooAgent({ name: "Assistant", purpose: "A helpful teammate in this chat." })
|
|
229
|
+
class ChatApp {
|
|
230
|
+
@MuhkooSpace({ description: "Main team discussion." }) general!: string;
|
|
231
|
+
@MuhkooDB({ access: "read", description: "Chat message history." }) messages!: unknown;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
await client.agents.create(appId, {
|
|
235
|
+
handle: "@assistant",
|
|
236
|
+
displayName: "Assistant",
|
|
237
|
+
model: "openai/gpt-oss-120b", // a function-calling model
|
|
238
|
+
systemPrompt: ejectAgentPrompt(ChatApp),
|
|
239
|
+
tools: ejectAgentTools(ChatApp),
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
213
243
|
**Serverless Functions (`client.functions`).** Deploy your own code that runs on
|
|
214
244
|
the accelerator. A function is an untrusted single-module ES worker
|
|
215
245
|
(`export default { fetch }`) with two triggers: **HTTP** (reachable at its own
|
package/dist/browser/index.js
CHANGED
|
@@ -5305,6 +5305,92 @@ class KvNamespace {
|
|
|
5305
5305
|
}
|
|
5306
5306
|
}
|
|
5307
5307
|
|
|
5308
|
+
/**
|
|
5309
|
+
* `client.db` — the app's scalable database. A developer defines tables in the
|
|
5310
|
+
* Muhkoo portal (columns + indexes); each table is backed by its own Durable
|
|
5311
|
+
* Object SQLite instance and reachable through a sanitized REST gateway. This
|
|
5312
|
+
* namespace wraps that gateway:
|
|
5313
|
+
*
|
|
5314
|
+
* const todos = client.db.table('todos');
|
|
5315
|
+
* const { id } = await todos.insert({ title: 'Buy milk', done: false });
|
|
5316
|
+
* const one = await todos.get(id);
|
|
5317
|
+
* const { rows, nextCursor } = await todos.query({
|
|
5318
|
+
* where: [{ column: 'done', op: 'eq', value: false }],
|
|
5319
|
+
* orderBy: { column: 'rank', dir: 'asc' },
|
|
5320
|
+
* limit: 50,
|
|
5321
|
+
* });
|
|
5322
|
+
* await todos.update(id, { done: true });
|
|
5323
|
+
* await todos.delete(id);
|
|
5324
|
+
*
|
|
5325
|
+
* Authorization is the **app key** ({@link HttpClient} stamps it on every
|
|
5326
|
+
* request); the appId + environment are resolved server-side from the key, so a
|
|
5327
|
+
* key can only ever reach its own app's tables. The front end never touches the
|
|
5328
|
+
* database directly — this REST surface is the only gateway, and all input is
|
|
5329
|
+
* validated against the table's schema (parameterized statements, column +
|
|
5330
|
+
* operator allowlists). There is no raw-SQL passthrough.
|
|
5331
|
+
*
|
|
5332
|
+
* Schema is authored in the portal, not here (the SDK reads + writes rows, it
|
|
5333
|
+
* doesn't create tables). Pagination is keyset-based: pass the `nextCursor` from
|
|
5334
|
+
* a previous `query()` back as `cursor` to fetch the next page.
|
|
5335
|
+
*/
|
|
5336
|
+
/** A handle to one table — the ergonomic surface for row operations. */
|
|
5337
|
+
class DbTable {
|
|
5338
|
+
http;
|
|
5339
|
+
name;
|
|
5340
|
+
constructor(http, name) {
|
|
5341
|
+
this.http = http;
|
|
5342
|
+
this.name = name;
|
|
5343
|
+
}
|
|
5344
|
+
base() {
|
|
5345
|
+
return `/api/db/${encodeURIComponent(this.name)}`;
|
|
5346
|
+
}
|
|
5347
|
+
/** Insert a row. Returns the created row and its primary-key value. */
|
|
5348
|
+
async insert(values) {
|
|
5349
|
+
return this.http.post(this.base(), { values });
|
|
5350
|
+
}
|
|
5351
|
+
/** Fetch a row by primary key, or `null` if it doesn't exist. */
|
|
5352
|
+
async get(id) {
|
|
5353
|
+
try {
|
|
5354
|
+
const res = await this.http.get(`${this.base()}/${encodeURIComponent(String(id))}`);
|
|
5355
|
+
return res.row;
|
|
5356
|
+
}
|
|
5357
|
+
catch (e) {
|
|
5358
|
+
if (e?.status === 404)
|
|
5359
|
+
return null;
|
|
5360
|
+
throw e;
|
|
5361
|
+
}
|
|
5362
|
+
}
|
|
5363
|
+
/** Query rows with filters, ordering, and keyset pagination. */
|
|
5364
|
+
async query(query = {}) {
|
|
5365
|
+
return this.http.post(`${this.base()}/query`, query);
|
|
5366
|
+
}
|
|
5367
|
+
/** Update a row by primary key. Returns the updated row. */
|
|
5368
|
+
async update(id, values) {
|
|
5369
|
+
return this.http.patch(`${this.base()}/${encodeURIComponent(String(id))}`, { values });
|
|
5370
|
+
}
|
|
5371
|
+
/** Delete a row by primary key. Returns the number of rows removed (0 or 1). */
|
|
5372
|
+
async delete(id) {
|
|
5373
|
+
const res = await this.http.del(`${this.base()}/${encodeURIComponent(String(id))}`);
|
|
5374
|
+
return res.deleted ?? 0;
|
|
5375
|
+
}
|
|
5376
|
+
}
|
|
5377
|
+
class DbNamespace {
|
|
5378
|
+
deps;
|
|
5379
|
+
constructor(deps) {
|
|
5380
|
+
this.deps = deps;
|
|
5381
|
+
}
|
|
5382
|
+
/**
|
|
5383
|
+
* A handle to a table defined in the portal. The optional type parameter
|
|
5384
|
+
* gives row operations a typed shape:
|
|
5385
|
+
*
|
|
5386
|
+
* interface Todo { _id: number; title: string; done: boolean }
|
|
5387
|
+
* const todos = client.db.table<Todo>('todos');
|
|
5388
|
+
*/
|
|
5389
|
+
table(name) {
|
|
5390
|
+
return new DbTable(this.deps.http, name);
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
|
|
5308
5394
|
/**
|
|
5309
5395
|
* `client.storage` — file storage. Hides the `FileStorage` / `ShardClient` /
|
|
5310
5396
|
* `SharedSpaceClient` primitives behind the unified client.
|
|
@@ -6865,8 +6951,13 @@ class SpaceNamespace {
|
|
|
6865
6951
|
* (viewers can read). Authorization rides the user session token; non-owner
|
|
6866
6952
|
* editors pass their management Space via `opts.space`.
|
|
6867
6953
|
*
|
|
6868
|
-
*
|
|
6869
|
-
* and `triggers` that decide when
|
|
6954
|
+
* An agent is "prompts + persona": a system prompt, a model, named prompt
|
|
6955
|
+
* `skills`, and `triggers` that decide when it speaks — plus optional `tools`
|
|
6956
|
+
* that let it act on the app (query/write its database, call its functions,
|
|
6957
|
+
* resolve its channels) via a server-side function-calling loop. See
|
|
6958
|
+
* {@link AgentToolsConfig}. Pair with the `@MuhkooAgent`/`@MuhkooSpace`/
|
|
6959
|
+
* `@MuhkooDB`/`@MuhkooFunction` decorators + `ejectAgentPrompt`/`ejectAgentTools`
|
|
6960
|
+
* to generate `systemPrompt` and `tools` straight from your app's surface.
|
|
6870
6961
|
*/
|
|
6871
6962
|
class AgentsNamespace {
|
|
6872
6963
|
deps;
|
|
@@ -7014,6 +7105,8 @@ class Client {
|
|
|
7014
7105
|
auth;
|
|
7015
7106
|
/** Per-user key/value storage — `client.kv.set(...)`, etc. */
|
|
7016
7107
|
kv;
|
|
7108
|
+
/** App scalable database — `client.db.table('todos').query(...)`, etc. */
|
|
7109
|
+
db;
|
|
7017
7110
|
/** File storage — `client.storage.writeFile(...)`, etc. */
|
|
7018
7111
|
storage;
|
|
7019
7112
|
/** Realtime messaging — `client.message.subscribe(...)`, etc. */
|
|
@@ -7051,6 +7144,7 @@ class Client {
|
|
|
7051
7144
|
const wsBaseUrl = toWsBase(this.baseUrl);
|
|
7052
7145
|
this.auth = new AuthNamespace({ auth: authClient, circuits, session: this.session });
|
|
7053
7146
|
this.kv = new KvNamespace({ http: this.http, session: this.session, wsBaseUrl });
|
|
7147
|
+
this.db = new DbNamespace({ http: this.http });
|
|
7054
7148
|
this.storage = new StorageNamespace({ http: this.http, baseUrl: this.baseUrl, kv: this.kv });
|
|
7055
7149
|
this.message = new MessageNamespace({ http: this.http, session: this.session, wsBaseUrl });
|
|
7056
7150
|
// Group keys are cached in the user's PersonalSpace (encrypted at rest
|
|
@@ -7121,6 +7215,177 @@ class Client {
|
|
|
7121
7215
|
}
|
|
7122
7216
|
}
|
|
7123
7217
|
|
|
7218
|
+
/**
|
|
7219
|
+
* Muhkoo app decorators — declare your app's agent-facing surface in code, then
|
|
7220
|
+
* "eject" a system prompt you hand to a Programmable Agent.
|
|
7221
|
+
*
|
|
7222
|
+
* You annotate a plain class with `@MuhkooAgent` (the app's identity + how the
|
|
7223
|
+
* agent should behave) plus per-surface decorators — `@MuhkooSpace`,
|
|
7224
|
+
* `@MuhkooDB`, `@MuhkooFunction` — that describe what each channel, table, and
|
|
7225
|
+
* function is *for*. {@link ejectAgentPrompt} reads those annotations and
|
|
7226
|
+
* produces a `systemPrompt` string:
|
|
7227
|
+
*
|
|
7228
|
+
* ```ts
|
|
7229
|
+
* @MuhkooAgent({
|
|
7230
|
+
* name: "Chat Assistant",
|
|
7231
|
+
* purpose: "A helpful assistant inside a real-time team chat.",
|
|
7232
|
+
* guidance: ["Keep replies short.", "Only chime in when relevant."],
|
|
7233
|
+
* })
|
|
7234
|
+
* class ChatAssistant {
|
|
7235
|
+
* @MuhkooSpace({ description: "Main team discussion." }) general!: string;
|
|
7236
|
+
* @MuhkooDB({ access: "read", description: "Chat message history." }) messages!: unknown;
|
|
7237
|
+
* @MuhkooFunction({ description: "Open a support ticket." }) openTicket!: () => void;
|
|
7238
|
+
* }
|
|
7239
|
+
*
|
|
7240
|
+
* const systemPrompt = ejectAgentPrompt(ChatAssistant);
|
|
7241
|
+
* await client.agents.create({ handle: "assistant", displayName: "Assistant", systemPrompt });
|
|
7242
|
+
* ```
|
|
7243
|
+
*
|
|
7244
|
+
* The ejected prompt owns the **semantic** layer — what the app is, how to act,
|
|
7245
|
+
* and what each surface means. The Muhkoo runtime separately appends the
|
|
7246
|
+
* **authoritative** roster (exact columns, function parameters, and the closed
|
|
7247
|
+
* list of callable tools), so the prompt here never needs to restate schema and
|
|
7248
|
+
* can't drift from it. Decorators only describe; they never change runtime
|
|
7249
|
+
* behavior, so they're safe to apply to a throwaway descriptor class.
|
|
7250
|
+
*
|
|
7251
|
+
* Requires `experimentalDecorators` (already enabled in this package). Metadata
|
|
7252
|
+
* is captured in a per-class registry — no `reflect-metadata` dependency.
|
|
7253
|
+
*/
|
|
7254
|
+
// Per-class metadata store, keyed by the class constructor. Member decorators
|
|
7255
|
+
// run during class-body evaluation (before the class decorator), so each
|
|
7256
|
+
// decorator get-or-creates the descriptor and they all converge on one entry.
|
|
7257
|
+
const REGISTRY = new WeakMap();
|
|
7258
|
+
function descriptorFor(ctor) {
|
|
7259
|
+
let d = REGISTRY.get(ctor);
|
|
7260
|
+
if (!d) {
|
|
7261
|
+
d = { spaces: [], tables: [], functions: [] };
|
|
7262
|
+
REGISTRY.set(ctor, d);
|
|
7263
|
+
}
|
|
7264
|
+
return d;
|
|
7265
|
+
}
|
|
7266
|
+
/** Resolve the owning class constructor from a decorator `target` — the
|
|
7267
|
+
* prototype for instance members, the constructor itself for static ones. */
|
|
7268
|
+
function ctorOf(target) {
|
|
7269
|
+
return typeof target === "function" ? target : target.constructor;
|
|
7270
|
+
}
|
|
7271
|
+
/**
|
|
7272
|
+
* Class decorator. Declares the app's agent identity, purpose, and behavioral
|
|
7273
|
+
* guidance. Apply it to the class whose members carry the surface decorators.
|
|
7274
|
+
*/
|
|
7275
|
+
function MuhkooAgent(meta) {
|
|
7276
|
+
return (target) => {
|
|
7277
|
+
descriptorFor(target).agent = meta;
|
|
7278
|
+
};
|
|
7279
|
+
}
|
|
7280
|
+
/** Member decorator. Marks a channel/Space the agent can resolve and post to. */
|
|
7281
|
+
function MuhkooSpace(meta) {
|
|
7282
|
+
return ((target, propertyKey) => {
|
|
7283
|
+
descriptorFor(ctorOf(target)).spaces.push({
|
|
7284
|
+
name: meta.name ?? String(propertyKey),
|
|
7285
|
+
description: meta.description,
|
|
7286
|
+
});
|
|
7287
|
+
});
|
|
7288
|
+
}
|
|
7289
|
+
/** Member decorator. Marks an app database table the agent can query/mutate. */
|
|
7290
|
+
function MuhkooDB(meta) {
|
|
7291
|
+
return ((target, propertyKey) => {
|
|
7292
|
+
descriptorFor(ctorOf(target)).tables.push({
|
|
7293
|
+
table: meta.table ?? String(propertyKey),
|
|
7294
|
+
access: meta.access ?? "read",
|
|
7295
|
+
description: meta.description,
|
|
7296
|
+
});
|
|
7297
|
+
});
|
|
7298
|
+
}
|
|
7299
|
+
/** Member decorator. Marks a serverless function the agent can call. */
|
|
7300
|
+
function MuhkooFunction(meta) {
|
|
7301
|
+
return ((target, propertyKey) => {
|
|
7302
|
+
descriptorFor(ctorOf(target)).functions.push({
|
|
7303
|
+
name: meta.name ?? String(propertyKey),
|
|
7304
|
+
description: meta.description,
|
|
7305
|
+
});
|
|
7306
|
+
});
|
|
7307
|
+
}
|
|
7308
|
+
/** Read back the raw descriptor a class accumulated (for tooling/tests). */
|
|
7309
|
+
function getMuhkooAppDescriptor(appClass) {
|
|
7310
|
+
return REGISTRY.get(appClass);
|
|
7311
|
+
}
|
|
7312
|
+
/**
|
|
7313
|
+
* Compose the agent system prompt from a `@MuhkooAgent`-decorated class. Throws
|
|
7314
|
+
* if the class isn't decorated. The result is the semantic layer only — the
|
|
7315
|
+
* runtime appends exact schema + the closed tool list at invocation time.
|
|
7316
|
+
*/
|
|
7317
|
+
function ejectAgentPrompt(appClass) {
|
|
7318
|
+
const d = REGISTRY.get(appClass);
|
|
7319
|
+
if (!d || !d.agent) {
|
|
7320
|
+
throw new Error("ejectAgentPrompt: the class must be decorated with @MuhkooAgent");
|
|
7321
|
+
}
|
|
7322
|
+
const { agent } = d;
|
|
7323
|
+
const lines = [];
|
|
7324
|
+
lines.push(`You are ${agent.name}. ${agent.purpose}`.trim());
|
|
7325
|
+
if (agent.guidance?.length) {
|
|
7326
|
+
lines.push("", "Guidance:");
|
|
7327
|
+
for (const g of agent.guidance)
|
|
7328
|
+
lines.push(`- ${g}`);
|
|
7329
|
+
}
|
|
7330
|
+
if (d.spaces.length) {
|
|
7331
|
+
lines.push("", "Channels (Spaces) you can resolve with resolve_channel and post messages into:");
|
|
7332
|
+
for (const s of d.spaces)
|
|
7333
|
+
lines.push(`- ${s.name}: ${s.description}`);
|
|
7334
|
+
}
|
|
7335
|
+
if (d.tables.length) {
|
|
7336
|
+
lines.push("", "App database tables:");
|
|
7337
|
+
for (const t of d.tables) {
|
|
7338
|
+
const verbs = t.access === "write"
|
|
7339
|
+
? "read & write — db_query/db_get/db_insert/db_update/db_delete"
|
|
7340
|
+
: "read-only — db_query/db_get";
|
|
7341
|
+
lines.push(`- ${t.table} (${verbs}): ${t.description}`);
|
|
7342
|
+
}
|
|
7343
|
+
}
|
|
7344
|
+
if (d.functions.length) {
|
|
7345
|
+
lines.push("", "Functions you can invoke with call_function:");
|
|
7346
|
+
for (const f of d.functions)
|
|
7347
|
+
lines.push(`- ${f.name}: ${f.description}`);
|
|
7348
|
+
}
|
|
7349
|
+
if (agent.instructions?.trim()) {
|
|
7350
|
+
lines.push("", agent.instructions.trim());
|
|
7351
|
+
}
|
|
7352
|
+
// How to respond — the load-bearing behavioral contract. Without this, models
|
|
7353
|
+
// (especially gpt-oss) tend to run tool calls and then end their turn with no
|
|
7354
|
+
// user-facing message, so the user sees the work happen but gets no reply.
|
|
7355
|
+
const hasTools = d.tables.length > 0 || d.functions.length > 0;
|
|
7356
|
+
lines.push("", "How to respond:");
|
|
7357
|
+
if (hasTools) {
|
|
7358
|
+
lines.push("- When you need information or need to make a change, call your tools immediately — don't ask the user to do it, and don't describe or name the tools to them.", "- After your tool calls return, you MUST send one final reply to the channel, in plain language, that answers the request using the results.");
|
|
7359
|
+
}
|
|
7360
|
+
lines.push("- Always end your turn with a short written reply (one or two sentences). Never finish with only tool calls and no message, and never reply with an empty message.", "- Don't restate function names, parameters, JSON, or your list of tools to the user — just give them the answer.");
|
|
7361
|
+
lines.push("", "The exact columns, function parameters, and the full list of callable tools are supplied to you by the runtime. Follow that authoritative list — never invent tables, columns, functions, or tools.");
|
|
7362
|
+
return lines.join("\n");
|
|
7363
|
+
}
|
|
7364
|
+
/**
|
|
7365
|
+
* Derive a suggested tools allowlist from a decorated class — the db tables
|
|
7366
|
+
* (and whether any are writable), the callable functions, and whether channels
|
|
7367
|
+
* are in play. Pair with {@link ejectAgentPrompt} when configuring the agent.
|
|
7368
|
+
*
|
|
7369
|
+
* If any tables/functions are present the result has `enabled: true`; to
|
|
7370
|
+
* actually grant tools you must also pass a function-calling `model` in the same
|
|
7371
|
+
* `client.agents.create`/`update` call (the server enforces this).
|
|
7372
|
+
*/
|
|
7373
|
+
function ejectAgentTools(appClass, opts) {
|
|
7374
|
+
const d = REGISTRY.get(appClass);
|
|
7375
|
+
if (!d) {
|
|
7376
|
+
throw new Error("ejectAgentTools: the class must be decorated with @MuhkooAgent");
|
|
7377
|
+
}
|
|
7378
|
+
const anyWrite = d.tables.some((t) => t.access === "write");
|
|
7379
|
+
const mode = d.tables.length === 0 ? "off" : anyWrite ? "write" : "read";
|
|
7380
|
+
return {
|
|
7381
|
+
enabled: d.tables.length > 0 || d.functions.length > 0 || d.spaces.length > 0,
|
|
7382
|
+
db: { mode, tables: d.tables.map((t) => t.table) },
|
|
7383
|
+
functions: d.functions.map((f) => f.name),
|
|
7384
|
+
channels: d.spaces.length > 0,
|
|
7385
|
+
maxIterations: opts?.maxIterations ?? 6,
|
|
7386
|
+
};
|
|
7387
|
+
}
|
|
7388
|
+
|
|
7124
7389
|
/**
|
|
7125
7390
|
* PacketCipher — the strategy `Network` uses to seal/open a packet's payload.
|
|
7126
7391
|
*
|
|
@@ -7187,5 +7452,5 @@ var bundledLoader = /*#__PURE__*/Object.freeze({
|
|
|
7187
7452
|
default: loadRsWasm
|
|
7188
7453
|
});
|
|
7189
7454
|
|
|
7190
|
-
export { AES_GCM_IV_BYTES, AES_GCM_KEY_BYTES, AES_GCM_TAG_BYTES, AgentsNamespace, AuthClient, AuthNamespace, AuthPublicInput, Authenticator, BroadcastChannel, BroadcastChannelEvents, ChannelExistsError, ChannelNotFoundError, ChunkCipher, Client, DEFAULT_BASE_URL, DoubleRatchet, DoubleRatchetCipher, DoubleRatchetManager, EncryptedSession, EventCore, EventCoreEvents, Field, Field as FieldElement, FileStorage, FunctionsNamespace, HashKnowledge, HttpClient, HttpError, KEEPER_MEMBER_ID, KeyStore, KeyringClient, KvNamespace, LocalStorageSessionStore, MemorySessionStore, Message, Message as MessageDefault, MessageNamespace, PBKDF2_DEFAULT_ITERATIONS, PREIMAGE_POK_VERIFICATION_KEY, Packet, PersonalSpaceClient, Poseidon, PreimagePoK, ReedSolomonCodec, Space as Room, SerializeMessage, SessionState, ShardClient, SharedSpaceClient, Space, SpaceKeyring, SpaceNamespace, SpacePacketCipher, StorageNamespace, WSTransport, ZkAuth, buildCommitment, compilePrograms, decodeFromHex, decorators, decryptAesGcm, defaultCircuitUrls, defaultSessionStore, deriveAesKeyFromPassphrase, deriveBitsHkdf, deriveIdentity, encodeToHex, encryptAesGcm, exportPublicKeyBase64, exportPublicKeyHex, generateAuthProof, getSubtle, initBn128Wasm, initRsWasm, initializeCircuits, manifestToStat, poseidonHash, quickVerify, randomBytes, shardHash, signMessage, toField, unwrapWithPassphrase, verify, verifyGroth16, verifyHashKnowledge, verifyPreimagePoK, wrapWithPassphrase };
|
|
7455
|
+
export { AES_GCM_IV_BYTES, AES_GCM_KEY_BYTES, AES_GCM_TAG_BYTES, AgentsNamespace, AuthClient, AuthNamespace, AuthPublicInput, Authenticator, BroadcastChannel, BroadcastChannelEvents, ChannelExistsError, ChannelNotFoundError, ChunkCipher, Client, DEFAULT_BASE_URL, DoubleRatchet, DoubleRatchetCipher, DoubleRatchetManager, EncryptedSession, EventCore, EventCoreEvents, Field, Field as FieldElement, FileStorage, FunctionsNamespace, HashKnowledge, HttpClient, HttpError, KEEPER_MEMBER_ID, KeyStore, KeyringClient, KvNamespace, LocalStorageSessionStore, MemorySessionStore, Message, Message as MessageDefault, MessageNamespace, MuhkooAgent, MuhkooDB, MuhkooFunction, MuhkooSpace, PBKDF2_DEFAULT_ITERATIONS, PREIMAGE_POK_VERIFICATION_KEY, Packet, PersonalSpaceClient, Poseidon, PreimagePoK, ReedSolomonCodec, Space as Room, SerializeMessage, SessionState, ShardClient, SharedSpaceClient, Space, SpaceKeyring, SpaceNamespace, SpacePacketCipher, StorageNamespace, WSTransport, ZkAuth, buildCommitment, compilePrograms, decodeFromHex, decorators, decryptAesGcm, defaultCircuitUrls, defaultSessionStore, deriveAesKeyFromPassphrase, deriveBitsHkdf, deriveIdentity, ejectAgentPrompt, ejectAgentTools, encodeToHex, encryptAesGcm, exportPublicKeyBase64, exportPublicKeyHex, generateAuthProof, getMuhkooAppDescriptor, getSubtle, initBn128Wasm, initRsWasm, initializeCircuits, manifestToStat, poseidonHash, quickVerify, randomBytes, shardHash, signMessage, toField, unwrapWithPassphrase, verify, verifyGroth16, verifyHashKnowledge, verifyPreimagePoK, wrapWithPassphrase };
|
|
7191
7456
|
//# sourceMappingURL=index.js.map
|