@qvac/core 0.10.2 → 0.10.3

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/CHANGELOG.md CHANGED
@@ -13,6 +13,34 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.10.3] - 2026-10-21
17
+
18
+ ### Added
19
+
20
+ - `listAgentFolders`, `addAgentFolder` and `removeAgentFolder` share a folder on
21
+ this device with an agent, read only or read and write, so its file tools have
22
+ somewhere to work. They keep the `fs.<agentId>.roots` and
23
+ `fs.<agentId>.writable` config keys the assistant already reads, so a grant
24
+ written before keeps working. See
25
+ [agent folders](docs/api/agent-folders.md). (#445)
26
+
27
+ ### Changed
28
+
29
+ - The runs a `deleteAgent` with `keepChats` cancels carry
30
+ `reason: 'agent-deleted'`, so an app can tell them from a run its user took
31
+ back and keep the message they answered. (#486)
32
+ - `deleteAgent` forgets the folders shared with the agent on this device. (#445)
33
+
34
+ ### Fixed
35
+
36
+ - A borrowed run (`lenderDeviceId`) no longer acts on the lender's machine. The
37
+ lender serves it with no shared folders, with the `files` and `exec` toolsets
38
+ off, as none of its own agents, and with its KV caches kept apart; a borrowed
39
+ run gets no image or attachment. (#477)
40
+ - A device-invite `joinMesh` no longer lists a mesh it is leaving as closed, so
41
+ the app no longer reopens it and reports `MESH_NOT_FOUND` after pairing.
42
+ (#489)
43
+
16
44
  ## [0.10.2] - 2026-10-20
17
45
 
18
46
  ### Added
@@ -1829,7 +1857,8 @@ Published under the `release-0.1` dist-tag.
1829
1857
  await assistant.ready()
1830
1858
  ```
1831
1859
 
1832
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.10.2...HEAD
1860
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.10.3...HEAD
1861
+ [0.10.3]: https://github.com/tetherto/qvac-core/compare/v0.10.2...v0.10.3
1833
1862
  [0.10.2]: https://github.com/tetherto/qvac-core/compare/v0.10.1...v0.10.2
1834
1863
  [0.10.1]: https://github.com/tetherto/qvac-core/compare/v0.10.0...v0.10.1
1835
1864
  [0.10.0]: https://github.com/tetherto/qvac-core/compare/v0.9.0...v0.10.0
@@ -0,0 +1,22 @@
1
+ import type { AssistantAddAgentFolderRequest, AssistantAgentFolders, AssistantAgentFoldersRequest, AssistantRemoveAgentFolderRequest } from '../../spec/hyperschema/types.d.ts';
2
+ import type { openLocalStore } from '../core/local/index.ts';
3
+ import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
4
+ type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
5
+ export interface AgentFoldersOptions {
6
+ readonly storageRoot: string;
7
+ }
8
+ export declare class AgentFolders {
9
+ private readonly _state;
10
+ private readonly _storageRoot;
11
+ private readonly _lock;
12
+ constructor(state: LocalStore, { storageRoot }: AgentFoldersOptions);
13
+ list({ agentId }: AssistantAgentFoldersRequest): Promise<AssistantAgentFolders>;
14
+ add({ agentId, path: given, access }: AssistantAddAgentFolderRequest): Promise<AssistantAgentFolders>;
15
+ remove({ agentId, path: given }: AssistantRemoveAgentFolderRequest): Promise<AssistantAgentFolders>;
16
+ forget(agentId: string): Promise<void>;
17
+ private _read;
18
+ private _update;
19
+ private _shareable;
20
+ }
21
+ export declare function createAgentFoldersApi(folders: AgentFolders): Pick<CapabilityHandlers, 'listAgentFolders' | 'addAgentFolder' | 'removeAgentFolder'>;
22
+ export {};
@@ -0,0 +1,115 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import ScopeLock from 'scope-lock';
4
+ import { CoreError } from '../errors.js';
5
+ import { fsGrantKey, fsWriteGrantKey } from '../fs-grant-keys.js';
6
+ import { fsGrantsFrom, grantedDirsFrom } from '../fs-grants.js';
7
+ export class AgentFolders {
8
+ _state;
9
+ _storageRoot;
10
+ _lock = new ScopeLock();
11
+ constructor(state, { storageRoot }) {
12
+ this._state = state;
13
+ this._storageRoot = storageRoot;
14
+ }
15
+ async list({ agentId }) {
16
+ return { agentId, folders: foldersOf(await this._read(agentId)) };
17
+ }
18
+ async add({ agentId, path: given, access }) {
19
+ const folder = await this._shareable(given);
20
+ return this._update(agentId, ({ roots, writable }) => ({
21
+ roots: localPathsOf(roots).includes(folder)
22
+ ? roots
23
+ : [...roots, { kind: 'local', path: folder }],
24
+ writable: access === 'write' ? withDir(writable, folder) : withoutDir(writable, folder)
25
+ }));
26
+ }
27
+ async remove({ agentId, path: given }) {
28
+ const names = await namesOf(given);
29
+ return this._update(agentId, (grants) => {
30
+ if (!foldersOf(grants).some((folder) => names.includes(folder.path))) {
31
+ throw new CoreError('AGENT_FOLDER_NOT_SHARED', [given]);
32
+ }
33
+ return {
34
+ roots: grants.roots.filter((root) => !names.includes(localPathOf(root) ?? '')),
35
+ writable: names.reduce(withoutDir, grants.writable)
36
+ };
37
+ });
38
+ }
39
+ async forget(agentId) {
40
+ await this._lock.lock();
41
+ try {
42
+ await this._state.deleteAll([fsGrantKey(agentId), fsWriteGrantKey(agentId)]);
43
+ }
44
+ finally {
45
+ this._lock.unlock();
46
+ }
47
+ }
48
+ async _read(agentId) {
49
+ const [roots, writable] = await Promise.all([
50
+ this._state.get(fsGrantKey(agentId)),
51
+ this._state.get(fsWriteGrantKey(agentId))
52
+ ]);
53
+ return { roots: Array.isArray(roots) ? roots : [], writable: grantedDirsFrom(writable) };
54
+ }
55
+ async _update(agentId, change) {
56
+ await this._lock.lock();
57
+ try {
58
+ const next = change(await this._read(agentId));
59
+ await this._state.setAll([
60
+ { key: fsGrantKey(agentId), value: next.roots },
61
+ { key: fsWriteGrantKey(agentId), value: next.writable }
62
+ ]);
63
+ return { agentId, folders: foldersOf(next) };
64
+ }
65
+ finally {
66
+ this._lock.unlock();
67
+ }
68
+ }
69
+ async _shareable(given) {
70
+ if (!path.isAbsolute(given)) {
71
+ throw new CoreError('AGENT_FOLDER_NOT_ABSOLUTE', [given]);
72
+ }
73
+ const folder = await fs.promises.realpath(given).catch(() => null);
74
+ if (!folder) {
75
+ throw new CoreError('AGENT_FOLDER_MISSING', [given]);
76
+ }
77
+ if (!(await fs.promises.stat(folder)).isDirectory()) {
78
+ throw new CoreError('AGENT_FOLDER_IS_FILE', [given]);
79
+ }
80
+ const storage = await fs.promises.realpath(this._storageRoot);
81
+ if (folder === storage || folder.startsWith(storage + path.sep)) {
82
+ throw new CoreError('AGENT_FOLDER_IN_STORAGE', [given]);
83
+ }
84
+ return folder;
85
+ }
86
+ }
87
+ export function createAgentFoldersApi(folders) {
88
+ return {
89
+ listAgentFolders: (request) => folders.list(request),
90
+ addAgentFolder: (request) => folders.add(request),
91
+ removeAgentFolder: (request) => folders.remove(request)
92
+ };
93
+ }
94
+ async function namesOf(given) {
95
+ const resolved = path.resolve(given);
96
+ const real = await fs.promises.realpath(resolved).catch(() => resolved);
97
+ return [...new Set([resolved, real])];
98
+ }
99
+ function localPathOf(root) {
100
+ const [grant] = fsGrantsFrom([root]);
101
+ return grant?.kind === 'local' ? grant.path : null;
102
+ }
103
+ function localPathsOf(roots) {
104
+ return roots.map(localPathOf).filter((dir) => dir !== null);
105
+ }
106
+ function withDir(dirs, dir) {
107
+ return dirs.includes(dir) ? dirs : [...dirs, dir];
108
+ }
109
+ function withoutDir(dirs, dir) {
110
+ return dirs.filter((other) => other !== dir);
111
+ }
112
+ function foldersOf({ roots, writable }) {
113
+ const paths = [...new Set([...localPathsOf(roots), ...writable])];
114
+ return paths.map((dir) => ({ path: dir, access: writable.includes(dir) ? 'write' : 'read' }));
115
+ }
@@ -1,11 +1,13 @@
1
1
  import type { LoggerInterface } from '@qvac/logging';
2
2
  import { type MeshPool } from './current-mesh.ts';
3
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
4
+ import type { AgentFolders } from './agent-folders.ts';
4
5
  type AgentCapabilities = Pick<CapabilityHandlers, 'createAgent' | 'listAgents' | 'getAgent' | 'getDefaultAgent' | 'updateAgent' | 'deleteAgent' | 'agentsWatch'>;
5
6
  export interface CreateAgentsApiOptions {
6
7
  readonly deviceId: Buffer | null;
7
8
  readonly computeLender: (() => Promise<Buffer | null>) | null;
9
+ readonly folders: AgentFolders | null;
8
10
  readonly log: LoggerInterface | null;
9
11
  }
10
- export declare function createAgentsApi(pool: MeshPool, { deviceId, computeLender, log }: CreateAgentsApiOptions): AgentCapabilities;
12
+ export declare function createAgentsApi(pool: MeshPool, { deviceId, computeLender, folders, log }: CreateAgentsApiOptions): AgentCapabilities;
11
13
  export {};
@@ -1,7 +1,7 @@
1
1
  import { createAgent, deleteAgent, getDefaultAgent, isOrphaned, listAgents, liveProviderIds, mustGetActiveAgent, updateAgent } from '../core/agent.js';
2
2
  import { meshWatchable, requireMesh } from './current-mesh.js';
3
3
  import b4a from 'b4a';
4
- export function createAgentsApi(pool, { deviceId, computeLender, log }) {
4
+ export function createAgentsApi(pool, { deviceId, computeLender, folders, log }) {
5
5
  const withOrphaned = async (mesh, agent) => ({
6
6
  ...agent,
7
7
  orphaned: await isOrphaned(mesh, agent)
@@ -43,7 +43,9 @@ export function createAgentsApi(pool, { deviceId, computeLender, log }) {
43
43
  },
44
44
  deleteAgent: async ({ agentId, meshId, keepChats }) => {
45
45
  const mesh = await requireMesh(pool, meshId);
46
- return withOrphaned(mesh, await deleteAgent(mesh, deviceId, { id: agentId, keepChats }));
46
+ const deleted = await deleteAgent(mesh, deviceId, { id: agentId, keepChats });
47
+ await folders?.forget(agentId);
48
+ return withOrphaned(mesh, deleted);
47
49
  },
48
50
  agentsWatch: meshWatchable(pool, (request, mesh) => list(mesh, request.providerDeviceId ?? undefined), { name: 'agentsWatch', log })
49
51
  };
@@ -60,6 +60,7 @@ interface ApiDeps {
60
60
  platform?: (() => string | null) | null;
61
61
  computeLender?: (() => Promise<Buffer | null>) | null;
62
62
  pushSkillSecret?: ((request: AssistantPushSkillSecretRequest) => Promise<void>) | null;
63
+ storageRoot?: string | null;
63
64
  skills?: ((agentId?: string | null, modelName?: string | null, options?: SkillOptions) => Promise<unknown>) | null;
64
65
  skillCatalog?: ((agentId?: string | null, modelName?: string | null, options?: {
65
66
  readonly refresh?: boolean;
@@ -2,6 +2,7 @@ import { toAsyncIterable } from '../core/async-iterable.js';
2
2
  import { normalizeImageForModel } from '../core/image/normalize.js';
3
3
  import { detectImageMime } from '../core/image/sniff.js';
4
4
  import { createAgentsApi } from './agents.js';
5
+ import { AgentFolders, createAgentFoldersApi } from './agent-folders.js';
5
6
  import { createApprovalRulesApi } from './approval-rules.js';
6
7
  import { createAttachmentsApi } from './attachments.js';
7
8
  import { createChatApi } from './chat.js';
@@ -38,6 +39,7 @@ export function createApi(deps = {}) {
38
39
  const state = deps.state ?? null;
39
40
  const log = deps.log ?? null;
40
41
  const members = mesh && deps.meshStatus ? createMembersApi(mesh, deps.meshStatus, { state, log }) : null;
42
+ const folders = state && deps.storageRoot ? new AgentFolders(state, { storageRoot: deps.storageRoot }) : null;
41
43
  const handlers = {
42
44
  ...(state ? createConfigApi(state, log) : null),
43
45
  ...(state ? createAppConfigApi(state, log) : null),
@@ -49,10 +51,12 @@ export function createApi(deps = {}) {
49
51
  log
50
52
  })
51
53
  : null),
54
+ ...(folders ? createAgentFoldersApi(folders) : null),
52
55
  ...(mesh
53
56
  ? createAgentsApi(mesh, {
54
57
  deviceId: deps.deviceId ?? null,
55
58
  computeLender: deps.computeLender ?? null,
59
+ folders,
56
60
  log
57
61
  })
58
62
  : null),
@@ -8,6 +8,7 @@ import { startModelMemoryCap } from './model-memory-cap.js';
8
8
  import { startDownloadsAllowedPusher } from './downloads-allowed-pusher.js';
9
9
  import { serveHarness } from '@qvac/harness';
10
10
  import { duplexPair } from '@qvac/harness/transport';
11
+ import { lentHarness } from './lent-harness.js';
11
12
  export function assistantTree(opts) {
12
13
  const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel, fakeModels = false } = opts;
13
14
  const sup = new Supervisor();
@@ -118,7 +119,7 @@ export function assistantTree(opts) {
118
119
  },
119
120
  logger
120
121
  });
121
- offLoanableHarness = core.registerLoanableHarness((stream) => serveHarness(stream, harness));
122
+ offLoanableHarness = core.registerLoanableHarness((stream) => serveHarness(stream, lentHarness(harness)));
122
123
  offRetryModelDownload = core.registerRetryModelDownload((name) => assistant.retryModelDownload(name));
123
124
  offModelResidency = core.registerModelResidency({
124
125
  load: (name) => assistant.loadModel(name),
@@ -161,6 +161,7 @@ const RAG_SOURCE_BOUNDS = {
161
161
  excerptChars: RAG_SOURCE_EXCERPT_CHARS
162
162
  };
163
163
  const WEB_RAG_SOURCE_BOUNDS = { ...RAG_SOURCE_BOUNDS, maxUrlChars: MAX_RAG_SOURCE_URL_CHARS };
164
+ const NO_FS_GRANTS = { roots: [], write: [] };
164
165
  export class QvacAssistant extends ReadyResource {
165
166
  _engine;
166
167
  _harness;
@@ -1619,7 +1620,7 @@ export class QvacAssistant extends ReadyResource {
1619
1620
  meshId
1620
1621
  });
1621
1622
  const toolConfigsPromise = this._loadToolConfigs(engine, agent.id);
1622
- const fsGrantsPromise = this._loadFsGrants(agent.id);
1623
+ const fsGrantsPromise = lender ? Promise.resolve(NO_FS_GRANTS) : this._loadFsGrants(agent.id);
1623
1624
  const all = await listHistoryChunks(engine, chatId);
1624
1625
  if (agentSwitched(all, request, deviceId)) {
1625
1626
  await this._deleteChatKvCache(chatId, 'agent switched');
@@ -1670,9 +1671,11 @@ export class QvacAssistant extends ReadyResource {
1670
1671
  enabledSkills: []
1671
1672
  }
1672
1673
  : configuredAgent;
1673
- const seesImages = this._harness.supportsImagesFor
1674
- ? this._harness.supportsImagesFor(model)
1675
- : (this._harness.supportsImages ?? this._info.supportsImages) !== false;
1674
+ const sendsFiles = lender === null;
1675
+ const seesImages = sendsFiles &&
1676
+ (this._harness.supportsImagesFor
1677
+ ? this._harness.supportsImagesFor(model)
1678
+ : (this._harness.supportsImages ?? this._info.supportsImages) !== false);
1676
1679
  let unreadableImages = new Map();
1677
1680
  let renderedPdfIds = new Set();
1678
1681
  if (!seesImages) {
@@ -55,4 +55,5 @@ export interface RemoveChatAttachmentsOptions {
55
55
  export declare function removeChatAttachments(store: Mesh, chatId: string, { deviceId, at }: RemoveChatAttachmentsOptions): Promise<void>;
56
56
  export declare function deleteChat(store: Mesh, deviceId: Buffer | null, id: string): Promise<ChatListing>;
57
57
  export declare function softDeleteChatsForAgent(store: Mesh, deviceId: Buffer | null, agentId: string): Promise<void>;
58
+ export declare const AGENT_DELETED = "agent-deleted";
58
59
  export declare function cancelRunsForAgent(store: Mesh, deviceId: Buffer, agentId: string): Promise<void>;
@@ -291,8 +291,9 @@ export async function deleteChat(store, deviceId, id) {
291
291
  export function softDeleteChatsForAgent(store, deviceId, agentId) {
292
292
  return eachChatOfAgent(store, agentId, (chatId) => deleteChat(store, deviceId, chatId));
293
293
  }
294
+ export const AGENT_DELETED = 'agent-deleted';
294
295
  export function cancelRunsForAgent(store, deviceId, agentId) {
295
- return eachChatOfAgent(store, agentId, (chatId) => cancelActiveRuns(store, chatId, { deviceId, agentId }));
296
+ return eachChatOfAgent(store, agentId, (chatId) => cancelActiveRuns(store, chatId, { deviceId, agentId, reason: AGENT_DELETED }));
296
297
  }
297
298
  async function eachChatOfAgent(store, agentId, fn) {
298
299
  const snap = store.view.snapshot();
@@ -4,6 +4,7 @@ import BlindPeering from 'blind-peering';
4
4
  import Corestore from 'corestore';
5
5
  import CorestoreStorage from 'hypercore-storage';
6
6
  import { constants as RocksConstants } from 'rocksdb-native';
7
+ import path from 'path';
7
8
  import Rache from 'rache';
8
9
  import Hyperswarm from 'hyperswarm';
9
10
  import Wakeup from 'protomux-wakeup';
@@ -409,6 +410,7 @@ export class Core extends ReadyResource {
409
410
  platform: () => this._localDevice?.platform ?? null,
410
411
  computeLender: () => this._computeLender(),
411
412
  pushSkillSecret: (request) => this.pushSkillSecret(request),
413
+ storageRoot: path.dirname(this._storagePath),
412
414
  listModels: this._hostsModelSource || this._listModels
413
415
  ? async (request) => (await this._readModelList(request)) ?? { models: [] }
414
416
  : null,
@@ -2148,13 +2150,13 @@ export class Core extends ReadyResource {
2148
2150
  }
2149
2151
  const rows = (await this.local.listMeshes()).filter((row) => !b4a.equals(row.key, joined));
2150
2152
  const meshes = rows.filter((row) => !(account && b4a.equals(account, row.key)));
2151
- for (const mesh of meshes) {
2152
- await this._departIfPooled(mesh.key, 'mesh');
2153
- }
2154
2153
  await this.local.adoptAccountMesh(this._requireDeviceKeyPair().publicKey, joined, {
2155
2154
  account,
2156
2155
  keepName
2157
2156
  });
2157
+ for (const mesh of meshes) {
2158
+ await this._departIfPooled(mesh.key, 'mesh');
2159
+ }
2158
2160
  if (account) {
2159
2161
  await this._departIfPooled(account, 'account');
2160
2162
  }
@@ -2278,7 +2280,7 @@ export class Core extends ReadyResource {
2278
2280
  if (this.closing)
2279
2281
  return null;
2280
2282
  const key = await this._storedAccountKey();
2281
- const held = key ? this._pooled(b4a.toHex(key)) : null;
2283
+ const held = key ? (this._pooled(b4a.toHex(key)) ?? this._opening.get(b4a.toHex(key))) : null;
2282
2284
  const mesh = key ? await this._openPooledMesh(b4a.toHex(key)).catch(noop) : null;
2283
2285
  if (mesh && !mesh.ourMemberId) {
2284
2286
  await mesh.refreshOurMember();
@@ -268,6 +268,26 @@ declare const DEFINITIONS: {
268
268
  readonly code: 100616;
269
269
  readonly message: () => string;
270
270
  };
271
+ readonly AGENT_FOLDER_NOT_ABSOLUTE: {
272
+ readonly code: 100617;
273
+ readonly message: (path: string) => string;
274
+ };
275
+ readonly AGENT_FOLDER_MISSING: {
276
+ readonly code: 100618;
277
+ readonly message: (path: string) => string;
278
+ };
279
+ readonly AGENT_FOLDER_IS_FILE: {
280
+ readonly code: 100619;
281
+ readonly message: (path: string) => string;
282
+ };
283
+ readonly AGENT_FOLDER_IN_STORAGE: {
284
+ readonly code: 100620;
285
+ readonly message: (path: string) => string;
286
+ };
287
+ readonly AGENT_FOLDER_NOT_SHARED: {
288
+ readonly code: 100621;
289
+ readonly message: (path: string) => string;
290
+ };
271
291
  readonly CHAT_NOT_FOUND: {
272
292
  readonly code: 100701;
273
293
  readonly message: (chatId: string) => string;
@@ -197,6 +197,26 @@ const DEFINITIONS = {
197
197
  },
198
198
  LOAN_UNREACHABLE: { code: 100615, message: () => LOAN_UNREACHABLE },
199
199
  LOAN_REVOKED: { code: 100616, message: () => 'the device stopped lending its model' },
200
+ AGENT_FOLDER_NOT_ABSOLUTE: {
201
+ code: 100617,
202
+ message: (path) => `a shared folder is an absolute path, not ${path}`
203
+ },
204
+ AGENT_FOLDER_MISSING: {
205
+ code: 100618,
206
+ message: (path) => `there is no folder at ${path}`
207
+ },
208
+ AGENT_FOLDER_IS_FILE: {
209
+ code: 100619,
210
+ message: (path) => `${path} is a file, not a folder`
211
+ },
212
+ AGENT_FOLDER_IN_STORAGE: {
213
+ code: 100620,
214
+ message: (path) => `${path} is inside the app's own storage, which no agent may reach`
215
+ },
216
+ AGENT_FOLDER_NOT_SHARED: {
217
+ code: 100621,
218
+ message: (path) => `${path} is not shared with this agent`
219
+ },
200
220
  CHAT_NOT_FOUND: {
201
221
  code: 100701,
202
222
  message: (chatId) => `chat not found: ${chatId}`
@@ -0,0 +1,2 @@
1
+ import type { HarnessContract } from '@qvac/harness';
2
+ export declare function lentHarness(harness: HarnessContract): HarnessContract;
@@ -0,0 +1,51 @@
1
+ const HOST_TOOLSETS = ['files', 'exec'];
2
+ const LENT_AGENT = 'lent';
3
+ export function lentHarness(harness) {
4
+ const invoke = harness.invoke?.bind(harness);
5
+ const deleteKvCache = harness.deleteKvCache?.bind(harness);
6
+ return {
7
+ describe: async () => ({
8
+ toolNames: [],
9
+ skills: [],
10
+ supportsImages: false,
11
+ supportsKvCacheDeletion: (await harness.describe?.())?.supportsKvCacheDeletion === true
12
+ }),
13
+ completion: (context) => harness.completion(lentRun(context)),
14
+ invoke: invoke && ((context) => invoke(lentInvoke(context))),
15
+ deleteKvCache: deleteKvCache && ((key) => deleteKvCache(lentKey(key)))
16
+ };
17
+ }
18
+ function lentRun(context) {
19
+ return {
20
+ ...context,
21
+ agent: lentAgent(context.agent),
22
+ cacheKey: context.cacheKey && lentKey(context.cacheKey),
23
+ session: context.session && lentKey(context.session),
24
+ messages: context.messages.map((turn) => ({ ...turn, attachments: undefined })),
25
+ fetchAttachment: undefined,
26
+ grantedDirs: undefined,
27
+ grantedWriteDirs: undefined,
28
+ grantedDrives: undefined,
29
+ driveOp: undefined
30
+ };
31
+ }
32
+ function lentInvoke(context) {
33
+ return {
34
+ ...context,
35
+ agent: context.agent && lentAgent(context.agent),
36
+ fetchAttachment: undefined
37
+ };
38
+ }
39
+ function lentAgent(agent) {
40
+ const disabled = agent.disabledToolsets ?? [];
41
+ return {
42
+ ...agent,
43
+ id: LENT_AGENT,
44
+ skillsScope: 'selected',
45
+ enabledSkills: [],
46
+ disabledToolsets: [...new Set([...disabled, ...HOST_TOOLSETS])]
47
+ };
48
+ }
49
+ function lentKey(key) {
50
+ return `${LENT_AGENT}-${key}`;
51
+ }
@@ -127,6 +127,9 @@ const DEVICE_LOCAL = new Set([
127
127
  'networkWatch',
128
128
  'setBlindPeering',
129
129
  'blindPeeringWatch',
130
+ 'listAgentFolders',
131
+ 'addAgentFolder',
132
+ 'removeAgentFolder',
130
133
  'meshStatusWatch',
131
134
  'listMeshes',
132
135
  'meshesWatch',
@@ -2167,6 +2167,40 @@ export function registerEngineTypes(ns) {
2167
2167
  { name: 'keepChats', type: 'bool' }
2168
2168
  ]
2169
2169
  });
2170
+ ns.register({ name: 'agent-folder-access', enum: ['read', 'write'], strings: true });
2171
+ ns.register({
2172
+ name: 'agent-folder',
2173
+ fields: [
2174
+ { name: 'path', type: 'string', required: true },
2175
+ { name: 'access', type: '@assistant/agent-folder-access', required: true }
2176
+ ]
2177
+ });
2178
+ ns.register({
2179
+ name: 'agent-folders-request',
2180
+ fields: [{ name: 'agentId', type: 'string', required: true }]
2181
+ });
2182
+ ns.register({
2183
+ name: 'agent-folders',
2184
+ fields: [
2185
+ { name: 'agentId', type: 'string', required: true },
2186
+ { name: 'folders', type: '@assistant/agent-folder', array: true }
2187
+ ]
2188
+ });
2189
+ ns.register({
2190
+ name: 'add-agent-folder-request',
2191
+ fields: [
2192
+ { name: 'agentId', type: 'string', required: true },
2193
+ { name: 'path', type: 'string', required: true },
2194
+ { name: 'access', type: '@assistant/agent-folder-access', required: true }
2195
+ ]
2196
+ });
2197
+ ns.register({
2198
+ name: 'remove-agent-folder-request',
2199
+ fields: [
2200
+ { name: 'agentId', type: 'string', required: true },
2201
+ { name: 'path', type: 'string', required: true }
2202
+ ]
2203
+ });
2170
2204
  }
2171
2205
  export function registerEngineApi(api) {
2172
2206
  api.register({
@@ -2974,4 +3008,19 @@ export function registerEngineApi(api) {
2974
3008
  request: { name: '@assistant/empty', stream: false },
2975
3009
  response: { name: '@assistant/blind-peering', stream: true }
2976
3010
  });
3011
+ api.register({
3012
+ name: 'list-agent-folders',
3013
+ request: { name: '@assistant/agent-folders-request', stream: false },
3014
+ response: { name: '@assistant/agent-folders', stream: false }
3015
+ });
3016
+ api.register({
3017
+ name: 'add-agent-folder',
3018
+ request: { name: '@assistant/add-agent-folder-request', stream: false },
3019
+ response: { name: '@assistant/agent-folders', stream: false }
3020
+ });
3021
+ api.register({
3022
+ name: 'remove-agent-folder',
3023
+ request: { name: '@assistant/remove-agent-folder-request', stream: false },
3024
+ response: { name: '@assistant/agent-folders', stream: false }
3025
+ });
2977
3026
  }
@@ -690,4 +690,13 @@ export function bindApi(rpc, api) {
690
690
  out.writeStream?.on("close", () => src.destroy());
691
691
  });
692
692
  }
693
+ if (api.listAgentFolders) {
694
+ rpc.onListAgentFolders((req) => api.listAgentFolders(req));
695
+ }
696
+ if (api.addAgentFolder) {
697
+ rpc.onAddAgentFolder((req) => api.addAgentFolder(req));
698
+ }
699
+ if (api.removeAgentFolder) {
700
+ rpc.onRemoveAgentFolder((req) => api.removeAgentFolder(req));
701
+ }
693
702
  }
@@ -171,5 +171,8 @@ export function engineClient(rpc) {
171
171
  forkChat: (input) => rpc.forkChat(input),
172
172
  setBlindPeering: (input) => rpc.setBlindPeering(input),
173
173
  blindPeeringWatch: (input) => armed(rpc.blindPeeringWatch(input ?? {})),
174
+ listAgentFolders: (input) => rpc.listAgentFolders(input),
175
+ addAgentFolder: (input) => rpc.addAgentFolder(input),
176
+ removeAgentFolder: (input) => rpc.removeAgentFolder(input),
174
177
  };
175
178
  }
@@ -189,6 +189,9 @@ export interface Capabilities {
189
189
  forkChat(input: T.AssistantForkChatRequest): Promise<T.AssistantChat>
190
190
  setBlindPeering(input: T.AssistantBlindPeering): Promise<T.AssistantBlindPeering>
191
191
  blindPeeringWatch(input?: T.AssistantEmpty): WatchStream<T.AssistantBlindPeering>
192
+ listAgentFolders(input: T.AssistantAgentFoldersRequest): Promise<T.AssistantAgentFolders>
193
+ addAgentFolder(input: T.AssistantAddAgentFolderRequest): Promise<T.AssistantAgentFolders>
194
+ removeAgentFolder(input: T.AssistantRemoveAgentFolderRequest): Promise<T.AssistantAgentFolders>
192
195
  }
193
196
 
194
197
  export interface CapabilityHandlers {
@@ -353,4 +356,7 @@ export interface CapabilityHandlers {
353
356
  forkChat(input: T.AssistantForkChatRequest): T.AssistantChat | Promise<T.AssistantChat>
354
357
  setBlindPeering(input: T.AssistantBlindPeering): T.AssistantBlindPeering | Promise<T.AssistantBlindPeering>
355
358
  blindPeeringWatch(input?: T.AssistantEmpty): AsyncIterable<T.AssistantBlindPeering>
359
+ listAgentFolders(input: T.AssistantAgentFoldersRequest): T.AssistantAgentFolders | Promise<T.AssistantAgentFolders>
360
+ addAgentFolder(input: T.AssistantAddAgentFolderRequest): T.AssistantAgentFolders | Promise<T.AssistantAgentFolders>
361
+ removeAgentFolder(input: T.AssistantRemoveAgentFolderRequest): T.AssistantAgentFolders | Promise<T.AssistantAgentFolders>
356
362
  }
@@ -2093,6 +2093,45 @@
2093
2093
  "stream": true
2094
2094
  },
2095
2095
  "version": 1
2096
+ },
2097
+ {
2098
+ "id": 161,
2099
+ "name": "@assistant/list-agent-folders",
2100
+ "request": {
2101
+ "name": "@assistant/agent-folders-request",
2102
+ "stream": false
2103
+ },
2104
+ "response": {
2105
+ "name": "@assistant/agent-folders",
2106
+ "stream": false
2107
+ },
2108
+ "version": 1
2109
+ },
2110
+ {
2111
+ "id": 162,
2112
+ "name": "@assistant/add-agent-folder",
2113
+ "request": {
2114
+ "name": "@assistant/add-agent-folder-request",
2115
+ "stream": false
2116
+ },
2117
+ "response": {
2118
+ "name": "@assistant/agent-folders",
2119
+ "stream": false
2120
+ },
2121
+ "version": 1
2122
+ },
2123
+ {
2124
+ "id": 163,
2125
+ "name": "@assistant/remove-agent-folder",
2126
+ "request": {
2127
+ "name": "@assistant/remove-agent-folder-request",
2128
+ "stream": false
2129
+ },
2130
+ "response": {
2131
+ "name": "@assistant/agent-folders",
2132
+ "stream": false
2133
+ },
2134
+ "version": 1
2096
2135
  }
2097
2136
  ]
2098
2137
  }