@botmanor/fe-sdk 0.0.0-stage → 2026.1203.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 +36 -2
- package/dist/index.d.ts +325 -0
- package/dist/index.js +1352 -0
- package/package.json +88 -4
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @botmanor/fe-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Embed BotManor **Stewards** (🗺️ in development — BOFF-15352).
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { StewardsSdkProvider, StewardConsole, useStewardsEvent } from '@botmanor/fe-sdk';
|
|
7
|
+
|
|
8
|
+
<StewardsSdkProvider
|
|
9
|
+
gatewayUrl={gatewayUrl}
|
|
10
|
+
workspaceId={workspaceId}
|
|
11
|
+
getAccessToken={() => auth.currentToken()}
|
|
12
|
+
onTokenExpired={() => auth.refresh()}
|
|
13
|
+
onEvent={(e) => analytics.track(e.type)}
|
|
14
|
+
theme={{ accent: 'var(--my-brand)' }}
|
|
15
|
+
>
|
|
16
|
+
<StewardConsole stewardId={stewardId} />
|
|
17
|
+
</StewardsSdkProvider>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Theme variables are scoped to the SDK's wrapper; the SDK never styles your page.
|
|
21
|
+
See [AGENTS.md](AGENTS.md).
|
|
22
|
+
|
|
23
|
+
## Data and transport
|
|
24
|
+
|
|
25
|
+
Components read and write Stewards through the host's GraphQL gateway
|
|
26
|
+
(`gatewayUrl`, an https URL with no credentials or query string; http only for
|
|
27
|
+
loopback). The access token from `getAccessToken` (the embed session token when
|
|
28
|
+
embedded on a third-party page) goes in the `Authorization` header only; no
|
|
29
|
+
cookies, no referrer. A 401 or `UNAUTHENTICATED` raises `onTokenExpired` and the
|
|
30
|
+
`auth.expired` event. Operations match `@burdenoff/microfe-stewards` and use the
|
|
31
|
+
`Botmanor*` schema; the SDK does not depend on that package because it pulls in
|
|
32
|
+
Apollo and the fe-libs shell.
|
|
33
|
+
|
|
34
|
+
- `StewardConsole`: steward list, or one steward with run prompt and recent runs.
|
|
35
|
+
- `StewardBuilder`: create from an agent and charter, or edit a charter (`stewardId`).
|
|
36
|
+
- `StewardRunView`: steps, approvals, trust level and budget; polls while active.
|
|
37
|
+
- `ApprovalInbox`: pending steward approvals with the approval scope choice.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @botmanor/fe-sdk — embed BotManor Stewards in Burdenoff shells and
|
|
4
|
+
* third-party pages (plan 09 §5.8).
|
|
5
|
+
*
|
|
6
|
+
* Rules the SDK keeps (lessons from the FluidGrids SDK):
|
|
7
|
+
* - scoped theming: variables live on the SDK's own wrapper, never `<html>`;
|
|
8
|
+
* - no module singleton: every provider owns its config and event bus;
|
|
9
|
+
* - the host owns auth: tokens come from `getAccessToken`, expiry goes to
|
|
10
|
+
* `onTokenExpired`, and every event is passed through `onEvent`.
|
|
11
|
+
*/
|
|
12
|
+
import { CSSProperties, ReactNode } from "react";
|
|
13
|
+
/** Failure from the gateway: a transport status or a GraphQL error code. */
|
|
14
|
+
export declare class StewardsRequestError extends Error {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
constructor(message: string, code: string, status?: number);
|
|
18
|
+
}
|
|
19
|
+
interface StewardsClient {
|
|
20
|
+
request<T>(document: string, variables?: Record<string, unknown>, signal?: AbortSignal): Promise<T>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Stewards SDK events. Names follow the devportal outbound-webhook subjects
|
|
24
|
+
* (`graph.botmanor.StewardRun.{started,waiting,completed,failed}`, plan §5.8)
|
|
25
|
+
* so host code handles the same vocabulary in-page and server-side.
|
|
26
|
+
*/
|
|
27
|
+
interface StewardsEventMap {
|
|
28
|
+
"run.started": {
|
|
29
|
+
runId: string;
|
|
30
|
+
stewardId: string;
|
|
31
|
+
};
|
|
32
|
+
"run.waiting": {
|
|
33
|
+
runId: string;
|
|
34
|
+
stewardId: string;
|
|
35
|
+
reason: "APPROVAL" | "TAKEOVER" | "BUDGET";
|
|
36
|
+
};
|
|
37
|
+
"run.completed": {
|
|
38
|
+
runId: string;
|
|
39
|
+
stewardId: string;
|
|
40
|
+
};
|
|
41
|
+
"run.failed": {
|
|
42
|
+
runId: string;
|
|
43
|
+
stewardId: string;
|
|
44
|
+
message: string;
|
|
45
|
+
};
|
|
46
|
+
"approval.requested": {
|
|
47
|
+
approvalId: string;
|
|
48
|
+
runId: string;
|
|
49
|
+
};
|
|
50
|
+
"approval.decided": {
|
|
51
|
+
approvalId: string;
|
|
52
|
+
decision: "APPROVE" | "DENY";
|
|
53
|
+
};
|
|
54
|
+
/** The provider's token getter failed or the gateway answered 401. */
|
|
55
|
+
"auth.expired": {
|
|
56
|
+
reason: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
type StewardsEventType = keyof StewardsEventMap;
|
|
60
|
+
type StewardsEvent = { [K in StewardsEventType]: {
|
|
61
|
+
type: K;
|
|
62
|
+
payload: StewardsEventMap[K];
|
|
63
|
+
}; }[StewardsEventType];
|
|
64
|
+
interface StewardsEventBus {
|
|
65
|
+
emit<K extends StewardsEventType>(type: K, payload: StewardsEventMap[K]): void;
|
|
66
|
+
on<K extends StewardsEventType>(type: K, handler: (payload: StewardsEventMap[K]) => void): () => void;
|
|
67
|
+
/** Every event, in emit order. Used for the provider's `onEvent` passthrough. */
|
|
68
|
+
onAny(handler: (event: StewardsEvent) => void): () => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A new, independent bus. The SDK never keeps one at module level: each
|
|
72
|
+
* provider instance owns its own, so two embeds on one page never cross-talk
|
|
73
|
+
* (the FluidGrids SDK singleton lesson, plan §5.8).
|
|
74
|
+
*/
|
|
75
|
+
export declare function createStewardsEventBus(): StewardsEventBus;
|
|
76
|
+
/**
|
|
77
|
+
* Theme for an embedded Stewards surface. Every key becomes a CSS custom
|
|
78
|
+
* property on the SDK's own wrapper element (`--bm-sdk-<key>`), never on
|
|
79
|
+
* `<html>` or `:root`, so an embed cannot restyle its host page.
|
|
80
|
+
*/
|
|
81
|
+
interface StewardsTheme {
|
|
82
|
+
surface: string;
|
|
83
|
+
surfaceMuted: string;
|
|
84
|
+
text: string;
|
|
85
|
+
textMuted: string;
|
|
86
|
+
border: string;
|
|
87
|
+
accent: string;
|
|
88
|
+
accentText: string;
|
|
89
|
+
danger: string;
|
|
90
|
+
radius: string;
|
|
91
|
+
fontFamily: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Defaults reference the fe-libs semantic tokens, so inside a Burdenoff shell
|
|
95
|
+
* the SDK matches the app's light/dark theme with no configuration. A
|
|
96
|
+
* third-party page that does not load the fe-libs token stylesheet passes its
|
|
97
|
+
* own `theme`.
|
|
98
|
+
*/
|
|
99
|
+
export declare const DEFAULT_STEWARDS_THEME: StewardsTheme;
|
|
100
|
+
/** The wrapper's inline style: one custom property per theme key. */
|
|
101
|
+
export declare function themeToStyle(theme?: Partial<StewardsTheme>): CSSProperties;
|
|
102
|
+
interface StewardsSdkConfig {
|
|
103
|
+
/** Public workspace gateway GraphQL endpoint, e.g. `https://graphqlworkspaces.burdenoff.com/workspaces/graphql`. */
|
|
104
|
+
gatewayUrl: string;
|
|
105
|
+
workspaceId: string;
|
|
106
|
+
/**
|
|
107
|
+
* Returns a current access token. Called before each request, never cached
|
|
108
|
+
* by the SDK beyond one request, so the host stays the owner of refresh.
|
|
109
|
+
*/
|
|
110
|
+
getAccessToken: () => string | Promise<string>;
|
|
111
|
+
/** Called when the token getter throws or the gateway answers 401. */
|
|
112
|
+
onTokenExpired?: (reason: string) => void;
|
|
113
|
+
/** Every SDK event, for hosts that prefer one callback to `useStewardsEvent`. */
|
|
114
|
+
onEvent?: (event: StewardsEvent) => void;
|
|
115
|
+
theme?: Partial<StewardsTheme>;
|
|
116
|
+
}
|
|
117
|
+
interface StewardsSdkContextValue {
|
|
118
|
+
config: StewardsSdkConfig;
|
|
119
|
+
events: StewardsEventBus;
|
|
120
|
+
/** Resolves the token, reporting failures through `onTokenExpired` and `auth.expired`. */
|
|
121
|
+
resolveToken: () => Promise<string>;
|
|
122
|
+
/** Reports an expired session through `onTokenExpired` and `auth.expired`. */
|
|
123
|
+
reportAuthExpired: (reason: string) => void;
|
|
124
|
+
/** GraphQL transport bound to this provider's gateway, workspace and token. */
|
|
125
|
+
client: StewardsClient;
|
|
126
|
+
}
|
|
127
|
+
interface StewardsSdkProviderProps extends StewardsSdkConfig {
|
|
128
|
+
children?: ReactNode;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Root of every embedded Stewards surface. Each instance owns its own event
|
|
132
|
+
* bus and config: the SDK holds no module-level state, so several providers
|
|
133
|
+
* (two workspaces, or two embeds) can share a page.
|
|
134
|
+
*/
|
|
135
|
+
export declare function StewardsSdkProvider({ children, ...config }: StewardsSdkProviderProps): import("react").JSX.Element;
|
|
136
|
+
export declare function useStewardsSdk(): StewardsSdkContextValue;
|
|
137
|
+
/** Subscribe to one SDK event for the lifetime of the calling component. */
|
|
138
|
+
export declare function useStewardsEvent<K extends StewardsEventType>(type: K, handler: (payload: StewardsEventMap[K]) => void): void;
|
|
139
|
+
interface StewardConsoleProps {
|
|
140
|
+
/**
|
|
141
|
+
* The steward to show. Omitted lists the workspace's stewards and lets the
|
|
142
|
+
* viewer open one (the host can follow along through `onSelectSteward`).
|
|
143
|
+
*/
|
|
144
|
+
stewardId?: string;
|
|
145
|
+
onSelectSteward?: (stewardId: string) => void;
|
|
146
|
+
}
|
|
147
|
+
/** List stewards, or open one: its charter summary, start a run, recent runs. */
|
|
148
|
+
export declare function StewardConsole({ stewardId, onSelectSteward }: StewardConsoleProps): import("react").JSX.Element;
|
|
149
|
+
interface StewardBuilderProps {
|
|
150
|
+
/** Start from an existing agent; omitted shows the agent picker. */
|
|
151
|
+
agentId?: string;
|
|
152
|
+
/** Edit the charter of this steward instead of creating one. */
|
|
153
|
+
stewardId?: string;
|
|
154
|
+
/** Called with the new steward's id once it is created. */
|
|
155
|
+
onCreated?: (stewardId: string) => void;
|
|
156
|
+
/** Called with the steward's id once its charter is saved. */
|
|
157
|
+
onSaved?: (stewardId: string) => void;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a steward from an agent and a charter, or edit an existing charter:
|
|
161
|
+
* the charter text, the autonomy level and a daily credit budget. Duties and
|
|
162
|
+
* playbooks live in the full Stewards app.
|
|
163
|
+
*/
|
|
164
|
+
export declare function StewardBuilder(props: StewardBuilderProps): import("react").JSX.Element;
|
|
165
|
+
interface StewardRunViewProps {
|
|
166
|
+
/** The run to show. */
|
|
167
|
+
runId: string;
|
|
168
|
+
/** Poll interval while the run is active. Defaults to 3000 ms. */
|
|
169
|
+
pollIntervalMs?: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* One run: its steps, approvals, trust level and budget. Polls the gateway
|
|
173
|
+
* while the run is active (the embed session is not a subscription actor) and
|
|
174
|
+
* emits `run.waiting`, `run.completed` and `run.failed` as the status changes.
|
|
175
|
+
*/
|
|
176
|
+
export declare function StewardRunView({ runId, pollIntervalMs }: StewardRunViewProps): import("react").JSX.Element;
|
|
177
|
+
interface ApprovalInboxProps {
|
|
178
|
+
/** Limit to one steward; omitted shows every steward approval the viewer can decide. */
|
|
179
|
+
stewardId?: string;
|
|
180
|
+
/** Poll interval. Defaults to 15000 ms. */
|
|
181
|
+
pollIntervalMs?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Pending steward approvals the viewer can decide, with the approval scope
|
|
185
|
+
* choice. Extends the platform tool-approval queue (`source: STEWARD`,
|
|
186
|
+
* `mine: true`) rather than a parallel one.
|
|
187
|
+
*/
|
|
188
|
+
export declare function ApprovalInbox({ stewardId, pollIntervalMs }: ApprovalInboxProps): import("react").JSX.Element;
|
|
189
|
+
/**
|
|
190
|
+
* The slice of the workspace gateway schema the SDK reads and writes. Names
|
|
191
|
+
* follow the `Botmanor*` types of the Hive production supergraph (the same
|
|
192
|
+
* operations `@burdenoff/microfe-stewards` ships), never the deprecated
|
|
193
|
+
* `Botlit*` twins.
|
|
194
|
+
*/
|
|
195
|
+
type StewardStatus = "ACTIVE" | "ARCHIVED" | "DRAFT" | "PAUSED";
|
|
196
|
+
type StewardAutonomy = "ASK" | "GUIDED" | "OBSERVE" | "TRUSTED";
|
|
197
|
+
type StewardDeskKind = "BROWSER" | "CLOUD" | "NONE" | "OWN_MACHINE";
|
|
198
|
+
type StewardRunStatus = "CANCELLED" | "COMPLETED" | "FAILED" | "PAUSED_BUDGET" | "PROPOSED" | "QUEUED" | "RUNNING" | "STOPPED" | "WAITING_APPROVAL" | "WAITING_TAKEOVER";
|
|
199
|
+
type StewardApprovalScope = "DUTY" | "ONCE" | "RUN" | "STANDING" | "TIME_LIMITED";
|
|
200
|
+
type StewardStepVerdict = "ALLOWED" | "APPROVED" | "ASKED" | "BLOCKED_DRY_RUN" | "DENIED" | "FAILED" | "SKIPPED";
|
|
201
|
+
interface StewardBudget {
|
|
202
|
+
credits: number | null;
|
|
203
|
+
deskMinutes: number | null;
|
|
204
|
+
steps: number | null;
|
|
205
|
+
wallSeconds: number | null;
|
|
206
|
+
connectorSpendMinor: number | null;
|
|
207
|
+
}
|
|
208
|
+
interface StewardRunBrief {
|
|
209
|
+
id: string;
|
|
210
|
+
status: StewardRunStatus;
|
|
211
|
+
startedAt: string | null;
|
|
212
|
+
}
|
|
213
|
+
interface StewardListItem {
|
|
214
|
+
id: string;
|
|
215
|
+
agentId: string;
|
|
216
|
+
agent: {
|
|
217
|
+
id: string;
|
|
218
|
+
name: string;
|
|
219
|
+
} | null;
|
|
220
|
+
status: StewardStatus;
|
|
221
|
+
defaultDeskKind: StewardDeskKind;
|
|
222
|
+
pendingApprovalCount: number;
|
|
223
|
+
charter: {
|
|
224
|
+
autonomyLevel: StewardAutonomy;
|
|
225
|
+
budgetPerDay: {
|
|
226
|
+
credits: number | null;
|
|
227
|
+
} | null;
|
|
228
|
+
} | null;
|
|
229
|
+
usageToday: {
|
|
230
|
+
credits: number | null;
|
|
231
|
+
} | null;
|
|
232
|
+
lastRun: StewardRunBrief | null;
|
|
233
|
+
}
|
|
234
|
+
interface StewardDetail {
|
|
235
|
+
id: string;
|
|
236
|
+
agentId: string;
|
|
237
|
+
agent: {
|
|
238
|
+
id: string;
|
|
239
|
+
name: string;
|
|
240
|
+
capabilities: string[];
|
|
241
|
+
} | null;
|
|
242
|
+
ownerActorId: string;
|
|
243
|
+
status: StewardStatus;
|
|
244
|
+
defaultDeskKind: StewardDeskKind;
|
|
245
|
+
pendingApprovalCount: number;
|
|
246
|
+
charter: {
|
|
247
|
+
autonomyLevel: StewardAutonomy;
|
|
248
|
+
charterText: string;
|
|
249
|
+
charterVersion: number;
|
|
250
|
+
allowedToolKeys: string[];
|
|
251
|
+
allowedConnectionIds: string[];
|
|
252
|
+
budgetPerRun: StewardBudget | null;
|
|
253
|
+
budgetPerDay: StewardBudget | null;
|
|
254
|
+
budgetTotal: StewardBudget | null;
|
|
255
|
+
timezone: string | null;
|
|
256
|
+
dryRunDefault: boolean;
|
|
257
|
+
} | null;
|
|
258
|
+
usageToday: StewardBudget | null;
|
|
259
|
+
lastRun: StewardRunBrief | null;
|
|
260
|
+
createdAt: string;
|
|
261
|
+
updatedAt: string;
|
|
262
|
+
}
|
|
263
|
+
interface StewardRunSummary {
|
|
264
|
+
id: string;
|
|
265
|
+
stewardId: string;
|
|
266
|
+
trigger: string;
|
|
267
|
+
status: StewardRunStatus;
|
|
268
|
+
trustLevel: string;
|
|
269
|
+
initialTrustLevel: string;
|
|
270
|
+
dryRun: boolean;
|
|
271
|
+
stepCount: number;
|
|
272
|
+
stopReason: string | null;
|
|
273
|
+
budgetUsed: StewardBudget | null;
|
|
274
|
+
startedAt: string | null;
|
|
275
|
+
finishedAt: string | null;
|
|
276
|
+
createdAt: string;
|
|
277
|
+
}
|
|
278
|
+
interface StewardStep {
|
|
279
|
+
id: string;
|
|
280
|
+
seq: number;
|
|
281
|
+
kind: string;
|
|
282
|
+
toolKey: string | null;
|
|
283
|
+
targetSummary: string | null;
|
|
284
|
+
resultSummary: string | null;
|
|
285
|
+
classification: string | null;
|
|
286
|
+
verdict: StewardStepVerdict;
|
|
287
|
+
verdictReasons: string[];
|
|
288
|
+
approvalRequestId: string | null;
|
|
289
|
+
creditsUsed: number | null;
|
|
290
|
+
startedAt: string | null;
|
|
291
|
+
finishedAt: string | null;
|
|
292
|
+
}
|
|
293
|
+
interface StewardRunApproval {
|
|
294
|
+
id: string;
|
|
295
|
+
toolName: string;
|
|
296
|
+
riskLevel: string;
|
|
297
|
+
status: ApprovalStatus;
|
|
298
|
+
requestedScope: StewardApprovalScope | null;
|
|
299
|
+
grantedScope: StewardApprovalScope | null;
|
|
300
|
+
expiresAt: string;
|
|
301
|
+
decidedAt: string | null;
|
|
302
|
+
createdAt: string;
|
|
303
|
+
}
|
|
304
|
+
interface StewardRunDetail extends StewardRunSummary {
|
|
305
|
+
steps: StewardStep[];
|
|
306
|
+
approvals: StewardRunApproval[];
|
|
307
|
+
}
|
|
308
|
+
type ApprovalStatus = "APPROVED" | "CANCELLED" | "DENIED" | "EXPIRED" | "PENDING";
|
|
309
|
+
interface StewardApprovalRequest {
|
|
310
|
+
id: string;
|
|
311
|
+
agentName: string | null;
|
|
312
|
+
stewardId: string | null;
|
|
313
|
+
stewardRunId: string | null;
|
|
314
|
+
toolName: string;
|
|
315
|
+
riskLevel: string;
|
|
316
|
+
destination: string | null;
|
|
317
|
+
purpose: string | null;
|
|
318
|
+
reasons: string[];
|
|
319
|
+
fixedDefault: string | null;
|
|
320
|
+
requestedScope: StewardApprovalScope | null;
|
|
321
|
+
status: ApprovalStatus;
|
|
322
|
+
expiresAt: string;
|
|
323
|
+
createdAt: string;
|
|
324
|
+
}
|
|
325
|
+
export type { ApprovalInboxProps, StewardApprovalRequest, StewardBuilderProps, StewardConsoleProps, StewardDetail, StewardListItem, StewardRunDetail, StewardRunSummary, StewardRunViewProps, StewardsClient, StewardsEvent, StewardsEventBus, StewardsEventMap, StewardsEventType, StewardsSdkConfig, StewardsSdkContextValue, StewardsTheme };
|