@neuralis/brain-core 0.2.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.
Files changed (123) hide show
  1. package/README.md +8 -3
  2. package/app/README.md +1 -1
  3. package/app/filesystem/README.md +3 -3
  4. package/app/filesystem/api/README.md +4 -4
  5. package/app/filesystem/api/index.ts +144 -139
  6. package/app/filesystem/domain/types.ts +12 -0
  7. package/app/filesystem/hooks/README.md +5 -5
  8. package/app/filesystem/hooks/useDiscoverableSources.ts +4 -2
  9. package/app/filesystem/hooks/useFilesystemSSE.ts +31 -23
  10. package/app/filesystem/hooks/useGitChangesInventory.ts +4 -2
  11. package/app/filesystem/host/README.md +3 -2
  12. package/app/filesystem/host/installFilesystemHostComponents.tsx +22 -9
  13. package/app/filesystem/store/README.md +12 -8
  14. package/app/filesystem/store/filesystemStore.ts +444 -163
  15. package/app/filesystem/store/gitSlice.ts +6 -6
  16. package/app/filesystem/store/listSlice.ts +9 -6
  17. package/app/filesystem/store/searchSlice.ts +3 -3
  18. package/app/filesystem/ui/FileEditor.tsx +90 -39
  19. package/app/filesystem/ui/FileTree.tsx +10 -9
  20. package/app/filesystem/ui/GitCommitChangesView.tsx +5 -3
  21. package/app/filesystem/ui/GitCommitGraph.tsx +6 -5
  22. package/app/filesystem/ui/GitControlPanel.tsx +14 -14
  23. package/app/filesystem/ui/GitDiffView.tsx +14 -6
  24. package/app/filesystem/ui/GitFileDiff.tsx +22 -15
  25. package/app/filesystem/ui/PendingChangesPanel.tsx +108 -44
  26. package/app/filesystem/ui/PendingReviewDialog.tsx +8 -5
  27. package/app/filesystem/ui/README.md +9 -9
  28. package/app/filesystem/ui/ReembedDialog.tsx +4 -2
  29. package/app/filesystem/ui/SourcesPanel.tsx +26 -28
  30. package/app/filesystem/ui/Toolbar.tsx +5 -4
  31. package/app/filesystem/ui/VectorHealthPanel.tsx +48 -17
  32. package/dist/app/host.js +46 -46
  33. package/dist/src/config/env.d.ts +4 -0
  34. package/dist/src/config/env.d.ts.map +1 -1
  35. package/dist/src/config/env.js +13 -0
  36. package/dist/src/config/env.js.map +1 -1
  37. package/dist/src/connectors/LocalDiskConnector.d.ts +9 -1
  38. package/dist/src/connectors/LocalDiskConnector.d.ts.map +1 -1
  39. package/dist/src/connectors/LocalDiskConnector.js +51 -2
  40. package/dist/src/connectors/LocalDiskConnector.js.map +1 -1
  41. package/dist/src/domain/healthTypes.d.ts +1 -7
  42. package/dist/src/domain/healthTypes.d.ts.map +1 -1
  43. package/dist/src/domain/pendingChange.d.ts +31 -0
  44. package/dist/src/domain/pendingChange.d.ts.map +1 -1
  45. package/dist/src/domain/pendingChange.js.map +1 -1
  46. package/dist/src/routes/health.js +2 -3
  47. package/dist/src/routes/health.js.map +1 -1
  48. package/dist/src/routes/pending.d.ts +7 -7
  49. package/dist/src/routes/pending.d.ts.map +1 -1
  50. package/dist/src/routes/pending.js +21 -21
  51. package/dist/src/routes/pending.js.map +1 -1
  52. package/dist/src/services/FilesystemService.d.ts +13 -61
  53. package/dist/src/services/FilesystemService.d.ts.map +1 -1
  54. package/dist/src/services/FilesystemService.js +47 -189
  55. package/dist/src/services/FilesystemService.js.map +1 -1
  56. package/dist/src/services/FilesystemUiService.d.ts +33 -1
  57. package/dist/src/services/FilesystemUiService.d.ts.map +1 -1
  58. package/dist/src/services/FilesystemUiService.js +50 -1
  59. package/dist/src/services/FilesystemUiService.js.map +1 -1
  60. package/dist/src/store/PendingChangeStore.d.ts +3 -0
  61. package/dist/src/store/PendingChangeStore.d.ts.map +1 -1
  62. package/dist/src/store/PendingChangeStore.js +84 -25
  63. package/dist/src/store/PendingChangeStore.js.map +1 -1
  64. package/dist/src/usecases/orphanedPending.d.ts +2 -2
  65. package/dist/src/usecases/orphanedPending.d.ts.map +1 -1
  66. package/dist/src/usecases/orphanedPending.js +5 -3
  67. package/dist/src/usecases/orphanedPending.js.map +1 -1
  68. package/dist/src/usecases/pendingListing.d.ts +34 -0
  69. package/dist/src/usecases/pendingListing.d.ts.map +1 -0
  70. package/dist/src/usecases/pendingListing.js +244 -0
  71. package/dist/src/usecases/pendingListing.js.map +1 -0
  72. package/dist/src/usecases/vectorMaintenance.d.ts +6 -9
  73. package/dist/src/usecases/vectorMaintenance.d.ts.map +1 -1
  74. package/dist/src/usecases/vectorMaintenance.js +4 -13
  75. package/dist/src/usecases/vectorMaintenance.js.map +1 -1
  76. package/dist/src/vector/InMemoryVectorIndex.d.ts.map +1 -1
  77. package/dist/src/vector/InMemoryVectorIndex.js +30 -9
  78. package/dist/src/vector/InMemoryVectorIndex.js.map +1 -1
  79. package/package.json +27 -5
  80. package/rules/brain-rules.md +1 -1
  81. package/skills/create-package/SKILL.md +3 -3
  82. package/skills/create-package/references/config-and-credentials.md +1 -1
  83. package/skills/create-package/references/manifest-and-discovery.md +1 -1
  84. package/skills/create-package/references/runtime-and-build.md +1 -1
  85. package/skills/create-package/references/skills-and-context.md +25 -12
  86. package/skills/create-package/references/surfaces-and-design.md +7 -5
  87. package/skills/create-package/references/test-and-ship.md +9 -16
  88. package/skills/create-package/scripts/check-package.sh +47 -1
  89. package/skills/create-package/scripts/verify-loaded.sh +18 -27
  90. package/skills/git/SKILL.md +27 -29
  91. package/skills/manage-files/SKILL.md +37 -32
  92. package/skills/manage-files/scripts/upload.sh +7 -9
  93. package/skills/manage-files/scripts/write.sh +2 -6
  94. package/skills/manage-sources/SKILL.md +93 -95
  95. package/skills/manage-sources/scripts/reembed.sh +2 -6
  96. package/skills/manage-uri-policy/SKILL.md +30 -58
  97. package/app/filesystem/hooks/useContainerWidth.ts +0 -39
  98. package/skills/git/scripts/git.sh +0 -48
  99. package/skills/manage-files/scripts/approve.sh +0 -9
  100. package/skills/manage-files/scripts/list.sh +0 -9
  101. package/skills/manage-files/scripts/pending.sh +0 -23
  102. package/skills/manage-files/scripts/raw.sh +0 -11
  103. package/skills/manage-files/scripts/read.sh +0 -9
  104. package/skills/manage-files/scripts/search.sh +0 -15
  105. package/skills/manage-sources/scripts/browse.sh +0 -12
  106. package/skills/manage-sources/scripts/cancel.sh +0 -14
  107. package/skills/manage-sources/scripts/create.sh +0 -13
  108. package/skills/manage-sources/scripts/delete.sh +0 -17
  109. package/skills/manage-sources/scripts/discoverable.sh +0 -6
  110. package/skills/manage-sources/scripts/get.sh +0 -7
  111. package/skills/manage-sources/scripts/kind-schema.sh +0 -7
  112. package/skills/manage-sources/scripts/kinds.sh +0 -6
  113. package/skills/manage-sources/scripts/list.sh +0 -6
  114. package/skills/manage-sources/scripts/purge-index.sh +0 -18
  115. package/skills/manage-sources/scripts/reindex.sh +0 -13
  116. package/skills/manage-sources/scripts/reset.sh +0 -11
  117. package/skills/manage-sources/scripts/set-enabled.sh +0 -17
  118. package/skills/manage-sources/scripts/sync-status.sh +0 -14
  119. package/skills/manage-sources/scripts/sync.sh +0 -13
  120. package/skills/manage-sources/scripts/update.sh +0 -18
  121. package/skills/manage-uri-policy/scripts/manifests.sh +0 -20
  122. package/skills/manage-uri-policy/scripts/set-uri.sh +0 -66
  123. package/skills/manage-uri-policy/scripts/show-uri.sh +0 -23
