@stigmer/react 3.3.0 → 3.4.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.
- package/billing/index.d.ts +0 -18
- package/billing/index.d.ts.map +1 -1
- package/billing/index.js +4 -9
- package/billing/index.js.map +1 -1
- package/cursor-accounts/CursorAccountEditor.d.ts +7 -1
- package/cursor-accounts/CursorAccountEditor.d.ts.map +1 -1
- package/cursor-accounts/CursorAccountEditor.js +21 -5
- package/cursor-accounts/CursorAccountEditor.js.map +1 -1
- package/cursor-accounts/CursorAccountsConsole.d.ts +9 -5
- package/cursor-accounts/CursorAccountsConsole.d.ts.map +1 -1
- package/cursor-accounts/CursorAccountsConsole.js +34 -140
- package/cursor-accounts/CursorAccountsConsole.js.map +1 -1
- package/cursor-accounts/MemberCoverageTable.d.ts +29 -0
- package/cursor-accounts/MemberCoverageTable.d.ts.map +1 -0
- package/cursor-accounts/MemberCoverageTable.js +150 -0
- package/cursor-accounts/MemberCoverageTable.js.map +1 -0
- package/cursor-accounts/MemberKeysPanel.d.ts +25 -0
- package/cursor-accounts/MemberKeysPanel.d.ts.map +1 -0
- package/cursor-accounts/MemberKeysPanel.js +115 -0
- package/cursor-accounts/MemberKeysPanel.js.map +1 -0
- package/cursor-accounts/badges.d.ts +9 -0
- package/cursor-accounts/badges.d.ts.map +1 -0
- package/cursor-accounts/badges.js +10 -0
- package/cursor-accounts/badges.js.map +1 -0
- package/cursor-accounts/cursor-account-coverage.d.ts +41 -0
- package/cursor-accounts/cursor-account-coverage.d.ts.map +1 -0
- package/cursor-accounts/cursor-account-coverage.js +26 -0
- package/cursor-accounts/cursor-account-coverage.js.map +1 -0
- package/cursor-accounts/cursor-account-format.d.ts +13 -0
- package/cursor-accounts/cursor-account-format.d.ts.map +1 -1
- package/cursor-accounts/cursor-account-format.js +16 -1
- package/cursor-accounts/cursor-account-format.js.map +1 -1
- package/datastore/CollectionRecordsBrowser.js +18 -4
- package/datastore/CollectionRecordsBrowser.js.map +1 -1
- package/datastore/RecordFilterBuilder.d.ts +8 -1
- package/datastore/RecordFilterBuilder.d.ts.map +1 -1
- package/datastore/RecordFilterBuilder.js +2 -2
- package/datastore/RecordFilterBuilder.js.map +1 -1
- package/datastore/recordFilter.d.ts +9 -1
- package/datastore/recordFilter.d.ts.map +1 -1
- package/datastore/recordFilter.js +12 -1
- package/datastore/recordFilter.js.map +1 -1
- package/execution/ExecutionProgress.d.ts.map +1 -1
- package/execution/ExecutionProgress.js +13 -4
- package/execution/ExecutionProgress.js.map +1 -1
- package/execution/MessageThread.d.ts.map +1 -1
- package/execution/MessageThread.js +10 -2
- package/execution/MessageThread.js.map +1 -1
- package/execution/useCreateAgentExecution.d.ts +31 -1
- package/execution/useCreateAgentExecution.d.ts.map +1 -1
- package/execution/useCreateAgentExecution.js +2 -0
- package/execution/useCreateAgentExecution.js.map +1 -1
- package/index.d.ts +4 -2
- package/index.d.ts.map +1 -1
- package/index.js +6 -2
- package/index.js.map +1 -1
- package/internal/form-primitives.d.ts +10 -0
- package/internal/form-primitives.d.ts.map +1 -0
- package/{billing → internal}/form-primitives.js +5 -9
- package/internal/form-primitives.js.map +1 -0
- package/package.json +4 -4
- package/pricing-governance/BaselineEditor.d.ts.map +1 -0
- package/{billing → pricing-governance}/BaselineEditor.js +19 -2
- package/pricing-governance/BaselineEditor.js.map +1 -0
- package/pricing-governance/ModelCatalogPanel.d.ts.map +1 -0
- package/pricing-governance/ModelCatalogPanel.js.map +1 -0
- package/pricing-governance/ModelGovernanceDetail.d.ts.map +1 -0
- package/pricing-governance/ModelGovernanceDetail.js.map +1 -0
- package/pricing-governance/OperatorAccessNotice.d.ts.map +1 -0
- package/pricing-governance/OperatorAccessNotice.js.map +1 -0
- package/pricing-governance/PricingGovernanceConsole.d.ts.map +1 -0
- package/{billing → pricing-governance}/PricingGovernanceConsole.js +1 -1
- package/pricing-governance/PricingGovernanceConsole.js.map +1 -0
- package/pricing-governance/PricingGovernancePanel.d.ts.map +1 -0
- package/pricing-governance/PricingGovernancePanel.js.map +1 -0
- package/pricing-governance/RetireConfirm.d.ts.map +1 -0
- package/{billing → pricing-governance}/RetireConfirm.js +1 -1
- package/pricing-governance/RetireConfirm.js.map +1 -0
- package/pricing-governance/governance-primitives.d.ts.map +1 -0
- package/pricing-governance/governance-primitives.js.map +1 -0
- package/pricing-governance/index.d.ts +19 -0
- package/pricing-governance/index.d.ts.map +1 -0
- package/pricing-governance/index.js +20 -0
- package/pricing-governance/index.js.map +1 -0
- package/pricing-governance/pricing-format.d.ts.map +1 -0
- package/pricing-governance/pricing-format.js.map +1 -0
- package/pricing-governance/useDecidePricingOverride.d.ts.map +1 -0
- package/pricing-governance/useDecidePricingOverride.js.map +1 -0
- package/pricing-governance/useModelGovernanceView.d.ts.map +1 -0
- package/pricing-governance/useModelGovernanceView.js.map +1 -0
- package/pricing-governance/useModelPricingBaselines.d.ts.map +1 -0
- package/pricing-governance/useModelPricingBaselines.js.map +1 -0
- package/pricing-governance/usePricingGovernance.d.ts.map +1 -0
- package/pricing-governance/usePricingGovernance.js.map +1 -0
- package/pricing-governance/useRetireModelPricingBaseline.d.ts.map +1 -0
- package/pricing-governance/useRetireModelPricingBaseline.js.map +1 -0
- package/pricing-governance/useUpsertModelPricingBaseline.d.ts.map +1 -0
- package/pricing-governance/useUpsertModelPricingBaseline.js.map +1 -0
- package/session/useCreateSession.d.ts +28 -0
- package/session/useCreateSession.d.ts.map +1 -1
- package/session/useCreateSession.js +2 -1
- package/session/useCreateSession.js.map +1 -1
- package/session/useNewSessionFlow.d.ts +30 -0
- package/session/useNewSessionFlow.d.ts.map +1 -1
- package/session/useNewSessionFlow.js +7 -1
- package/session/useNewSessionFlow.js.map +1 -1
- package/session/useUpdateSession.d.ts +29 -10
- package/session/useUpdateSession.d.ts.map +1 -1
- package/session/useUpdateSession.js +29 -10
- package/session/useUpdateSession.js.map +1 -1
- package/src/billing/index.ts +5 -37
- package/src/cursor-accounts/CursorAccountEditor.tsx +61 -13
- package/src/cursor-accounts/CursorAccountsConsole.tsx +44 -400
- package/src/cursor-accounts/MemberCoverageTable.tsx +439 -0
- package/src/cursor-accounts/MemberKeysPanel.tsx +278 -0
- package/src/cursor-accounts/__tests__/CursorAccountsConsole.test.tsx +306 -10
- package/src/cursor-accounts/__tests__/cursor-account-coverage.test.ts +73 -0
- package/src/cursor-accounts/badges.tsx +26 -0
- package/src/cursor-accounts/cursor-account-coverage.ts +71 -0
- package/src/cursor-accounts/cursor-account-format.ts +17 -1
- package/src/datastore/CollectionRecordsBrowser.tsx +29 -3
- package/src/datastore/RecordFilterBuilder.tsx +12 -1
- package/src/datastore/__tests__/CollectionRecordsBrowser.test.tsx +38 -0
- package/src/datastore/__tests__/RecordFilterBuilder.test.tsx +14 -0
- package/src/datastore/__tests__/recordFilter.test.ts +13 -0
- package/src/datastore/recordFilter.ts +15 -1
- package/src/execution/ExecutionProgress.tsx +14 -4
- package/src/execution/MessageThread.tsx +10 -2
- package/src/execution/__tests__/ExecutionProgress.test.tsx +67 -0
- package/src/execution/__tests__/MessageThread.test.tsx +44 -0
- package/src/execution/__tests__/useCreateAgentExecution.test.tsx +86 -0
- package/src/execution/useCreateAgentExecution.ts +41 -6
- package/src/index.ts +32 -24
- package/src/{billing → internal}/form-primitives.tsx +4 -32
- package/src/{billing → pricing-governance}/BaselineEditor.tsx +36 -3
- package/src/{billing → pricing-governance}/PricingGovernanceConsole.tsx +1 -1
- package/src/{billing → pricing-governance}/RetireConfirm.tsx +1 -1
- package/src/pricing-governance/index.ts +50 -0
- package/src/session/__tests__/useCreateSession.test.tsx +94 -0
- package/src/session/__tests__/useNewSessionFlow.test.tsx +33 -0
- package/src/session/useCreateSession.ts +30 -0
- package/src/session/useNewSessionFlow.ts +45 -1
- package/src/session/useUpdateSession.ts +29 -10
- package/styles.css +1 -1
- package/billing/BaselineEditor.d.ts.map +0 -1
- package/billing/BaselineEditor.js.map +0 -1
- package/billing/ModelCatalogPanel.d.ts.map +0 -1
- package/billing/ModelCatalogPanel.js.map +0 -1
- package/billing/ModelGovernanceDetail.d.ts.map +0 -1
- package/billing/ModelGovernanceDetail.js.map +0 -1
- package/billing/OperatorAccessNotice.d.ts.map +0 -1
- package/billing/OperatorAccessNotice.js.map +0 -1
- package/billing/PricingGovernanceConsole.d.ts.map +0 -1
- package/billing/PricingGovernanceConsole.js.map +0 -1
- package/billing/PricingGovernancePanel.d.ts.map +0 -1
- package/billing/PricingGovernancePanel.js.map +0 -1
- package/billing/RetireConfirm.d.ts.map +0 -1
- package/billing/RetireConfirm.js.map +0 -1
- package/billing/form-primitives.d.ts +0 -18
- package/billing/form-primitives.d.ts.map +0 -1
- package/billing/form-primitives.js.map +0 -1
- package/billing/governance-primitives.d.ts.map +0 -1
- package/billing/governance-primitives.js.map +0 -1
- package/billing/pricing-format.d.ts.map +0 -1
- package/billing/pricing-format.js.map +0 -1
- package/billing/useDecidePricingOverride.d.ts.map +0 -1
- package/billing/useDecidePricingOverride.js.map +0 -1
- package/billing/useModelGovernanceView.d.ts.map +0 -1
- package/billing/useModelGovernanceView.js.map +0 -1
- package/billing/useModelPricingBaselines.d.ts.map +0 -1
- package/billing/useModelPricingBaselines.js.map +0 -1
- package/billing/usePricingGovernance.d.ts.map +0 -1
- package/billing/usePricingGovernance.js.map +0 -1
- package/billing/useRetireModelPricingBaseline.d.ts.map +0 -1
- package/billing/useRetireModelPricingBaseline.js.map +0 -1
- package/billing/useUpsertModelPricingBaseline.d.ts.map +0 -1
- package/billing/useUpsertModelPricingBaseline.js.map +0 -1
- /package/{billing → pricing-governance}/BaselineEditor.d.ts +0 -0
- /package/{billing → pricing-governance}/ModelCatalogPanel.d.ts +0 -0
- /package/{billing → pricing-governance}/ModelCatalogPanel.js +0 -0
- /package/{billing → pricing-governance}/ModelGovernanceDetail.d.ts +0 -0
- /package/{billing → pricing-governance}/ModelGovernanceDetail.js +0 -0
- /package/{billing → pricing-governance}/OperatorAccessNotice.d.ts +0 -0
- /package/{billing → pricing-governance}/OperatorAccessNotice.js +0 -0
- /package/{billing → pricing-governance}/PricingGovernanceConsole.d.ts +0 -0
- /package/{billing → pricing-governance}/PricingGovernancePanel.d.ts +0 -0
- /package/{billing → pricing-governance}/PricingGovernancePanel.js +0 -0
- /package/{billing → pricing-governance}/RetireConfirm.d.ts +0 -0
- /package/{billing → pricing-governance}/governance-primitives.d.ts +0 -0
- /package/{billing → pricing-governance}/governance-primitives.js +0 -0
- /package/{billing → pricing-governance}/pricing-format.d.ts +0 -0
- /package/{billing → pricing-governance}/pricing-format.js +0 -0
- /package/{billing → pricing-governance}/useDecidePricingOverride.d.ts +0 -0
- /package/{billing → pricing-governance}/useDecidePricingOverride.js +0 -0
- /package/{billing → pricing-governance}/useModelGovernanceView.d.ts +0 -0
- /package/{billing → pricing-governance}/useModelGovernanceView.js +0 -0
- /package/{billing → pricing-governance}/useModelPricingBaselines.d.ts +0 -0
- /package/{billing → pricing-governance}/useModelPricingBaselines.js +0 -0
- /package/{billing → pricing-governance}/usePricingGovernance.d.ts +0 -0
- /package/{billing → pricing-governance}/usePricingGovernance.js +0 -0
- /package/{billing → pricing-governance}/useRetireModelPricingBaseline.d.ts +0 -0
- /package/{billing → pricing-governance}/useRetireModelPricingBaseline.js +0 -0
- /package/{billing → pricing-governance}/useUpsertModelPricingBaseline.d.ts +0 -0
- /package/{billing → pricing-governance}/useUpsertModelPricingBaseline.js +0 -0
- /package/src/{billing → pricing-governance}/ModelCatalogPanel.tsx +0 -0
- /package/src/{billing → pricing-governance}/ModelGovernanceDetail.tsx +0 -0
- /package/src/{billing → pricing-governance}/OperatorAccessNotice.tsx +0 -0
- /package/src/{billing → pricing-governance}/PricingGovernancePanel.tsx +0 -0
- /package/src/{billing → pricing-governance}/__tests__/ModelCatalogPanel.test.tsx +0 -0
- /package/src/{billing → pricing-governance}/__tests__/PricingGovernanceConsole.test.tsx +0 -0
- /package/src/{billing → pricing-governance}/__tests__/useModelGovernanceView.test.tsx +0 -0
- /package/src/{billing → pricing-governance}/governance-primitives.tsx +0 -0
- /package/src/{billing → pricing-governance}/pricing-format.ts +0 -0
- /package/src/{billing → pricing-governance}/useDecidePricingOverride.ts +0 -0
- /package/src/{billing → pricing-governance}/useModelGovernanceView.ts +0 -0
- /package/src/{billing → pricing-governance}/useModelPricingBaselines.ts +0 -0
- /package/src/{billing → pricing-governance}/usePricingGovernance.ts +0 -0
- /package/src/{billing → pricing-governance}/useRetireModelPricingBaseline.ts +0 -0
- /package/src/{billing → pricing-governance}/useUpsertModelPricingBaseline.ts +0 -0
|
@@ -4,17 +4,14 @@ import { useCallback, useState } from "react";
|
|
|
4
4
|
import { cn } from "@stigmer/theme";
|
|
5
5
|
import { getUserMessage, isPermissionDenied } from "@stigmer/sdk";
|
|
6
6
|
import type { CursorAccount } from "@stigmer/protos/ai/stigmer/platform/cursoraccount/v1/cursor_account_pb";
|
|
7
|
-
import {
|
|
8
|
-
CursorMemberKeyState,
|
|
9
|
-
type CursorAccountSummary,
|
|
10
|
-
type CursorMemberKeyView,
|
|
11
|
-
} from "@stigmer/protos/ai/stigmer/platform/cursoraccount/v1/io_pb";
|
|
7
|
+
import type { CursorAccountSummary } from "@stigmer/protos/ai/stigmer/platform/cursoraccount/v1/io_pb";
|
|
12
8
|
import { Button } from "../button/index.js";
|
|
13
|
-
import {
|
|
14
|
-
import { toError } from "../internal/toError.js";
|
|
9
|
+
import { StateBadge } from "./badges.js";
|
|
15
10
|
import { CursorAccountEditor } from "./CursorAccountEditor.js";
|
|
16
11
|
import { CursorAccountsAccessNotice } from "./CursorAccountsAccessNotice.js";
|
|
17
|
-
import {
|
|
12
|
+
import { deriveCoverage } from "./cursor-account-coverage.js";
|
|
13
|
+
import { formatSyncTime } from "./cursor-account-format.js";
|
|
14
|
+
import { MemberKeysPanel } from "./MemberKeysPanel.js";
|
|
18
15
|
import { useCursorAccounts } from "./useCursorAccounts.js";
|
|
19
16
|
import { useCursorAccountView } from "./useCursorAccountView.js";
|
|
20
17
|
import { useCursorMemberKeyActions } from "./useCursorMemberKeyActions.js";
|
|
@@ -36,14 +33,18 @@ type Flow =
|
|
|
36
33
|
/**
|
|
37
34
|
* The platform-operator console for managed Cursor accounts: the Cursor
|
|
38
35
|
* teams (admin keys, member execution keys, org assignments) that back
|
|
39
|
-
* the cursor harness, with roster coverage and per-member
|
|
40
|
-
*
|
|
36
|
+
* the cursor harness, with roster coverage and per-member usage from
|
|
37
|
+
* the hourly sync.
|
|
41
38
|
*
|
|
42
39
|
* - **List** — every account with routability at a glance (an account
|
|
43
40
|
* with zero enabled member keys cannot serve executions).
|
|
44
|
-
* - **Detail** — org assignments,
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* - **Detail** — org assignments, "Sync now", and the team-coverage
|
|
42
|
+
* table: every member and stored key classified into three explicit
|
|
43
|
+
* categories (on team with key / on team without key / key held but
|
|
44
|
+
* not on team), each row carrying Cursor's pool-usage percentages
|
|
45
|
+
* (first-party / API) and cycle spend dollars (included / on-demand).
|
|
46
|
+
* Off-team rows offer one-click copy of the account's Cursor team
|
|
47
|
+
* invite link when the operator has configured one.
|
|
47
48
|
*
|
|
48
49
|
* Requires `can_manage_cursor_accounts` on `platform:stigmer` —
|
|
49
50
|
* non-operators see the designed access notice. Key material never
|
|
@@ -194,9 +195,11 @@ function AccountRow({
|
|
|
194
195
|
<span className="block truncate font-medium text-foreground">
|
|
195
196
|
{account.displayName}
|
|
196
197
|
</span>
|
|
197
|
-
{
|
|
198
|
+
{/* Account class is DERIVED from org_ids (DD-008): no org
|
|
199
|
+
assignment means the account belongs to the shared pool. */}
|
|
200
|
+
{account.orgIds.length === 0 && (
|
|
198
201
|
<span className="block text-[11px] text-muted-foreground">
|
|
199
|
-
|
|
202
|
+
shared pool
|
|
200
203
|
</span>
|
|
201
204
|
)}
|
|
202
205
|
</span>
|
|
@@ -322,6 +325,19 @@ function AccountDetail({
|
|
|
322
325
|
|
|
323
326
|
const view = detail.view;
|
|
324
327
|
const account = view.account as CursorAccount;
|
|
328
|
+
// Derived once here: the panel's table consumes the groups, the header
|
|
329
|
+
// line the member counts (active roster = covered + uncovered members —
|
|
330
|
+
// server-computed facts only, no role-string parsing in the client).
|
|
331
|
+
// The covered count is exactly one row per member because the server
|
|
332
|
+
// rejects a second key for an already-bound email, so the removed-seat
|
|
333
|
+
// count is plain list arithmetic: roster entries minus active members.
|
|
334
|
+
// It answers "where did my N members go?" when Cursor marks departed
|
|
335
|
+
// seats role:"removed" in place instead of dropping them.
|
|
336
|
+
const coverage = deriveCoverage(view);
|
|
337
|
+
const activeMemberCount =
|
|
338
|
+
coverage.onTeamWithKey.length + coverage.onTeamWithoutKey.length;
|
|
339
|
+
const removedSeatCount =
|
|
340
|
+
(view.snapshot?.members.length ?? 0) - activeMemberCount;
|
|
325
341
|
|
|
326
342
|
if (editing) {
|
|
327
343
|
return (
|
|
@@ -356,14 +372,21 @@ function AccountDetail({
|
|
|
356
372
|
</h3>
|
|
357
373
|
<p className="text-[11px] text-muted-foreground">
|
|
358
374
|
{account.orgIds.length > 0
|
|
359
|
-
? `
|
|
360
|
-
: account
|
|
361
|
-
? "Platform default — serves all unassigned orgs"
|
|
362
|
-
: "No org assignments"}
|
|
375
|
+
? `Dedicated to ${account.orgIds.length} org(s): ${account.orgIds.join(", ")}`
|
|
376
|
+
: "Shared pool — serves every org with no dedicated account"}
|
|
363
377
|
{" · "}
|
|
364
378
|
{account.enabled ? "enabled" : "disabled"}
|
|
379
|
+
{account.onDemandUsageDisabled
|
|
380
|
+
? " · on-demand usage off (usage guard active)"
|
|
381
|
+
: ""}
|
|
365
382
|
{" · synced "}
|
|
366
383
|
{formatSyncTime(view.snapshot?.syncedAt)}
|
|
384
|
+
{coverage.hasRoster
|
|
385
|
+
? ` · ${activeMemberCount} ${activeMemberCount === 1 ? "member" : "members"}`
|
|
386
|
+
: ""}
|
|
387
|
+
{coverage.hasRoster && removedSeatCount > 0
|
|
388
|
+
? ` · ${removedSeatCount} removed ${removedSeatCount === 1 ? "seat" : "seats"}`
|
|
389
|
+
: ""}
|
|
367
390
|
</p>
|
|
368
391
|
</div>
|
|
369
392
|
<div className="flex gap-2">
|
|
@@ -419,392 +442,13 @@ function AccountDetail({
|
|
|
419
442
|
|
|
420
443
|
<MemberKeysPanel
|
|
421
444
|
accountId={accountId}
|
|
422
|
-
|
|
445
|
+
view={view}
|
|
446
|
+
coverage={coverage}
|
|
423
447
|
actions={keyActions}
|
|
424
448
|
onChanged={refreshAll}
|
|
425
449
|
onImported={syncAfterImport}
|
|
426
450
|
/>
|
|
427
|
-
|
|
428
|
-
{view.membersWithoutKeys.length > 0 && (
|
|
429
|
-
<section className="space-y-1">
|
|
430
|
-
<h4 className="text-xs font-semibold text-foreground">
|
|
431
|
-
Members without execution keys
|
|
432
|
-
</h4>
|
|
433
|
-
<p className="text-[11px] text-muted-foreground">
|
|
434
|
-
Active team members Stigmer holds no key for — sessions can never
|
|
435
|
-
run under their identity or included quota.
|
|
436
|
-
</p>
|
|
437
|
-
<ul role="list" className="m-0 list-none space-y-0.5 p-0 text-xs text-muted-foreground">
|
|
438
|
-
{view.membersWithoutKeys.map((member) => (
|
|
439
|
-
<li key={member.email}>
|
|
440
|
-
{member.name || member.email} · {member.email}
|
|
441
|
-
</li>
|
|
442
|
-
))}
|
|
443
|
-
</ul>
|
|
444
|
-
</section>
|
|
445
|
-
)}
|
|
446
451
|
</div>
|
|
447
452
|
);
|
|
448
453
|
}
|
|
449
454
|
|
|
450
|
-
// ---------------------------------------------------------------------------
|
|
451
|
-
// Member keys panel (internal)
|
|
452
|
-
// ---------------------------------------------------------------------------
|
|
453
|
-
|
|
454
|
-
/** One line's outcome from a bulk key import. */
|
|
455
|
-
interface ImportLineResult {
|
|
456
|
-
/** Masked identification of the key (never the full material). */
|
|
457
|
-
readonly keyPreview: string;
|
|
458
|
-
readonly ok: boolean;
|
|
459
|
-
/** Bound email on success; the server/Cursor error on failure. */
|
|
460
|
-
readonly message: string;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/** Parse bulk-import text: one key per line, trimmed, deduped. */
|
|
464
|
-
function parseImportKeys(text: string): string[] {
|
|
465
|
-
return [...new Set(text.split(/\r?\n/).map((s) => s.trim()).filter((s) => s !== ""))];
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function maskKey(key: string, index: number): string {
|
|
469
|
-
return key.length >= 8 ? `key ${index + 1} (…${key.slice(-4)})` : `key ${index + 1}`;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function MemberKeysPanel({
|
|
473
|
-
accountId,
|
|
474
|
-
keyViews,
|
|
475
|
-
actions,
|
|
476
|
-
onChanged,
|
|
477
|
-
onImported,
|
|
478
|
-
}: {
|
|
479
|
-
readonly accountId: string;
|
|
480
|
-
readonly keyViews: readonly CursorMemberKeyView[];
|
|
481
|
-
readonly actions: ReturnType<typeof useCursorMemberKeyActions>;
|
|
482
|
-
readonly onChanged: () => void;
|
|
483
|
-
/** Called after a bulk import added at least one key (triggers sync). */
|
|
484
|
-
readonly onImported: () => void;
|
|
485
|
-
}) {
|
|
486
|
-
const [newKey, setNewKey] = useState("");
|
|
487
|
-
const [newLabel, setNewLabel] = useState("");
|
|
488
|
-
const [showImport, setShowImport] = useState(false);
|
|
489
|
-
const [importText, setImportText] = useState("");
|
|
490
|
-
const [isImporting, setIsImporting] = useState(false);
|
|
491
|
-
const [importProgress, setImportProgress] = useState<
|
|
492
|
-
{ readonly done: number; readonly total: number } | null
|
|
493
|
-
>(null);
|
|
494
|
-
const [importResults, setImportResults] = useState<readonly ImportLineResult[] | null>(
|
|
495
|
-
null,
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
const submitNewKey = (e: React.FormEvent) => {
|
|
499
|
-
e.preventDefault();
|
|
500
|
-
if (newKey.trim() === "" || actions.isSubmitting) return;
|
|
501
|
-
void actions
|
|
502
|
-
.addKey({ accountId, apiKey: newKey.trim(), label: newLabel.trim() || undefined })
|
|
503
|
-
.then(() => {
|
|
504
|
-
setNewKey("");
|
|
505
|
-
setNewLabel("");
|
|
506
|
-
onChanged();
|
|
507
|
-
}, () => {
|
|
508
|
-
// Surfaced via actions.error (incl. Cursor's own key-class 401 text).
|
|
509
|
-
});
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
const importKeyCount = parseImportKeys(importText).length;
|
|
513
|
-
|
|
514
|
-
const submitImport = async (e: React.FormEvent) => {
|
|
515
|
-
e.preventDefault();
|
|
516
|
-
const keys = parseImportKeys(importText);
|
|
517
|
-
if (keys.length === 0 || isImporting) return;
|
|
518
|
-
|
|
519
|
-
setIsImporting(true);
|
|
520
|
-
setImportResults(null);
|
|
521
|
-
|
|
522
|
-
// Sequential on purpose: each key is validated live against Cursor's
|
|
523
|
-
// /v1/me, and per-key errors (wrong key class, revoked, duplicate)
|
|
524
|
-
// must be attributable to their line.
|
|
525
|
-
const knownKeyIds = new Set(
|
|
526
|
-
keyViews.map((kv) => kv.key?.keyId).filter((id): id is string => !!id),
|
|
527
|
-
);
|
|
528
|
-
const results: ImportLineResult[] = [];
|
|
529
|
-
const failedKeys: string[] = [];
|
|
530
|
-
for (const [i, key] of keys.entries()) {
|
|
531
|
-
setImportProgress({ done: i, total: keys.length });
|
|
532
|
-
try {
|
|
533
|
-
const account = await actions.addKey({ accountId, apiKey: key });
|
|
534
|
-
const addedKey = account.memberKeys.find((mk) => !knownKeyIds.has(mk.keyId));
|
|
535
|
-
if (addedKey) knownKeyIds.add(addedKey.keyId);
|
|
536
|
-
results.push({
|
|
537
|
-
keyPreview: maskKey(key, i),
|
|
538
|
-
ok: true,
|
|
539
|
-
message: addedKey?.boundEmail
|
|
540
|
-
? `added — bound to ${addedKey.boundEmail}`
|
|
541
|
-
: "added",
|
|
542
|
-
});
|
|
543
|
-
} catch (err) {
|
|
544
|
-
actions.clearError();
|
|
545
|
-
failedKeys.push(key);
|
|
546
|
-
results.push({
|
|
547
|
-
keyPreview: maskKey(key, i),
|
|
548
|
-
ok: false,
|
|
549
|
-
message: getUserMessage(toError(err)),
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
setImportProgress(null);
|
|
555
|
-
setImportResults(results);
|
|
556
|
-
// Failed lines stay in the box so the operator can fix and retry.
|
|
557
|
-
setImportText(failedKeys.join("\n"));
|
|
558
|
-
setIsImporting(false);
|
|
559
|
-
if (failedKeys.length < keys.length) onImported();
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
return (
|
|
563
|
-
<section className="space-y-2">
|
|
564
|
-
<h4 className="text-xs font-semibold text-foreground">Member execution keys</h4>
|
|
565
|
-
|
|
566
|
-
{keyViews.length === 0 ? (
|
|
567
|
-
<p className="text-xs text-muted-foreground" role="status">
|
|
568
|
-
No execution keys — this account is <strong>not routable</strong>.
|
|
569
|
-
Add a member's user-scoped API key below.
|
|
570
|
-
</p>
|
|
571
|
-
) : (
|
|
572
|
-
<ul role="list" aria-label="Member keys" className="m-0 list-none space-y-1 p-0">
|
|
573
|
-
{keyViews.map((keyView) => (
|
|
574
|
-
<MemberKeyRow
|
|
575
|
-
key={keyView.key?.keyId}
|
|
576
|
-
accountId={accountId}
|
|
577
|
-
keyView={keyView}
|
|
578
|
-
actions={actions}
|
|
579
|
-
onChanged={onChanged}
|
|
580
|
-
/>
|
|
581
|
-
))}
|
|
582
|
-
</ul>
|
|
583
|
-
)}
|
|
584
|
-
|
|
585
|
-
{actions.error && (
|
|
586
|
-
<p className="text-destructive text-xs" role="alert">
|
|
587
|
-
{getUserMessage(actions.error)}
|
|
588
|
-
</p>
|
|
589
|
-
)}
|
|
590
|
-
|
|
591
|
-
<form className="flex flex-wrap items-end gap-2" onSubmit={submitNewKey}>
|
|
592
|
-
<label className="block min-w-56 flex-1 space-y-1">
|
|
593
|
-
<span className="text-[11px] font-medium text-muted-foreground">
|
|
594
|
-
User-scoped API key
|
|
595
|
-
</span>
|
|
596
|
-
<input
|
|
597
|
-
className={INPUT_CLASSES}
|
|
598
|
-
type="password"
|
|
599
|
-
value={newKey}
|
|
600
|
-
onChange={(e) => setNewKey(e.target.value)}
|
|
601
|
-
placeholder="the member's personal Cursor API key"
|
|
602
|
-
disabled={actions.isSubmitting}
|
|
603
|
-
autoComplete="off"
|
|
604
|
-
/>
|
|
605
|
-
</label>
|
|
606
|
-
<label className="block min-w-40 space-y-1">
|
|
607
|
-
<span className="text-[11px] font-medium text-muted-foreground">
|
|
608
|
-
Label (optional)
|
|
609
|
-
</span>
|
|
610
|
-
<input
|
|
611
|
-
className={INPUT_CLASSES}
|
|
612
|
-
value={newLabel}
|
|
613
|
-
onChange={(e) => setNewLabel(e.target.value)}
|
|
614
|
-
placeholder="e.g. zane — prod"
|
|
615
|
-
disabled={actions.isSubmitting}
|
|
616
|
-
/>
|
|
617
|
-
</label>
|
|
618
|
-
<Button type="submit" size="sm" disabled={newKey.trim() === "" || actions.isSubmitting}>
|
|
619
|
-
{actions.isSubmitting ? "Verifying…" : "Add key"}
|
|
620
|
-
</Button>
|
|
621
|
-
<Button
|
|
622
|
-
type="button"
|
|
623
|
-
size="sm"
|
|
624
|
-
variant="outline"
|
|
625
|
-
disabled={isImporting}
|
|
626
|
-
onClick={() => {
|
|
627
|
-
setShowImport((v) => !v);
|
|
628
|
-
setImportResults(null);
|
|
629
|
-
}}
|
|
630
|
-
>
|
|
631
|
-
{showImport ? "Hide import" : "Import keys"}
|
|
632
|
-
</Button>
|
|
633
|
-
</form>
|
|
634
|
-
|
|
635
|
-
{showImport && (
|
|
636
|
-
<form className="space-y-2 rounded-md border border-border bg-card p-3" onSubmit={submitImport}>
|
|
637
|
-
<label className="block space-y-1">
|
|
638
|
-
<span className="text-[11px] font-medium text-muted-foreground">
|
|
639
|
-
Bulk import — one user-scoped API key per line
|
|
640
|
-
</span>
|
|
641
|
-
<textarea
|
|
642
|
-
className={cn(INPUT_CLASSES, "min-h-24 font-mono")}
|
|
643
|
-
value={importText}
|
|
644
|
-
onChange={(e) => setImportText(e.target.value)}
|
|
645
|
-
placeholder={"key_...\nkey_...\nkey_..."}
|
|
646
|
-
disabled={isImporting}
|
|
647
|
-
autoComplete="off"
|
|
648
|
-
spellCheck={false}
|
|
649
|
-
/>
|
|
650
|
-
</label>
|
|
651
|
-
<p className="text-[11px] text-muted-foreground">
|
|
652
|
-
Each key is verified against Cursor and bound to its owning team
|
|
653
|
-
member, one at a time. Lines that fail stay in the box so you can
|
|
654
|
-
fix and retry them. A roster sync runs automatically afterwards,
|
|
655
|
-
so the key badges reflect current team membership.
|
|
656
|
-
</p>
|
|
657
|
-
<div className="flex items-center gap-2">
|
|
658
|
-
<Button type="submit" size="sm" disabled={importKeyCount === 0 || isImporting}>
|
|
659
|
-
{isImporting && importProgress
|
|
660
|
-
? `Importing ${importProgress.done + 1} of ${importProgress.total}…`
|
|
661
|
-
: importKeyCount > 0
|
|
662
|
-
? `Import ${importKeyCount} ${importKeyCount === 1 ? "key" : "keys"}`
|
|
663
|
-
: "Import keys"}
|
|
664
|
-
</Button>
|
|
665
|
-
<Button
|
|
666
|
-
type="button"
|
|
667
|
-
size="sm"
|
|
668
|
-
variant="outline"
|
|
669
|
-
disabled={isImporting}
|
|
670
|
-
onClick={() => {
|
|
671
|
-
setShowImport(false);
|
|
672
|
-
setImportText("");
|
|
673
|
-
setImportResults(null);
|
|
674
|
-
}}
|
|
675
|
-
>
|
|
676
|
-
Close
|
|
677
|
-
</Button>
|
|
678
|
-
</div>
|
|
679
|
-
{importResults && (
|
|
680
|
-
<ul
|
|
681
|
-
role="list"
|
|
682
|
-
aria-label="Import results"
|
|
683
|
-
className="m-0 list-none space-y-0.5 p-0 text-[11px]"
|
|
684
|
-
>
|
|
685
|
-
{importResults.map((result) => (
|
|
686
|
-
<li
|
|
687
|
-
key={result.keyPreview}
|
|
688
|
-
className={result.ok ? "text-muted-foreground" : "text-destructive"}
|
|
689
|
-
>
|
|
690
|
-
{result.keyPreview}: {result.message}
|
|
691
|
-
</li>
|
|
692
|
-
))}
|
|
693
|
-
</ul>
|
|
694
|
-
)}
|
|
695
|
-
</form>
|
|
696
|
-
)}
|
|
697
|
-
</section>
|
|
698
|
-
);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function MemberKeyRow({
|
|
702
|
-
accountId,
|
|
703
|
-
keyView,
|
|
704
|
-
actions,
|
|
705
|
-
onChanged,
|
|
706
|
-
}: {
|
|
707
|
-
readonly accountId: string;
|
|
708
|
-
readonly keyView: CursorMemberKeyView;
|
|
709
|
-
readonly actions: ReturnType<typeof useCursorMemberKeyActions>;
|
|
710
|
-
readonly onChanged: () => void;
|
|
711
|
-
}) {
|
|
712
|
-
const key = keyView.key;
|
|
713
|
-
if (!key) return null;
|
|
714
|
-
|
|
715
|
-
return (
|
|
716
|
-
<li className="flex flex-wrap items-center justify-between gap-2 rounded-md border border-border bg-card px-3 py-2">
|
|
717
|
-
<span className="min-w-0">
|
|
718
|
-
<span className="block truncate text-xs font-medium text-foreground">
|
|
719
|
-
{key.boundEmail}
|
|
720
|
-
{key.label ? ` · ${key.label}` : ""}
|
|
721
|
-
</span>
|
|
722
|
-
<span className="block text-[11px] text-muted-foreground">
|
|
723
|
-
{key.cursorKeyName || "unnamed key"}
|
|
724
|
-
{keyView.spend
|
|
725
|
-
? ` · ${formatSpendMicros(
|
|
726
|
-
keyView.spend.includedSpendUsdMicros + keyView.spend.overageSpendUsdMicros,
|
|
727
|
-
)} this cycle`
|
|
728
|
-
: ""}
|
|
729
|
-
</span>
|
|
730
|
-
</span>
|
|
731
|
-
<span className="flex items-center gap-2">
|
|
732
|
-
<KeyStateBadge state={keyView.state} enabled={key.enabled} />
|
|
733
|
-
<Button
|
|
734
|
-
size="sm"
|
|
735
|
-
variant="outline"
|
|
736
|
-
disabled={actions.isSubmitting}
|
|
737
|
-
onClick={() => {
|
|
738
|
-
void actions
|
|
739
|
-
.setKeyEnabled(accountId, key.keyId, !key.enabled)
|
|
740
|
-
.then(onChanged, () => {
|
|
741
|
-
// Surfaced via actions.error.
|
|
742
|
-
});
|
|
743
|
-
}}
|
|
744
|
-
>
|
|
745
|
-
{key.enabled ? "Disable" : "Enable"}
|
|
746
|
-
</Button>
|
|
747
|
-
<Button
|
|
748
|
-
size="sm"
|
|
749
|
-
variant="destructive"
|
|
750
|
-
disabled={actions.isSubmitting}
|
|
751
|
-
onClick={() => {
|
|
752
|
-
void actions
|
|
753
|
-
.removeKey({ accountId, keyId: key.keyId })
|
|
754
|
-
.then(onChanged, () => {
|
|
755
|
-
// Surfaced via actions.error (incl. the live-pin guard's
|
|
756
|
-
// "disable instead, or force" message).
|
|
757
|
-
});
|
|
758
|
-
}}
|
|
759
|
-
>
|
|
760
|
-
Remove
|
|
761
|
-
</Button>
|
|
762
|
-
</span>
|
|
763
|
-
</li>
|
|
764
|
-
);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
// ---------------------------------------------------------------------------
|
|
768
|
-
// Badges (internal)
|
|
769
|
-
// ---------------------------------------------------------------------------
|
|
770
|
-
|
|
771
|
-
function StateBadge({
|
|
772
|
-
tone,
|
|
773
|
-
label,
|
|
774
|
-
}: {
|
|
775
|
-
readonly tone: "ok" | "warn" | "muted";
|
|
776
|
-
readonly label: string;
|
|
777
|
-
}) {
|
|
778
|
-
return (
|
|
779
|
-
<span
|
|
780
|
-
className={cn(
|
|
781
|
-
"inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",
|
|
782
|
-
tone === "ok" && "bg-accent text-primary",
|
|
783
|
-
tone === "warn" && "bg-muted-subtle text-destructive",
|
|
784
|
-
tone === "muted" && "bg-muted-subtle text-muted-foreground",
|
|
785
|
-
)}
|
|
786
|
-
>
|
|
787
|
-
{label}
|
|
788
|
-
</span>
|
|
789
|
-
);
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
function KeyStateBadge({
|
|
793
|
-
state,
|
|
794
|
-
enabled,
|
|
795
|
-
}: {
|
|
796
|
-
readonly state: CursorMemberKeyState;
|
|
797
|
-
readonly enabled: boolean;
|
|
798
|
-
}) {
|
|
799
|
-
if (state === CursorMemberKeyState.member_key_owner_removed) {
|
|
800
|
-
return <StateBadge tone="warn" label="Owner left team" />;
|
|
801
|
-
}
|
|
802
|
-
if (state === CursorMemberKeyState.member_key_owner_unknown) {
|
|
803
|
-
return <StateBadge tone="muted" label="Owner unknown" />;
|
|
804
|
-
}
|
|
805
|
-
return enabled ? (
|
|
806
|
-
<StateBadge tone="ok" label="Active" />
|
|
807
|
-
) : (
|
|
808
|
-
<StateBadge tone="muted" label="Disabled" />
|
|
809
|
-
);
|
|
810
|
-
}
|