-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathworkspaceBindings.ts
More file actions
184 lines (168 loc) · 6.2 KB
/
Copy pathworkspaceBindings.ts
File metadata and controls
184 lines (168 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { invoke } from '@tauri-apps/api/core';
/**
* A WorkspaceBinding maps one normalized filesystem path to one or more
* FeatureSets within a Space. When an MCP session reports a root that
* matches a binding (longest-prefix wins), the resolver hands back the
* binding's `space_id` and the union of `feature_set_ids` — multiple FSes
* compose into a single allow set, no "follow active" indirection.
*/
export interface WorkspaceBinding {
id: string;
workspace_root: string;
space_id: string;
/**
* Non-empty by construction. Order is the operator-chosen rendering
* order; the resolver treats the list as a set. FeatureSet ids are
* strings (builtins use `fs_default_<space>`, customs use UUIDs).
*/
feature_set_ids: string[];
created_at: string;
updated_at: string;
}
/** Input payload for create / update. `feature_set_ids` must be non-empty. */
export interface WorkspaceBindingInput {
workspace_root: string;
space_id: string;
feature_set_ids: string[];
}
/** List every binding (sorted by workspace_root). */
export async function listWorkspaceBindings(): Promise<WorkspaceBinding[]> {
return invoke('list_workspace_bindings');
}
/**
* Every filesystem root that connected MCP clients have reported during
* their current sessions, deduplicated across sessions. Surfaces folders
* that aren't bound yet so the user can configure them from the Workspaces
* tab instead of waiting for the one-shot prompt.
*/
export async function listReportedWorkspaceRoots(): Promise<string[]> {
return invoke('list_reported_workspace_roots');
}
/**
* Forget every reported workspace root that has no binding ("unmapped").
* Clears them from the Workspaces tab in one action; the gateway then offers
* the "map this folder?" prompt again the next time those apps report a
* folder (or reconnect). Mapped folders are left untouched. Resolves with
* the number of roots cleared.
*/
export async function clearUnmappedReportedRoots(): Promise<number> {
return invoke('clear_unmapped_reported_roots');
}
/**
* Live path validation for the manual-add form. Runs the SAME rules the
* create/update commands apply so "validates in UI → saves OK" is a
* guarantee, not a hope.
*
* Resolves with the server's normalized form (e.g. `d:\foo` from raw
* `D:\foo\`). Rejects with a descriptive message on invalid input; empty
* input rejects with an empty string so the UI can distinguish
* "don't nag yet" from "here's a real error".
*/
export async function validateWorkspaceRoot(path: string): Promise<string> {
return invoke('validate_workspace_root', { path });
}
/** List bindings whose target Space is the given one. */
export async function listWorkspaceBindingsForSpace(
spaceId: string
): Promise<WorkspaceBinding[]> {
return invoke('list_workspace_bindings_for_space', { spaceId });
}
/**
* Create a new binding. `workspace_root` is normalized server-side so
* callers can pass raw OS paths, `file://` URIs, or MCP-reported roots.
*/
export async function createWorkspaceBinding(
input: WorkspaceBindingInput
): Promise<WorkspaceBinding> {
return invoke('create_workspace_binding', { input });
}
/** Update any axis of an existing binding. */
export async function updateWorkspaceBinding(
id: string,
input: WorkspaceBindingInput
): Promise<WorkspaceBinding> {
return invoke('update_workspace_binding', { id, input });
}
/** Delete a binding by id. */
export async function deleteWorkspaceBinding(id: string): Promise<void> {
return invoke('delete_workspace_binding', { id });
}
/** Convenience: build a `WorkspaceBindingInput` from a binding-shaped object. */
export function toInput(b: WorkspaceBinding): WorkspaceBindingInput {
return {
workspace_root: b.workspace_root,
space_id: b.space_id,
feature_set_ids: b.feature_set_ids,
};
}
/**
* Per-feature view returned from `get_workspace_effective_features`.
*
* `available` is `true` exactly when the underlying server is currently
* connected. A `false` value with `server_status = "disconnected"` (or
* `auth_required` / `error`) is the user's "configured but unavailable"
* case — the FS still includes this feature, but its server isn't usable
* right now.
*/
export interface EffectiveFeature {
id: string;
feature_name: string;
display_name: string | null;
description: string | null;
server_id: string;
server_alias: string | null;
/**
* snake_case mirror of the gateway's connection status, plus `unknown`
* when the gateway isn't running.
*/
server_status:
| 'connected'
| 'connecting'
| 'disconnected'
| 'refreshing'
| 'auth_required'
| 'authenticating'
| 'error'
| 'unknown';
available: boolean;
}
/**
* Per-server total feature counts in the resolved Space, regardless of FS
* filter. The right-hand side of the "{mapped} / {total}" badges.
*/
export interface ServerFeatureTotals {
tools: number;
prompts: number;
resources: number;
}
/** One FeatureSet contributing to the resolved view. */
export interface EffectiveFeatureSetSummary {
id: string;
name: string;
feature_set_type: 'starter' | 'default' | 'custom';
}
export interface WorkspaceEffectiveFeatures {
workspace_root: string;
/** `binding` when a saved WorkspaceBinding matched; `unbound` when no binding matched — the `feature_sets` field previews the default Space's Default FS but a live session here would be denied. */
source: 'binding' | 'unbound';
binding_id: string | null;
space_id: string;
space_name: string;
/** All FeatureSets contributing to the resolved view, in operator-chosen order. ≥ 1. */
feature_sets: EffectiveFeatureSetSummary[];
tools: EffectiveFeature[];
prompts: EffectiveFeature[];
resources: EffectiveFeature[];
/** `server_id -> totals` for every server installed in the resolved Space. */
server_totals: Record<string, ServerFeatureTotals>;
}
/**
* Resolve the FeatureSet that applies for a given workspace root and return
* its full configured tool/prompt/resource list with per-feature
* availability — same view the gateway resolver builds for live sessions.
*/
export async function getWorkspaceEffectiveFeatures(
workspaceRoot: string
): Promise<WorkspaceEffectiveFeatures> {
return invoke('get_workspace_effective_features', { workspaceRoot });
}