@@ -21,12 +21,15 @@ import type {
21
21
  } from '../domain/types';
22
22
 
23
23
  /**
24
- * Await the PackageApi for 'brain-core'. Uses tryGetPackageApiImperativeAsync so
25
- * that callers invoked at mount time don't race the PackageApiProvider registration.
24
+ * Every request takes its `client` as the LAST argument: a Files window passes
25
+ * the one its store was built with — `createPackageApi` over the window's project
26
+ * and BOUND agent (`createFilesWindowStore`) — so the X-Project-Id / X-Agent-Id
27
+ * headers are the window's own, fixed before any await, whatever other Files
28
+ * window or agent is mounted beside it. A request body may still name another
29
+ * agent (a file read through its writing agent); the header plane stays the
30
+ * window's. `readFiles` alone accepts no client, for the chat change card, which
31
+ * is not a Files window and reads through the first registered provider.
26
32
  */
27
- function api(): Promise<PackageApi> {
28
- return tryGetPackageApiImperativeAsync('brain-core');
29
- }
30
33
 
31
34
  export type ResolveListOpts = {
32
35
  /** Omit (or `/`) for the full-root view; otherwise a scope URI like `data://agent-core`. */
@@ -58,8 +61,9 @@ export type ResolveListOpts = {
58
61
 
59
62
  export async function resolveList(
60
63
  agentId: string,
61
- projectId?: string,
62
- opts?: ResolveListOpts,
64
+ projectId: string | undefined,
65
+ opts: ResolveListOpts,
66
+ client: PackageApi,
63
67
  ): Promise<{
64
68
  uri: string;
65
69
  folders: unknown[];
@@ -69,7 +73,6 @@ export async function resolveList(
69
73
  truncated?: boolean;
70
74
  summary_omitted_count?: number;
71
75
  }> {
72
- const a = await api();
73
76
  const body: Record<string, unknown> = { agentId };
74
77
  if (projectId) body.projectId = projectId;
75
78
  if (opts?.uri) body.uri = opts.uri;
@@ -81,7 +84,7 @@ export async function resolveList(
81
84
  if (typeof opts?.sources_only === 'boolean') body.sources_only = opts.sources_only;
82
85
  if (typeof opts?.include_counts === 'boolean') body.include_counts = opts.include_counts;
83
86
  if (typeof opts?.limit === 'number') body.limit = opts.limit;
84
- return a.post('list', body);
87
+ return client.post('list', body);
85
88
  }
86
89
 
87
90
  /**
@@ -95,6 +98,7 @@ export async function fetchSourceCounts(
95
98
  agentId: string,
96
99
  projectId: string | undefined,
97
100
  source: string,
101
+ client: PackageApi,
98
102
  ): Promise<SourceInfo | null> {
99
103
  const res = await resolveList(agentId, projectId, {
100
104
  uri: `${source}://`,
@@ -102,7 +106,7 @@ export async function fetchSourceCounts(
102
106
  include: 'folders',
103
107
  include_counts: true,
104
108
  limit: 1,
105
- });
109
+ }, client);
106
110
  return res.sources?.[0] ?? null;
107
111
  }
108
112
 
@@ -112,8 +116,8 @@ export async function readFiles(params: {
112
116
  files: string[];
113
117
  /** `baseline` reads the pre-change snapshot (for the Changes diff card). */
114
118
  read_version?: 'current' | 'baseline';
115
- }): Promise<FSReadResponse> {
116
- return (await api()).post('read', params);
119
+ }, client?: PackageApi): Promise<FSReadResponse> {
120
+ return (client ?? await tryGetPackageApiImperativeAsync('brain-core')).post('read', params);
117
121
  }
118
122
 
119
123
  export async function listSourceConfigs(params: {
@@ -121,20 +125,20 @@ export async function listSourceConfigs(params: {
121
125
  projectId?: string;
122
126
  scope?: 'project' | 'user' | 'agent';
123
127
  observed?: boolean;
124
- }): Promise<SourceConfigRecord[]> {
128
+ }, client: PackageApi): Promise<SourceConfigRecord[]> {
125
129
  const qs: Record<string, string> = { agentId: params.agentId };
126
130
  if (params.projectId) qs.projectId = params.projectId;
127
131
  if (params.scope) qs.scope = params.scope;
128
132
  if (params.observed) qs.observed = '1';
129
- return (await api()).get('sources', qs);
133
+ return client.get('sources', qs);
130
134
  }
131
135
 
132
136
  export async function updateSourceConfig(params: {
133
137
  agentId: string;
134
138
  projectId?: string;
135
139
  config: UpdateSourceConfigRequest;
136
- }): Promise<SourceConfigRecord> {
137
- return (await api()).patch('sources', {
140
+ }, client: PackageApi): Promise<SourceConfigRecord> {
141
+ return client.patch('sources', {
138
142
  agentId: params.agentId,
139
143
  ...(params.projectId ? { projectId: params.projectId } : {}),
140
144
  ...params.config,
@@ -149,8 +153,8 @@ export async function triggerSourceSync(params: {
149
153
  agentId: string;
150
154
  projectId?: string;
151
155
  source: string;
152
- }): Promise<TriggerSourceSyncResponse> {
153
- return (await api()).post('sources/sync', params);
156
+ }, client: PackageApi): Promise<TriggerSourceSyncResponse> {
157
+ return client.post('sources/sync', params);
154
158
  }
155
159
 
156
160
  /** Queue job status for one source (or every visible source when omitted). */
@@ -158,11 +162,11 @@ export async function getSyncStatus(params: {
158
162
  agentId: string;
159
163
  projectId?: string;
160
164
  source?: string;
161
- }): Promise<{ source?: string; job?: SyncJobSnapshotRecord | null; jobs?: SyncJobSnapshotRecord[] }> {
165
+ }, client: PackageApi): Promise<{ source?: string; job?: SyncJobSnapshotRecord | null; jobs?: SyncJobSnapshotRecord[] }> {
162
166
  const qs: Record<string, string> = { agentId: params.agentId };
163
167
  if (params.projectId) qs.projectId = params.projectId;
164
168
  if (params.source) qs.source = params.source;
165
- return (await api()).get('sources/sync-status', qs);
169
+ return client.get('sources/sync-status', qs);
166
170
  }
167
171
 
168
172
  /**
@@ -174,8 +178,8 @@ export async function setSourceEnabled(params: {
174
178
  projectId?: string;
175
179
  source: string;
176
180
  enabled: boolean | 'auto';
177
- }): Promise<SourceConfigRecord> {
178
- return (await api()).post('sources/enabled', {
181
+ }, client: PackageApi): Promise<SourceConfigRecord> {
182
+ return client.post('sources/enabled', {
179
183
  agentId: params.agentId,
180
184
  ...(params.projectId ? { projectId: params.projectId } : {}),
181
185
  source: params.source,
@@ -237,11 +241,11 @@ export type DiscoverableSourceSuggestion = {
237
241
  export async function listDiscoverableSources(params: {
238
242
  agentId: string;
239
243
  projectId?: string;
240
- }): Promise<{ suggestions: DiscoverableSourceSuggestion[] }> {
244
+ }, client: PackageApi): Promise<{ suggestions: DiscoverableSourceSuggestion[] }> {
241
245
  const qs = new URLSearchParams();
242
246
  qs.set('agentId', params.agentId);
243
247
  if (params.projectId) qs.set('projectId', params.projectId);
244
- return (await api()).get('sources/discoverable', Object.fromEntries(qs));
248
+ return client.get('sources/discoverable', Object.fromEntries(qs));
245
249
  }
246
250
 
247
251
  // ---------------------------------------------------------------------------
@@ -283,10 +287,10 @@ export async function getGitRepos(params: {
283
287
  agentId: string;
284
288
  projectId?: string;
285
289
  source: string;
286
- }): Promise<{ ok: boolean; repos: GitRepoInfo[] }> {
290
+ }, client: PackageApi): Promise<{ ok: boolean; repos: GitRepoInfo[] }> {
287
291
  const qs: Record<string, string> = { agentId: params.agentId, source: params.source };
288
292
  if (params.projectId) qs.projectId = params.projectId;
289
- return (await api()).get('git/repos', qs);
293
+ return client.get('git/repos', qs);
290
294
  }
291
295
 
292
296
  /**
@@ -299,7 +303,7 @@ export async function getGitStatus(params: {
299
303
  projectId?: string;
300
304
  source: string;
301
305
  repo?: string;
302
- }): Promise<{
306
+ }, client: PackageApi): Promise<{
303
307
  ok: boolean;
304
308
  status: GitControlStatus;
305
309
  /** Bucket `+/-` totals for the section headers, summed server-side over the
@@ -308,7 +312,7 @@ export async function getGitStatus(params: {
308
312
  }> {
309
313
  const qs: Record<string, string> = { agentId: params.agentId, source: params.source, ...repoQuery(params.repo) };
310
314
  if (params.projectId) qs.projectId = params.projectId;
311
- return (await api()).get('git/status', qs);
315
+ return client.get('git/status', qs);
312
316
  }
313
317
 
314
318
  /** Local branch list for the (G2.3) branch-switcher. */
@@ -317,10 +321,10 @@ export async function getGitBranches(params: {
317
321
  projectId?: string;
318
322
  source: string;
319
323
  repo?: string;
320
- }): Promise<{ ok: boolean; branches: GitBranchInfo[]; truncated?: boolean }> {
324
+ }, client: PackageApi): Promise<{ ok: boolean; branches: GitBranchInfo[]; truncated?: boolean }> {
321
325
  const qs: Record<string, string> = { agentId: params.agentId, source: params.source, ...repoQuery(params.repo) };
322
326
  if (params.projectId) qs.projectId = params.projectId;
323
- return (await api()).get('git/branch', qs);
327
+ return client.get('git/branch', qs);
324
328
  }
325
329
 
326
330
  /**
@@ -356,7 +360,7 @@ export async function getGitDiff(params: {
356
360
  commit?: string;
357
361
  base?: string;
358
362
  head?: string;
359
- }): Promise<
363
+ }, client: PackageApi): Promise<
360
364
  | {
361
365
  ok: true;
362
366
  diff: string;
@@ -390,7 +394,7 @@ export async function getGitDiff(params: {
390
394
  if (typeof params.head === 'string') qs.head = params.head;
391
395
  if (typeof params.staged === 'boolean') qs.staged = params.staged ? '1' : '0';
392
396
  if (params.projectId) qs.projectId = params.projectId;
393
- return (await api()).get('git/diff', qs);
397
+ return client.get('git/diff', qs);
394
398
  }
395
399
 
396
400
  /**
@@ -414,13 +418,13 @@ export async function getGitLog(params: {
414
418
  maxCount?: number;
415
419
  skip?: number;
416
420
  ref?: string;
417
- }): Promise<{ ok: boolean; commits: GitGraphCommit[]; hasMore: boolean; outgoing?: string[] }> {
421
+ }, client: PackageApi): Promise<{ ok: boolean; commits: GitGraphCommit[]; hasMore: boolean; outgoing?: string[] }> {
418
422
  const qs: Record<string, string> = { agentId: params.agentId, source: params.source, ...repoQuery(params.repo) };
419
423
  if (params.projectId) qs.projectId = params.projectId;
420
424
  if (typeof params.maxCount === 'number') qs.maxCount = String(params.maxCount);
421
425
  if (typeof params.skip === 'number') qs.skip = String(params.skip);
422
426
  if (params.ref) qs.ref = params.ref;
423
- return (await api()).get('git/log', qs);
427
+ return client.get('git/log', qs);
424
428
  }
425
429
 
426
430
  /**
@@ -444,13 +448,13 @@ export async function getGitLogStats(params: {
444
448
  maxCount?: number;
445
449
  skip?: number;
446
450
  ref?: string;
447
- }): Promise<GitLogStatsResponse> {
451
+ }, client: PackageApi): Promise<GitLogStatsResponse> {
448
452
  const qs: Record<string, string> = { agentId: params.agentId, source: params.source, ...repoQuery(params.repo) };
449
453
  if (params.projectId) qs.projectId = params.projectId;
450
454
  if (typeof params.maxCount === 'number') qs.maxCount = String(params.maxCount);
451
455
  if (typeof params.skip === 'number') qs.skip = String(params.skip);
452
456
  if (params.ref) qs.ref = params.ref;
453
- return (await api()).get('git/log-stats', qs);
457
+ return client.get('git/log-stats', qs);
454
458
  }
455
459
 
456
460
  /**
@@ -469,7 +473,7 @@ export async function getGitCommitFiles(params: {
469
473
  source: string;
470
474
  repo?: string;
471
475
  sha: string;
472
- }): Promise<
476
+ }, client: PackageApi): Promise<
473
477
  | { ok: true; sha: string; files: GitCommitFileChange[] }
474
478
  | { ok: false; code: 'unavailable'; sha: string }
475
479
  > {
@@ -480,7 +484,7 @@ export async function getGitCommitFiles(params: {
480
484
  sha: params.sha,
481
485
  };
482
486
  if (params.projectId) qs.projectId = params.projectId;
483
- return (await api()).get('git/commit', qs);
487
+ return client.get('git/commit', qs);
484
488
  }
485
489
 
486
490
  /**
@@ -498,7 +502,7 @@ export async function getGitOutgoing(params: {
498
502
  projectId?: string;
499
503
  source: string;
500
504
  repo?: string;
501
- }): Promise<{
505
+ }, client: PackageApi): Promise<{
502
506
  ok: boolean;
503
507
  // Present on the `ok:true` shapes (ready | honest no-upstream). A DEEP failure
504
508
  // (non-repo / unborn HEAD / any git error) is a typed refusal `{ok:false,
@@ -511,7 +515,7 @@ export async function getGitOutgoing(params: {
511
515
  }> {
512
516
  const qs: Record<string, string> = { agentId: params.agentId, source: params.source, ...repoQuery(params.repo) };
513
517
  if (params.projectId) qs.projectId = params.projectId;
514
- return (await api()).get('git/outgoing', qs);
518
+ return client.get('git/outgoing', qs);
515
519
  }
516
520
 
517
521
  /**
@@ -531,7 +535,7 @@ export async function getGitShow(params: {
531
535
  repo?: string;
532
536
  path: string;
533
537
  rev: string;
534
- }): Promise<
538
+ }, client: PackageApi): Promise<
535
539
  | { ok: true; content: string; path: string; rev: string }
536
540
  | { ok: false; code: 'not_a_blob' | 'too_large' | 'binary' | 'unavailable'; path: string; rev: string }
537
541
  > {
@@ -543,7 +547,7 @@ export async function getGitShow(params: {
543
547
  rev: params.rev,
544
548
  };
545
549
  if (params.projectId) qs.projectId = params.projectId;
546
- return (await api()).get('git/show', qs);
550
+ return client.get('git/show', qs);
547
551
  }
548
552
 
549
553
  // ---------------------------------------------------------------------------
@@ -560,8 +564,6 @@ export async function getGitShow(params: {
560
564
  // recovered from), surfaced for the best-effort undo affordance.
561
565
  // ---------------------------------------------------------------------------
562
566
 
563
- const git = () => api();
564
-
565
567
  /**
566
568
  * The typed rescue carrier a destructive op returns (G2.5) — drives one-click
567
569
  * UNDO via `restoreGit`. `stash` → `git stash apply <ref>` (discarded content);
@@ -577,8 +579,8 @@ export async function stagePaths(params: {
577
579
  source: string;
578
580
  repo?: string;
579
581
  paths: string[];
580
- }): Promise<{ ok: boolean; staged: string[] | 'hunk' }> {
581
- return (await git()).post('git/stage', {
582
+ }, client: PackageApi): Promise<{ ok: boolean; staged: string[] | 'hunk' }> {
583
+ return client.post('git/stage', {
582
584
  source: params.source,
583
585
  ...repoBody(params.repo),
584
586
  paths: params.paths,
@@ -594,8 +596,8 @@ export async function unstagePaths(params: {
594
596
  source: string;
595
597
  repo?: string;
596
598
  paths: string[];
597
- }): Promise<{ ok: boolean; unstaged: string[] | 'hunk' }> {
598
- return (await git()).post('git/unstage', {
599
+ }, client: PackageApi): Promise<{ ok: boolean; unstaged: string[] | 'hunk' }> {
600
+ return client.post('git/unstage', {
599
601
  source: params.source,
600
602
  ...repoBody(params.repo),
601
603
  paths: params.paths,
@@ -614,8 +616,8 @@ export async function stageHunk(params: {
614
616
  source: string;
615
617
  repo?: string;
616
618
  hunk: string;
617
- }): Promise<{ ok: boolean; staged: string[] | 'hunk' }> {
618
- return (await git()).post('git/stage', {
619
+ }, client: PackageApi): Promise<{ ok: boolean; staged: string[] | 'hunk' }> {
620
+ return client.post('git/stage', {
619
621
  source: params.source,
620
622
  ...repoBody(params.repo),
621
623
  hunk: params.hunk,
@@ -631,8 +633,8 @@ export async function unstageHunk(params: {
631
633
  source: string;
632
634
  repo?: string;
633
635
  hunk: string;
634
- }): Promise<{ ok: boolean; unstaged: string[] | 'hunk' }> {
635
- return (await git()).post('git/unstage', {
636
+ }, client: PackageApi): Promise<{ ok: boolean; unstaged: string[] | 'hunk' }> {
637
+ return client.post('git/unstage', {
636
638
  source: params.source,
637
639
  ...repoBody(params.repo),
638
640
  hunk: params.hunk,
@@ -653,8 +655,8 @@ export async function discardPaths(params: {
653
655
  source: string;
654
656
  repo?: string;
655
657
  paths: string[];
656
- }): Promise<{ ok: boolean; discarded: string[]; rescue?: GitRescue }> {
657
- return (await git()).post('git/discard', {
658
+ }, client: PackageApi): Promise<{ ok: boolean; discarded: string[]; rescue?: GitRescue }> {
659
+ return client.post('git/discard', {
658
660
  source: params.source,
659
661
  ...repoBody(params.repo),
660
662
  paths: params.paths,
@@ -671,8 +673,8 @@ export async function commitGit(params: {
671
673
  repo?: string;
672
674
  message: string;
673
675
  amend?: boolean;
674
- }): Promise<{ ok: boolean; commit: string }> {
675
- return (await git()).post('git/commit', {
676
+ }, client: PackageApi): Promise<{ ok: boolean; commit: string }> {
677
+ return client.post('git/commit', {
676
678
  source: params.source,
677
679
  ...repoBody(params.repo),
678
680
  message: params.message,
@@ -690,8 +692,8 @@ export async function createGitBranch(params: {
690
692
  repo?: string;
691
693
  name: string;
692
694
  startPoint?: string;
693
- }): Promise<{ ok: boolean; branch: string; action: 'create' }> {
694
- return (await git()).post('git/branch', {
695
+ }, client: PackageApi): Promise<{ ok: boolean; branch: string; action: 'create' }> {
696
+ return client.post('git/branch', {
695
697
  source: params.source,
696
698
  ...repoBody(params.repo),
697
699
  action: 'create',
@@ -714,8 +716,8 @@ export async function deleteGitBranch(params: {
714
716
  repo?: string;
715
717
  name: string;
716
718
  force?: boolean;
717
- }): Promise<{ ok: boolean; branch: string; action: 'delete'; rescue?: GitRescue }> {
718
- return (await git()).post('git/branch', {
719
+ }, client: PackageApi): Promise<{ ok: boolean; branch: string; action: 'delete'; rescue?: GitRescue }> {
720
+ return client.post('git/branch', {
719
721
  source: params.source,
720
722
  ...repoBody(params.repo),
721
723
  action: 'delete',
@@ -738,8 +740,8 @@ export async function restoreGit(params: {
738
740
  source: string;
739
741
  repo?: string;
740
742
  rescue: GitRescue;
741
- }): Promise<{ ok: boolean; restored: 'stash' | 'branch' }> {
742
- return (await git()).post('git/restore', {
743
+ }, client: PackageApi): Promise<{ ok: boolean; restored: 'stash' | 'branch' }> {
744
+ return client.post('git/restore', {
743
745
  source: params.source,
744
746
  ...repoBody(params.repo),
745
747
  rescue: params.rescue,
@@ -758,8 +760,8 @@ export async function checkoutGitBranch(params: {
758
760
  source: string;
759
761
  repo?: string;
760
762
  ref: string;
761
- }): Promise<{ ok: boolean; checkout: string }> {
762
- return (await git()).post('git/checkout', {
763
+ }, client: PackageApi): Promise<{ ok: boolean; checkout: string }> {
764
+ return client.post('git/checkout', {
763
765
  source: params.source,
764
766
  ...repoBody(params.repo),
765
767
  ref: params.ref,
@@ -781,8 +783,8 @@ export async function fetchGit(params: {
781
783
  projectId?: string;
782
784
  source: string;
783
785
  repo?: string;
784
- }): Promise<{ ok: boolean; op: 'fetch'; host: string; status?: GitControlStatus }> {
785
- return (await git()).post('git/fetch', {
786
+ }, client: PackageApi): Promise<{ ok: boolean; op: 'fetch'; host: string; status?: GitControlStatus }> {
787
+ return client.post('git/fetch', {
786
788
  source: params.source,
787
789
  ...repoBody(params.repo),
788
790
  ...(params.projectId ? { projectId: params.projectId } : {}),
@@ -796,8 +798,8 @@ export async function pullGit(params: {
796
798
  projectId?: string;
797
799
  source: string;
798
800
  repo?: string;
799
- }): Promise<{ ok: boolean; op: 'pull'; host: string; status?: GitControlStatus }> {
800
- return (await git()).post('git/pull', {
801
+ }, client: PackageApi): Promise<{ ok: boolean; op: 'pull'; host: string; status?: GitControlStatus }> {
802
+ return client.post('git/pull', {
801
803
  source: params.source,
802
804
  ...repoBody(params.repo),
803
805
  ...(params.projectId ? { projectId: params.projectId } : {}),
@@ -811,8 +813,8 @@ export async function pushGit(params: {
811
813
  projectId?: string;
812
814
  source: string;
813
815
  repo?: string;
814
- }): Promise<{ ok: boolean; op: 'push'; host: string }> {
815
- return (await git()).post('git/push', {
816
+ }, client: PackageApi): Promise<{ ok: boolean; op: 'push'; host: string }> {
817
+ return client.post('git/push', {
816
818
  source: params.source,
817
819
  ...repoBody(params.repo),
818
820
  ...(params.projectId ? { projectId: params.projectId } : {}),
@@ -836,8 +838,8 @@ export async function searchFiles(params: {
836
838
  created_before?: string;
837
839
  include_siblings?: boolean;
838
840
  limit?: number;
839
- }): Promise<FSSearchResponse> {
840
- return (await api()).post('search', params);
841
+ }, client: PackageApi): Promise<FSSearchResponse> {
842
+ return client.post('search', params);
841
843
  }
842
844
 
843
845
  /**
@@ -855,14 +857,14 @@ export async function uploadFile(params: {
855
857
  file: File;
856
858
  uri?: string;
857
859
  tags?: string[];
858
- }): Promise<FSUploadResponse> {
860
+ }, client: PackageApi): Promise<FSUploadResponse> {
859
861
  const form = new FormData();
860
862
  form.append('agentId', params.agentId);
861
863
  if (params.projectId) form.append('projectId', params.projectId);
862
864
  form.append('file', params.file);
863
865
  if (params.uri) form.append('uri', params.uri);
864
866
  if (params.tags?.length) form.append('tags', params.tags.join(','));
865
- return (await api()).upload('upload', form);
867
+ return client.upload('upload', form);
866
868
  }
867
869
 
868
870
  /**
@@ -901,8 +903,9 @@ export type FSWriteRequest = {
901
903
 
902
904
  export async function writeFile(
903
905
  params: { agentId: string; projectId?: string } & FSWriteRequest,
906
+ client: PackageApi,
904
907
  ): Promise<FSWriteResponse> {
905
- return (await api()).post('write', params);
908
+ return client.post('write', params);
906
909
  }
907
910
 
908
911
  /**
@@ -927,8 +930,8 @@ export async function approveFileReview(params: {
927
930
  uri?: string;
928
931
  expectedFingerprint?: string;
929
932
  acknowledgeCurrentState?: true;
930
- }): Promise<FSReviewApproveResponse> {
931
- return (await api()).post('approve', params);
933
+ }, client: PackageApi): Promise<FSReviewApproveResponse> {
934
+ return client.post('approve', params);
932
935
  }
933
936
 
934
937
  // ---------------------------------------------------------------------------
@@ -940,14 +943,17 @@ export async function approveFileReview(params: {
940
943
  // ---------------------------------------------------------------------------
941
944
 
942
945
  export type { PendingChangeRecord, PendingPreview, PendingReviewIntent } from '@neuralis/brain-core/domain/pending-change';
943
- import type { PendingChangeRecord, PendingPreview } from '@neuralis/brain-core/domain/pending-change';
946
+ import type { PendingChangeRecord, PendingPreview, PendingChangePage, PendingCount, PendingRepairPage } from '@neuralis/brain-core/domain/pending-change';
947
+ export type { PendingChangePage, PendingCount, PendingRepairPage } from '@neuralis/brain-core/domain/pending-change';
944
948
 
945
- export async function previewPendingChange(params: { agentId: string; projectId?: string; id: string }): Promise<PendingPreview> {
946
- const result = await (await api()).post('pending', { ...params, action: 'preview' }) as { preview: PendingPreview };
949
+ export async function previewPendingChange(params: { agentId: string; projectId?: string; id: string }, client: PackageApi): Promise<PendingPreview> {
950
+ const result = await client.post('pending', { ...params, action: 'preview' }) as { preview: PendingPreview };
947
951
  return result.preview;
948
952
  }
949
953
 
950
954
  export type PendingChangesQuery = {
955
+ cursor?: string;
956
+ uri?: string;
951
957
  agentId: string;
952
958
  projectId?: string;
953
959
  userId?: string;
@@ -970,26 +976,25 @@ export type PendingChangesQuery = {
970
976
  */
971
977
  export async function listPendingChanges(
972
978
  params: PendingChangesQuery,
973
- ): Promise<{ ok: boolean; changes: PendingChangeRecord[]; orphanIds: string[] }> {
974
- const res = await (await api()).post('pending', params) as {
975
- ok?: boolean; changes?: PendingChangeRecord[]; orphanIds?: string[];
976
- };
977
- return {
978
- ok: res?.ok !== false,
979
- changes: Array.isArray(res?.changes) ? res.changes : [],
980
- orphanIds: Array.isArray(res?.orphanIds) ? res.orphanIds : [],
981
- };
979
+ client: PackageApi,
980
+ ): Promise<PendingChangePage & { ok: boolean }> {
981
+ const res = await client.post('pending', params) as PendingChangePage & { ok: boolean };
982
+ if (!Array.isArray(res.changes) || typeof res.complete !== 'boolean' || typeof res.partial !== 'boolean') {
983
+ throw new Error('Pending listing unavailable; retry the request');
984
+ }
985
+ return res;
982
986
  }
983
987
 
984
988
  /**
985
989
  * The caller's visible pending COUNT — the list's own per-record floor, no orphan
986
990
  * probe and no rows on the wire. Feeds the Changes badge.
987
991
  */
988
- export async function countPendingChanges(params: { agentId: string; projectId?: string }): Promise<number> {
992
+ export async function countPendingChanges(params: { agentId: string; projectId?: string }, client: PackageApi): Promise<PendingCount> {
989
993
  const qs: Record<string, string> = { agentId: params.agentId, count_only: '1' };
990
994
  if (params.projectId) qs.projectId = params.projectId;
991
- const res = await (await api()).get('pending', qs) as { count?: number };
992
- return typeof res?.count === 'number' ? res.count : 0;
995
+ const res = await client.get('pending', qs) as PendingCount;
996
+ if (!Number.isInteger(res.count) || res.count < 0 || typeof res.exact !== 'boolean') throw new Error('Pending count unavailable');
997
+ return res;
993
998
  }
994
999
 
995
1000
  export async function revertPendingChange(params: {
@@ -998,8 +1003,8 @@ export async function revertPendingChange(params: {
998
1003
  id: string;
999
1004
  expectedFingerprint?: string;
1000
1005
  acknowledgeCurrentState?: true;
1001
- }): Promise<{ ok: boolean; id: string; uri?: string; error?: string }> {
1002
- return (await api()).post('pending', { ...params, action: 'revert' }) as Promise<{ ok: boolean; id: string; uri?: string; error?: string }>;
1006
+ }, client: PackageApi): Promise<{ ok: boolean; id: string; uri?: string; error?: string }> {
1007
+ return client.post('pending', { ...params, action: 'revert' }) as Promise<{ ok: boolean; id: string; uri?: string; error?: string }>;
1003
1008
  }
1004
1009
 
1005
1010
  /** Scan the caller's visible pending changes for ORPHANED rows — backing target
@@ -1009,9 +1014,10 @@ export async function scanOrphanedPending(params: {
1009
1014
  agentId: string;
1010
1015
  projectId?: string;
1011
1016
  conversationId?: string;
1012
- }): Promise<{ ok: boolean; orphans: PendingChangeRecord[] }> {
1013
- const res = await (await api()).post('pending', { ...params, action: 'scan-orphans' }) as { ok?: boolean; orphans?: PendingChangeRecord[] };
1014
- return { ok: res?.ok !== false, orphans: Array.isArray(res?.orphans) ? res.orphans : [] };
1017
+ cursor?: string;
1018
+ uri?: string;
1019
+ }, client: PackageApi): Promise<PendingChangePage & { ok: boolean; orphans: PendingChangeRecord[] }> {
1020
+ return client.post('pending', { ...params, action: 'scan-orphans' }) as Promise<PendingChangePage & { ok: boolean; orphans: PendingChangeRecord[] }>;
1015
1021
  }
1016
1022
 
1017
1023
  /** Discard ONE orphaned pending record (journal mark + blob + vector point) —
@@ -1020,8 +1026,8 @@ export async function discardPendingChange(params: {
1020
1026
  agentId: string;
1021
1027
  projectId?: string;
1022
1028
  id: string;
1023
- }): Promise<{ ok: boolean; id: string; uri?: string; error?: string }> {
1024
- return (await api()).post('pending', { ...params, action: 'discard' }) as Promise<{ ok: boolean; id: string; uri?: string; error?: string }>;
1029
+ }, client: PackageApi): Promise<{ ok: boolean; id: string; uri?: string; error?: string }> {
1030
+ return client.post('pending', { ...params, action: 'discard' }) as Promise<{ ok: boolean; id: string; uri?: string; error?: string }>;
1025
1031
  }
1026
1032
 
1027
1033
  /** DISMISS ONE live-source pending record — the op-aware "accept-and-stop-
@@ -1034,19 +1040,16 @@ export async function dismissPendingChange(params: {
1034
1040
  id: string;
1035
1041
  expectedFingerprint?: string;
1036
1042
  acknowledgeCurrentState?: true;
1037
- }): Promise<{ ok: boolean; id: string; uri?: string; error?: string; retryable?: boolean }> {
1038
- return (await api()).post('pending', { ...params, action: 'dismiss' }) as Promise<{ ok: boolean; id: string; uri?: string; error?: string; retryable?: boolean }>;
1043
+ }, client: PackageApi): Promise<{ ok: boolean; id: string; uri?: string; error?: string; retryable?: boolean }> {
1044
+ return client.post('pending', { ...params, action: 'dismiss' }) as Promise<{ ok: boolean; id: string; uri?: string; error?: string; retryable?: boolean }>;
1039
1045
  }
1040
1046
 
1041
- /** Bulk-discard every orphaned pending change the caller can write (the Repair
1042
- * button). Returns the actual discarded count. */
1047
+ /** Repair one visible page through the shared owner; callers continue explicitly
1048
+ * with nextCursor and pause on partial/failure. Counters describe actual effects. */
1043
1049
  export async function discardOrphanedPending(params: {
1044
- agentId: string;
1045
- projectId?: string;
1046
- conversationId?: string;
1047
- }): Promise<{ ok: boolean; discarded: number }> {
1048
- const res = await (await api()).post('pending', { ...params, action: 'discard-orphans' }) as { ok?: boolean; discarded?: number };
1049
- return { ok: res?.ok !== false, discarded: typeof res?.discarded === 'number' ? res.discarded : 0 };
1050
+ agentId: string; projectId?: string; conversationId?: string; cursor?: string;
1051
+ }, client: PackageApi): Promise<PendingRepairPage> {
1052
+ return client.post('pending', { ...params, action: 'discard-orphans' }) as Promise<PendingRepairPage>;
1050
1053
  }
1051
1054
 
1052
1055
  export function getRawFileUrl(agentId: string, uri: string, projectId?: string): string {
@@ -1066,16 +1069,16 @@ export function getRawFileUrl(agentId: string, uri: string, projectId?: string):
1066
1069
  export async function checkVectorHealth(params: {
1067
1070
  agentId: string;
1068
1071
  projectId?: string;
1069
- }): Promise<Record<string, unknown>> {
1070
- return (await api()).post('health', params);
1072
+ }, client: PackageApi): Promise<Record<string, unknown>> {
1073
+ return client.post('health', params);
1071
1074
  }
1072
1075
 
1073
1076
  /** Expensive integrity scan (orphan + duplicate detection) — explicit only. */
1074
1077
  export async function scanVectorHealth(params: {
1075
1078
  agentId: string;
1076
1079
  projectId?: string;
1077
- }): Promise<{ orphanChunkCount?: number; duplicateGroups?: number; generatedAt?: string }> {
1078
- return (await api()).post('health/scan', params);
1080
+ }, client: PackageApi): Promise<{ orphanChunkCount?: number; duplicateGroups?: number; generatedAt?: string }> {
1081
+ return client.post('health/scan', params);
1079
1082
  }
1080
1083
 
1081
1084
  export async function runHealthAction(params: {
@@ -1084,12 +1087,13 @@ export async function runHealthAction(params: {
1084
1087
  action: 'gc' | 'repair-orphans' | 'deduplicate' | 'repair-pending';
1085
1088
  dryRun?: boolean;
1086
1089
  retentionHours?: number;
1087
- }): Promise<Record<string, unknown>> {
1088
- return (await api()).post('health/gc', params);
1090
+ cursor?: string;
1091
+ }, client: PackageApi): Promise<Record<string, unknown>> {
1092
+ return client.post('health/gc', params);
1089
1093
  }
1090
1094
 
1091
- export async function createSource(params: CreateSourceRequest): Promise<SourceConfigRecord> {
1092
- return (await api()).post('sources', params);
1095
+ export async function createSource(params: CreateSourceRequest, client: PackageApi): Promise<SourceConfigRecord> {
1096
+ return client.post('sources', params);
1093
1097
  }
1094
1098
 
1095
1099
  export async function deleteSource(params: {
@@ -1101,19 +1105,19 @@ export async function deleteSource(params: {
1101
1105
  * false/omitted, only the config and in-memory connector binding are
1102
1106
  * removed; vectors stay in Qdrant. */
1103
1107
  purgeVectors?: boolean;
1104
- }): Promise<{ ok: true; purgeJob?: SyncJobSnapshotRecord }> {
1108
+ }, client: PackageApi): Promise<{ ok: true; purgeJob?: SyncJobSnapshotRecord }> {
1105
1109
  const qs = new URLSearchParams({ agentId: params.agentId });
1106
1110
  if (params.projectId) qs.set('projectId', params.projectId);
1107
1111
  if (params.purgeVectors) qs.set('purge', '1');
1108
- return (await api()).del(`sources/${encodeURIComponent(params.source)}?${qs.toString()}`);
1112
+ return client.del(`sources/${encodeURIComponent(params.source)}?${qs.toString()}`);
1109
1113
  }
1110
1114
 
1111
1115
  export async function resetSync(params: {
1112
1116
  agentId: string;
1113
1117
  projectId?: string;
1114
1118
  source: string;
1115
- }): Promise<{ ok: true; source: string }> {
1116
- return (await api()).post('sources/reset', params);
1119
+ }, client: PackageApi): Promise<{ ok: true; source: string }> {
1120
+ return client.post('sources/reset', params);
1117
1121
  }
1118
1122
 
1119
1123
  /**
@@ -1124,8 +1128,8 @@ export async function reindexSource(params: {
1124
1128
  agentId: string;
1125
1129
  projectId?: string;
1126
1130
  source: string;
1127
- }): Promise<SyncJobSnapshotRecord> {
1128
- return (await api()).post('sources/reindex', params);
1131
+ }, client: PackageApi): Promise<SyncJobSnapshotRecord> {
1132
+ return client.post('sources/reindex', params);
1129
1133
  }
1130
1134
 
1131
1135
  export type IndexPurgeCounts = { removedParents: number; removedChunks: number; retained: number; unresolved: number; canMaintain: boolean };
@@ -1133,8 +1137,8 @@ export type IndexPurgeSelector = { kind: 'source' } | { kind: 'folder' | 'file';
1133
1137
  export async function purgeSourceIndex(params: {
1134
1138
  agentId: string; projectId?: string; source: string;
1135
1139
  selector: IndexPurgeSelector; mode: 'estimate' | 'apply'; obsoleteOnly?: boolean;
1136
- }): Promise<IndexPurgeCounts> {
1137
- return (await api()).post('sources/purge', params);
1140
+ }, client: PackageApi): Promise<IndexPurgeCounts> {
1141
+ return client.post('sources/purge', params);
1138
1142
  }
1139
1143
 
1140
1144
  /** The scope of a forced re-embed: the whole source, one `folder`, or one `uri` (full URIs). */
@@ -1202,9 +1206,9 @@ const reembedVerb = (kind: ReembedKind) => (kind === 'pending' ? { embeddingOnly
1202
1206
  * source's sync markers — an estimate has no side effect. For `pending` the
1203
1207
  * figures are an upper bound: the whole scope, of which only the owed part runs.
1204
1208
  */
1205
- export async function estimateReembed(params: ReembedScope, kind: ReembedKind = 'reembed'): Promise<ReembedEstimate | null> {
1209
+ export async function estimateReembed(params: ReembedScope, kind: ReembedKind, client: PackageApi): Promise<ReembedEstimate | null> {
1206
1210
  return normalizeReembedEstimate(
1207
- await (await api()).post<unknown>('sources/reindex', { ...params, ...reembedVerb(kind), estimate: true }),
1211
+ await client.post<unknown>('sources/reindex', { ...params, ...reembedVerb(kind), estimate: true }),
1208
1212
  );
1209
1213
  }
1210
1214
 
@@ -1215,9 +1219,10 @@ export async function estimateReembed(params: ReembedScope, kind: ReembedKind =
1215
1219
  */
1216
1220
  export async function startReembed(
1217
1221
  params: ReembedScope,
1218
- kind: ReembedKind = 'reembed',
1222
+ kind: ReembedKind,
1223
+ client: PackageApi,
1219
1224
  ): Promise<{ documents: number | null; truncated: boolean; job: SyncJobSnapshotRecord | null }> {
1220
- const raw = await (await api()).post<Record<string, unknown> | null>('sources/reindex', { ...params, ...reembedVerb(kind) });
1225
+ const raw = await client.post<Record<string, unknown> | null>('sources/reindex', { ...params, ...reembedVerb(kind) });
1221
1226
  const job = raw?.job && typeof raw.job === 'object' ? (raw.job as SyncJobSnapshotRecord) : null;
1222
1227
  return { documents: finiteOrNull(raw?.documents), truncated: raw?.truncated === true, job };
1223
1228
  }
@@ -1230,14 +1235,14 @@ export async function cancelSync(params: {
1230
1235
  agentId: string;
1231
1236
  projectId?: string;
1232
1237
  source?: string;
1233
- }): Promise<{ ok: true; source?: string; cancelled: boolean | number }> {
1234
- return (await api()).post('sources/cancel', params);
1238
+ }, client: PackageApi): Promise<{ ok: true; source?: string; cancelled: boolean | number }> {
1239
+ return client.post('sources/cancel', params);
1235
1240
  }
1236
1241
 
1237
1242
  export async function getSourcesHealth(params: {
1238
1243
  agentId: string;
1239
1244
  projectId?: string;
1240
- }): Promise<Array<{
1245
+ }, client: PackageApi): Promise<Array<{
1241
1246
  source: string;
1242
1247
  source_kind: string;
1243
1248
  sync_status: string;
@@ -1245,7 +1250,7 @@ export async function getSourcesHealth(params: {
1245
1250
  }>> {
1246
1251
  const qs: Record<string, string> = { agentId: params.agentId };
1247
1252
  if (params.projectId) qs.projectId = params.projectId;
1248
- return (await api()).get('sources/health', qs);
1253
+ return client.get('sources/health', qs);
1249
1254
  }
1250
1255
 
1251
1256
  /**
@@ -1262,10 +1267,10 @@ export async function browseDirectories(params: {
1262
1267
  path: string;
1263
1268
  agentId: string;
1264
1269
  projectId?: string;
1265
- }): Promise<{ entries: Array<{ name: string; path: string; type: 'directory' }> }> {
1270
+ }, client: PackageApi): Promise<{ entries: Array<{ name: string; path: string; type: 'directory' }> }> {
1266
1271
  const qs: Record<string, string> = { path: params.path, agentId: params.agentId };
1267
1272
  if (params.projectId) qs.projectId = params.projectId;
1268
- return (await api()).get('sources/browse', qs);
1273
+ return client.get('sources/browse', qs);
1269
1274
  }
1270
1275
 
1271
1276
  export type SourceKindRecord = {
@@ -1296,10 +1301,10 @@ export type SourceKindSchema = {
1296
1301
  defaultSyncExcludes?: string[];
1297
1302
  };
1298
1303
 
1299
- export async function listSourceKinds(): Promise<{ kinds: SourceKindRecord[] }> {
1300
- return (await api()).get('sources/kinds', {});
1304
+ export async function listSourceKinds(client: PackageApi): Promise<{ kinds: SourceKindRecord[] }> {
1305
+ return client.get('sources/kinds', {});
1301
1306
  }
1302
1307
 
1303
- export async function getSourceKindSchema(kind: string): Promise<SourceKindSchema> {
1304
- return (await api()).get(`sources/kinds/${encodeURIComponent(kind)}/schema`, {});
1308
+ export async function getSourceKindSchema(kind: string, client: PackageApi): Promise<SourceKindSchema> {
1309
+ return client.get(`sources/kinds/${encodeURIComponent(kind)}/schema`, {});
1305
1310
  }