@startsimpli/integrations 0.2.77 → 0.2.78
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 +6 -1
- package/package.json +3 -3
- package/src/__tests__/api-fetch-factories.test.ts +81 -0
- package/src/api/_fetch.ts +93 -61
- package/src/api/connections.ts +162 -152
- package/src/api/mcp-tokens.ts +25 -15
- package/src/components/pages/ConnectClaudePage.tsx +1 -14
- package/src/components/pages/MemberConnectionRoster.tsx +2 -5
- package/src/components/pages/PlanningPage.tsx +3 -15
- package/src/components/pages/connect-claude-format.ts +24 -0
- package/src/components/pages/connection-format.ts +20 -0
- package/src/components/pages/work-items.tsx +4 -51
- package/src/corpus/planning.ts +21 -0
- package/src/corpus/work-item-logic.ts +59 -0
- package/src/native/corpus/api.ts +2 -3
- package/src/native/index.ts +16 -0
- package/src/native/screens/connect-claude/ConnectClaudeScreen.tsx +102 -0
- package/src/native/screens/connect-claude/__tests__/controller.test.ts +116 -0
- package/src/native/screens/connect-claude/controller.ts +108 -0
- package/src/native/screens/connect-claude/fake.ts +57 -0
- package/src/native/screens/connect-claude/tab.tsx +19 -0
- package/src/native/screens/connections/ConnectionsScreens.tsx +108 -0
- package/src/native/screens/connections/__tests__/controller.test.ts +66 -0
- package/src/native/screens/connections/controller.ts +93 -0
- package/src/native/screens/connections/fake.ts +69 -0
- package/src/native/screens/connections/tab.tsx +15 -0
- package/src/native/screens/planning/PlanningScreens.tsx +178 -0
- package/src/native/screens/planning/__tests__/controller.test.ts +145 -0
- package/src/native/screens/planning/__tests__/format.test.ts +29 -0
- package/src/native/screens/planning/controller.ts +173 -0
- package/src/native/screens/planning/fake.ts +16 -0
- package/src/native/screens/planning/format.ts +49 -0
- package/src/native/screens/planning/tab.tsx +26 -0
- package/src/native/screens/shared/PressableCard.tsx +14 -0
- package/src/native/screens/shared/format.ts +10 -0
package/src/api/mcp-tokens.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* until it expires and cannot be withdrawn (startsim-ja8mt). Nothing in this
|
|
23
23
|
* package may call `mint` from an effect.
|
|
24
24
|
*/
|
|
25
|
-
import { request } from './_fetch';
|
|
25
|
+
import { createRequester, request, type ClientDeps, type Requester } from './_fetch';
|
|
26
26
|
|
|
27
27
|
/** A foundry the signed-in account may connect a client to. */
|
|
28
28
|
export interface McpFoundry {
|
|
@@ -69,18 +69,28 @@ export interface McpTokensApi {
|
|
|
69
69
|
|
|
70
70
|
const BASE = '/auth/mcp-token';
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
function build(request: Requester): McpTokensApi {
|
|
73
|
+
return {
|
|
74
|
+
/**
|
|
75
|
+
* The foundries this account holds an active seat in. Advisory — central
|
|
76
|
+
* refuses the mint independently — so a slug that appears here can still be
|
|
77
|
+
* denied, and the composer has to render that denial rather than assume the
|
|
78
|
+
* list was authoritative.
|
|
79
|
+
*/
|
|
80
|
+
list(): Promise<McpFoundryList> {
|
|
81
|
+
return request<McpFoundryList>(`${BASE}/`);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
mint(input: { foundry: string; ttl_days?: number }): Promise<McpMintedToken> {
|
|
85
|
+
return request<McpMintedToken>(`${BASE}/`, { method: 'POST', body: input });
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The web client: global base, token provider and fetch. */
|
|
91
|
+
export const mcpTokens: McpTokensApi = build(request);
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
93
|
+
/** The same client over an injected fetch (a phone's `authorizedFetch`). */
|
|
94
|
+
export function createMcpTokensApi(deps: ClientDeps): McpTokensApi {
|
|
95
|
+
return build(createRequester(deps));
|
|
96
|
+
}
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import * as React from 'react';
|
|
32
32
|
|
|
33
|
+
import { daysUntil, readableDate } from './connect-claude-format';
|
|
33
34
|
import type { McpFoundry, McpMintedToken, McpTokensApi } from '../../api/mcp-tokens';
|
|
34
35
|
|
|
35
36
|
type ClassNames = Partial<Record<
|
|
@@ -60,20 +61,6 @@ function cx(theme: ClassNames | undefined, key: keyof typeof FALLBACK): string {
|
|
|
60
61
|
return theme?.[key] ?? FALLBACK[key];
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
/** Local-date rendering, so "expires" is not an ISO string a person has to parse. */
|
|
64
|
-
function readableDate(iso: string): string {
|
|
65
|
-
const d = new Date(iso);
|
|
66
|
-
return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString(undefined, {
|
|
67
|
-
year: 'numeric', month: 'long', day: 'numeric',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function daysUntil(iso: string): number | null {
|
|
72
|
-
const d = new Date(iso);
|
|
73
|
-
if (Number.isNaN(d.getTime())) return null;
|
|
74
|
-
return Math.max(0, Math.round((d.getTime() - Date.now()) / 86_400_000));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
64
|
export function ConnectClaudePage({ api, classNames, foundrySlug }: ConnectClaudePageProps) {
|
|
78
65
|
const [list, setList] = React.useState<{ foundries: McpFoundry[]; maxTtl: number; defaultTtl: number } | null>(null);
|
|
79
66
|
const [selected, setSelected] = React.useState<string>(foundrySlug ?? '');
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import * as React from 'react';
|
|
24
24
|
|
|
25
|
+
import { connectionStatusLine } from './connection-format';
|
|
25
26
|
import type {
|
|
26
27
|
ConnectionPermissions,
|
|
27
28
|
MemberConnectionRow,
|
|
@@ -146,11 +147,7 @@ function MemberConnectionCard({
|
|
|
146
147
|
{row.account_label ? ` · ${row.account_label}` : ''}
|
|
147
148
|
</p>
|
|
148
149
|
<p className="mt-1 text-xs text-gray-400">
|
|
149
|
-
{row
|
|
150
|
-
{row.health ? ` · ${row.health}` : ''}
|
|
151
|
-
{row.last_checked_at
|
|
152
|
-
? ` · last checked ${new Date(row.last_checked_at).toLocaleString()}`
|
|
153
|
-
: ' · never checked'}
|
|
150
|
+
{connectionStatusLine(row)}
|
|
154
151
|
</p>
|
|
155
152
|
{/* The vendor's own failure text, which the server already scrubbed of
|
|
156
153
|
anything the member submitted. An admin deciding whether to cut a
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import * as React from 'react';
|
|
33
33
|
|
|
34
|
-
import { displayProgress } from '../../corpus/planning';
|
|
34
|
+
import { displayProgress, focusStatusLabel, standingLabel } from '../../corpus/planning';
|
|
35
35
|
import { FocusDocuments } from '../FocusDocuments';
|
|
36
36
|
import {
|
|
37
37
|
UnfilteredNotice,
|
|
@@ -421,7 +421,7 @@ function FocusCard({
|
|
|
421
421
|
className={`${cn.card} text-left ${selected ? 'ring-2 ring-gray-900' : ''}`}
|
|
422
422
|
>
|
|
423
423
|
<div className="flex flex-wrap items-center gap-2">
|
|
424
|
-
<span className={cn.badge}>{focus.status
|
|
424
|
+
<span className={cn.badge}>{focusStatusLabel(focus.status)}</span>
|
|
425
425
|
{focus.category ? <span className={cn.badge}>{focus.category}</span> : null}
|
|
426
426
|
{focus.timeFrame ? (
|
|
427
427
|
<span className={cn.badge}>
|
|
@@ -442,19 +442,7 @@ function FocusCard({
|
|
|
442
442
|
) : null}
|
|
443
443
|
|
|
444
444
|
<p className={`mt-2 ${cn.muted}`}>
|
|
445
|
-
{standing
|
|
446
|
-
// Not "0 of 0". A standing that has not arrived and a focus with
|
|
447
|
-
// nothing under it are different facts, and only one of them is
|
|
448
|
-
// actionable.
|
|
449
|
-
'Counting…'
|
|
450
|
-
) : standing.total === 0 ? (
|
|
451
|
-
'Nothing filed under this yet'
|
|
452
|
-
) : (
|
|
453
|
-
<>
|
|
454
|
-
{standing.done} of {standing.total} done
|
|
455
|
-
{standing.overdue ? ` · ${standing.overdue} overdue` : ''}
|
|
456
|
-
</>
|
|
457
|
-
)}
|
|
445
|
+
{standingLabel(standing)}
|
|
458
446
|
{focus.targetValue !== undefined && focus.targetValue !== null ? (
|
|
459
447
|
<> · {focus.currentValue ?? 0} / {focus.targetValue} {focus.unit ?? ''}</>
|
|
460
448
|
) : null}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dates on the Connect Claude screens, shared by web and native (bd
|
|
3
|
+
* startsim-23np6.1.6). Pure: the clock is a parameter so a test does not depend on today.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Local-date rendering, so "expires" is not an ISO string a person has to parse. */
|
|
7
|
+
export function readableDate(iso: string): string {
|
|
8
|
+
const d = new Date(iso);
|
|
9
|
+
return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString(undefined, {
|
|
10
|
+
year: 'numeric', month: 'long', day: 'numeric',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function daysUntil(iso: string, now: number = Date.now()): number | null {
|
|
15
|
+
const d = new Date(iso);
|
|
16
|
+
if (Number.isNaN(d.getTime())) return null;
|
|
17
|
+
return Math.max(0, Math.round((d.getTime() - now) / 86_400_000));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** "Expires November 5, 2026 - about 2 days". */
|
|
21
|
+
export function expiryLine(iso: string, now: number = Date.now()): string {
|
|
22
|
+
const days = daysUntil(iso, now);
|
|
23
|
+
return `Expires ${readableDate(iso)}${days !== null ? ` — about ${days} days` : ''}`;
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a connection's state reads, shared by the web roster and the native screen
|
|
3
|
+
* (bd startsim-23np6.1.6) so they cannot disagree about it. Pure: no React, no DOM.
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionStatus } from './types';
|
|
6
|
+
|
|
7
|
+
/** "connected · ok · last checked <when>" - or "never checked". */
|
|
8
|
+
export function connectionStatusLine(
|
|
9
|
+
row: { status: ConnectionStatus; health?: string; last_checked_at?: string | null },
|
|
10
|
+
formatWhen: (iso: string) => string = (iso) => new Date(iso).toLocaleString(),
|
|
11
|
+
): string {
|
|
12
|
+
return `${row.status}${row.health ? ` · ${row.health}` : ''}${
|
|
13
|
+
row.last_checked_at ? ` · last checked ${formatWhen(row.last_checked_at)}` : ' · never checked'
|
|
14
|
+
}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A person's words for a status word. */
|
|
18
|
+
export function connectionStatusLabel(status: ConnectionStatus): string {
|
|
19
|
+
return ({ connected: 'Connected', needs_reauth: 'Needs reconnecting', error: 'Error', disabled: 'Disconnected' } as const)[status] ?? status;
|
|
20
|
+
}
|
|
@@ -36,57 +36,10 @@ export const WORK_ITEM_DEFAULTS: Record<WorkItemSlot, string> = {
|
|
|
36
36
|
|
|
37
37
|
const DAY_MS = 86_400_000;
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (priority === undefined || priority === null) return null;
|
|
44
|
-
return PRIORITY_LABELS[priority] ?? null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
// predicates — what the screens mean by "overdue" and "changed"
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Past its stated date and still owed.
|
|
53
|
-
*
|
|
54
|
-
* A `done` or `dropped` item is never overdue however old its date is, because
|
|
55
|
-
* an overdue count is a list of things to do and a finished item is not one.
|
|
56
|
-
*/
|
|
57
|
-
export function isOverdue(item: Commitment, now: number): boolean {
|
|
58
|
-
if (!item.dueAt) return false;
|
|
59
|
-
if (item.status === 'done' || item.status === 'dropped') return false;
|
|
60
|
-
return Date.parse(item.dueAt) < now;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function changedSince(item: Commitment, since: number): boolean {
|
|
64
|
-
const stamps = [item.lastSeenAt, item.resolvedAt].filter(Boolean) as string[];
|
|
65
|
-
return stamps.some((stamp) => Date.parse(stamp) >= since);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Overdue first, then the oldest thing still open.
|
|
70
|
-
*
|
|
71
|
-
* Sorting by "raised longest ago and still not done" rather than by recency is
|
|
72
|
-
* the whole difference between a list of meetings and a list of debts.
|
|
73
|
-
*/
|
|
74
|
-
export function compareForScreen(now: number) {
|
|
75
|
-
return (a: Commitment, b: Commitment): number => {
|
|
76
|
-
const overdue = Number(isOverdue(b, now)) - Number(isOverdue(a, now));
|
|
77
|
-
if (overdue !== 0) return overdue;
|
|
78
|
-
if (a.dueAt && b.dueAt && a.dueAt !== b.dueAt) return a.dueAt.localeCompare(b.dueAt);
|
|
79
|
-
if (a.dueAt !== b.dueAt) return a.dueAt ? -1 : 1;
|
|
80
|
-
return (a.firstSeenAt ?? '').localeCompare(b.firstSeenAt ?? '');
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function failureMessage(err: unknown): string {
|
|
85
|
-
const status = (err as { status?: number })?.status;
|
|
86
|
-
if (status === 403) return 'You do not have access to this workspace’s records.';
|
|
87
|
-
if (status === 401) return 'Your session has expired. Sign in again.';
|
|
88
|
-
return (err as { message?: string })?.message || 'That could not be loaded right now.';
|
|
89
|
-
}
|
|
39
|
+
export {
|
|
40
|
+
PRIORITY_LABELS, changedSince, compareForScreen, failureMessage, isOverdue, priorityLabel,
|
|
41
|
+
} from '../../corpus/work-item-logic';
|
|
42
|
+
import { isOverdue, priorityLabel } from '../../corpus/work-item-logic';
|
|
90
43
|
|
|
91
44
|
// ---------------------------------------------------------------------------
|
|
92
45
|
// the honesty banner
|
package/src/corpus/planning.ts
CHANGED
|
@@ -321,3 +321,24 @@ export function displayProgress(focus: Focus, standing?: FocusStanding | null):
|
|
|
321
321
|
if (focus.progress !== undefined && focus.progress !== null) return focus.progress;
|
|
322
322
|
return focusProgress(focus, standing);
|
|
323
323
|
}
|
|
324
|
+
|
|
325
|
+
// ---------------------------------------------------------------------------
|
|
326
|
+
// words — shared by the web card and the native one
|
|
327
|
+
// ---------------------------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
/** `on_track` -> `on track`. */
|
|
330
|
+
export function focusStatusLabel(status: FocusStatus): string {
|
|
331
|
+
return status.replace(/_/g, ' ');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The line under a focus: "12 of 40 done · 3 overdue".
|
|
336
|
+
*
|
|
337
|
+
* NOT "0 of 0" for a standing that has not arrived: a count in flight and a focus
|
|
338
|
+
* with nothing under it are different facts, and only one of them is actionable.
|
|
339
|
+
*/
|
|
340
|
+
export function standingLabel(standing: FocusStanding | null): string {
|
|
341
|
+
if (standing === null) return 'Counting…';
|
|
342
|
+
if (standing.total === 0) return 'Nothing filed under this yet';
|
|
343
|
+
return `${standing.done} of ${standing.total} done${standing.overdue ? ` · ${standing.overdue} overdue` : ''}`;
|
|
344
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of the work-item screens: what "overdue" and "changed" mean, the
|
|
3
|
+
* priority words and how a failure reads. No React and no DOM, so the web
|
|
4
|
+
* composers (`components/pages/work-items`) and the native screens share ONE
|
|
5
|
+
* definition (bd startsim-23np6.1.6) instead of each keeping a copy that drifts.
|
|
6
|
+
*/
|
|
7
|
+
import type { Commitment } from './types';
|
|
8
|
+
|
|
9
|
+
/** `WorkItem.Priority` — 0 critical .. 4 backlog, ascending is urgent. */
|
|
10
|
+
export const PRIORITY_LABELS = ['Critical', 'High', 'Medium', 'Low', 'Backlog'] as const;
|
|
11
|
+
|
|
12
|
+
export function priorityLabel(priority?: number): string | null {
|
|
13
|
+
if (priority === undefined || priority === null) return null;
|
|
14
|
+
return PRIORITY_LABELS[priority] ?? null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// predicates — what the screens mean by "overdue" and "changed"
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Past its stated date and still owed.
|
|
23
|
+
*
|
|
24
|
+
* A `done` or `dropped` item is never overdue however old its date is, because
|
|
25
|
+
* an overdue count is a list of things to do and a finished item is not one.
|
|
26
|
+
*/
|
|
27
|
+
export function isOverdue(item: Commitment, now: number): boolean {
|
|
28
|
+
if (!item.dueAt) return false;
|
|
29
|
+
if (item.status === 'done' || item.status === 'dropped') return false;
|
|
30
|
+
return Date.parse(item.dueAt) < now;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function changedSince(item: Commitment, since: number): boolean {
|
|
34
|
+
const stamps = [item.lastSeenAt, item.resolvedAt].filter(Boolean) as string[];
|
|
35
|
+
return stamps.some((stamp) => Date.parse(stamp) >= since);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Overdue first, then the oldest thing still open.
|
|
40
|
+
*
|
|
41
|
+
* Sorting by "raised longest ago and still not done" rather than by recency is
|
|
42
|
+
* the whole difference between a list of meetings and a list of debts.
|
|
43
|
+
*/
|
|
44
|
+
export function compareForScreen(now: number) {
|
|
45
|
+
return (a: Commitment, b: Commitment): number => {
|
|
46
|
+
const overdue = Number(isOverdue(b, now)) - Number(isOverdue(a, now));
|
|
47
|
+
if (overdue !== 0) return overdue;
|
|
48
|
+
if (a.dueAt && b.dueAt && a.dueAt !== b.dueAt) return a.dueAt.localeCompare(b.dueAt);
|
|
49
|
+
if (a.dueAt !== b.dueAt) return a.dueAt ? -1 : 1;
|
|
50
|
+
return (a.firstSeenAt ?? '').localeCompare(b.firstSeenAt ?? '');
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function failureMessage(err: unknown): string {
|
|
55
|
+
const status = (err as { status?: number })?.status;
|
|
56
|
+
if (status === 403) return 'You do not have access to this workspace’s records.';
|
|
57
|
+
if (status === 401) return 'Your session has expired. Sign in again.';
|
|
58
|
+
return (err as { message?: string })?.message || 'That could not be loaded right now.';
|
|
59
|
+
}
|
package/src/native/corpus/api.ts
CHANGED
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
* `reconcileFilters` reads the server's `applied_filters`, so a filter the
|
|
10
10
|
* endpoint ignored comes back as `ignoredFilters` instead of looking applied.
|
|
11
11
|
*
|
|
12
|
-
* Not used from here: `mcpTokens` / `connectionsMe` (api/*)
|
|
13
|
-
*
|
|
14
|
-
* tabs need a `create*Api(fetch)` factory first (see the README).
|
|
12
|
+
* Not used from here: `mcpTokens` / `connectionsMe` (api/*). Their `create*Api({ baseUrl, fetch })`
|
|
13
|
+
* factories take the same authorized fetch; see `screens/` for the Connections / Connect Claude tabs.
|
|
15
14
|
*/
|
|
16
15
|
import { createPlanningApi, type CreateCorpusApiOptions } from '../../corpus/client';
|
|
17
16
|
import { isRecord, notFound } from '../../corpus/client';
|
package/src/native/index.ts
CHANGED
|
@@ -41,3 +41,19 @@ export * from './screens/ask/answer-view';
|
|
|
41
41
|
export * from './screens/ask/controller';
|
|
42
42
|
export { AskScreen, type AskScreenProps } from './screens/ask/AskScreen';
|
|
43
43
|
export * from './screens/tabs';
|
|
44
|
+
// Planning, Connections, Connect Claude (bd startsim-23np6.1.6)
|
|
45
|
+
export {
|
|
46
|
+
createFocusDetailController, createPlanningController, STANDING_CONCURRENCY,
|
|
47
|
+
type FocusDetailController, type FocusDetailState, type PlanningController, type PlanningScreenApi, type PlanningState,
|
|
48
|
+
} from './screens/planning/controller';
|
|
49
|
+
export { createFakePlanningApi } from './screens/planning/fake';
|
|
50
|
+
export { PlanningDetailScreen, PlanningListScreen, type PlanningDetailScreenProps, type PlanningListScreenProps } from './screens/planning/PlanningScreens';
|
|
51
|
+
export { createPlanningTab } from './screens/planning/tab';
|
|
52
|
+
export { createConnectionsController, type ConnectionsController, type ConnectionsState } from './screens/connections/controller';
|
|
53
|
+
export { createFakeConnectionsApi, sampleConnections, type FakeConnectionsApi } from './screens/connections/fake';
|
|
54
|
+
export { ConnectionDetailScreen, ConnectionsListScreen, type ConnectionsListScreenProps } from './screens/connections/ConnectionsScreens';
|
|
55
|
+
export { createConnectionsTab } from './screens/connections/tab';
|
|
56
|
+
export { createConnectClaudeController, type ConnectClaudeController, type ConnectClaudeState, type ShareText } from './screens/connect-claude/controller';
|
|
57
|
+
export { createFakeMcpTokensApi, type FakeMcpTokensApi } from './screens/connect-claude/fake';
|
|
58
|
+
export { ConnectClaudeScreen, shareWithSystem } from './screens/connect-claude/ConnectClaudeScreen';
|
|
59
|
+
export { createConnectClaudeTab } from './screens/connect-claude/tab';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { Share, ScrollView, View } from 'react-native';
|
|
3
|
+
import { Alert, Button, Header, Input, Select, Spinner, Text, useTheme } from '@startsimpli/ui-native';
|
|
4
|
+
import type { McpTokensApi } from '../../../api/mcp-tokens';
|
|
5
|
+
import { useControllerState } from '../../components/useControllerState';
|
|
6
|
+
import { createConnectClaudeController, type ConnectClaudeController, type ShareText } from './controller';
|
|
7
|
+
|
|
8
|
+
/** The system share sheet (Copy is on it). `false` when the person dismissed it. */
|
|
9
|
+
export const shareWithSystem: ShareText = async (text) => {
|
|
10
|
+
const result = await Share.share({ message: text });
|
|
11
|
+
return result.action !== Share.dismissedAction;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function ConnectClaudeScreen({ controller }: { controller: ConnectClaudeController }) {
|
|
15
|
+
const s = useControllerState(controller);
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
const gap = { gap: theme.spacing.md } as const;
|
|
18
|
+
|
|
19
|
+
let body;
|
|
20
|
+
if (s.phase === 'loading') {
|
|
21
|
+
body = <Spinner />;
|
|
22
|
+
} else if (s.phase === 'error') {
|
|
23
|
+
body = (
|
|
24
|
+
<View style={gap}>
|
|
25
|
+
<Alert variant="destructive">{s.error ?? 'Could not load your workspaces.'}</Alert>
|
|
26
|
+
<Button title="Try again" onPress={() => { void controller.refresh(); }} />
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
} else if (s.foundries.length === 0) {
|
|
30
|
+
body = <Text variant="muted">You are not a member of any workspace that can be connected yet. Ask an owner or admin to invite you, then come back.</Text>;
|
|
31
|
+
} else if (s.minted) {
|
|
32
|
+
const m = s.minted;
|
|
33
|
+
body = (
|
|
34
|
+
<View style={gap} testID="connect-claude-token">
|
|
35
|
+
<Text variant="heading">Your token: copy it now</Text>
|
|
36
|
+
<View style={{ gap: 2 }}>
|
|
37
|
+
<Text variant="muted">This connection reads</Text>
|
|
38
|
+
<Text>{m.foundry}{m.acting_as.email ? ` as ${m.acting_as.email}` : ''}{m.acting_as.role ? ` (${m.acting_as.role})` : ''}</Text>
|
|
39
|
+
<Text variant="muted">{s.expiry}</Text>
|
|
40
|
+
</View>
|
|
41
|
+
<Alert variant="destructive">{m.notice}</Alert>
|
|
42
|
+
{m.claude_code_command ? (
|
|
43
|
+
<View style={{ gap: theme.spacing.sm }}>
|
|
44
|
+
<Text variant="muted">Run this in your terminal:</Text>
|
|
45
|
+
<Text selectable testID="connect-claude-command" style={{ fontFamily: 'Menlo', fontSize: theme.fontSizes.xs }}>{m.claude_code_command}</Text>
|
|
46
|
+
<Button testID="connect-claude-share-command" title={s.shared === 'command' ? 'Shared' : 'Copy or share command'} onPress={() => { void controller.share('command'); }} />
|
|
47
|
+
</View>
|
|
48
|
+
) : null}
|
|
49
|
+
<View style={{ gap: theme.spacing.sm }}>
|
|
50
|
+
<Text variant="muted">Just the token:</Text>
|
|
51
|
+
<Text selectable testID="connect-claude-token-text" style={{ fontFamily: 'Menlo', fontSize: theme.fontSizes.xs }}>{m.token}</Text>
|
|
52
|
+
<Button testID="connect-claude-share-token" variant="outline" title={s.shared === 'token' ? 'Shared' : 'Copy or share token'} onPress={() => { void controller.share('token'); }} />
|
|
53
|
+
</View>
|
|
54
|
+
<Button testID="connect-claude-done" title="Done" variant="ghost" onPress={() => controller.done()} />
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
body = (
|
|
59
|
+
<View style={gap} testID="connect-claude-form">
|
|
60
|
+
{s.foundries.length > 1 ? (
|
|
61
|
+
<Select
|
|
62
|
+
label="Which workspace?"
|
|
63
|
+
testID="connect-claude-workspace"
|
|
64
|
+
options={s.foundries.map((f) => ({ value: f.slug, label: f.name }))}
|
|
65
|
+
value={s.selected || null}
|
|
66
|
+
onChange={(v) => controller.select(v ?? '')}
|
|
67
|
+
/>
|
|
68
|
+
) : null}
|
|
69
|
+
<View style={{ gap: theme.spacing.xs }}>
|
|
70
|
+
<Text variant="heading" style={{ fontSize: theme.fontSizes.base }}>How long should it last?</Text>
|
|
71
|
+
<Input
|
|
72
|
+
testID="connect-claude-ttl"
|
|
73
|
+
keyboardType="number-pad"
|
|
74
|
+
placeholder={`${s.defaultTtl} days`}
|
|
75
|
+
value={s.ttlDays === null ? '' : String(s.ttlDays)}
|
|
76
|
+
onChangeText={(t) => controller.setTtlDays(t.trim() === '' || Number.isNaN(Number(t)) ? null : Number(t))}
|
|
77
|
+
/>
|
|
78
|
+
<Text variant="muted">Up to {s.maxTtl} days. Shorter is safer: this cannot be cancelled early, so the expiry date is the only way it stops working.</Text>
|
|
79
|
+
</View>
|
|
80
|
+
<Alert variant="destructive" title="Before you create this">
|
|
81
|
+
It reads this workspace as you: whatever you can see, it can see. It is shown once and cannot be retrieved again, and it cannot be cancelled before it expires. Turning off your access to the workspace stops new ones being made; it does not switch this one off.
|
|
82
|
+
</Alert>
|
|
83
|
+
{s.error ? <Alert variant="destructive">{s.error}</Alert> : null}
|
|
84
|
+
<Button testID="connect-claude-create" title={s.minting ? 'Creating...' : 'Create connection token'} disabled={!s.selected || s.minting} onPress={() => { void controller.mint(); }} />
|
|
85
|
+
<Text variant="muted">Tokens you made earlier cannot be listed or cancelled here: the server keeps no copy and cannot withdraw one before it expires.</Text>
|
|
86
|
+
</View>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return (
|
|
90
|
+
<View style={{ flex: 1 }}>
|
|
91
|
+
<Header title="Connect Claude" subtitle="Let an MCP client read this workspace" />
|
|
92
|
+
<ScrollView contentContainerStyle={{ padding: theme.spacing.lg }} keyboardShouldPersistTaps="handled">{body}</ScrollView>
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function useConnectClaudeController(api: McpTokensApi, share: ShareText = shareWithSystem): ConnectClaudeController {
|
|
98
|
+
const controller = useMemo(() => createConnectClaudeController({ api, share }), [api, share]);
|
|
99
|
+
// Leaving the screen with a token on it must not leave the token behind in memory.
|
|
100
|
+
useEffect(() => () => controller.done(), [controller]);
|
|
101
|
+
return controller;
|
|
102
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createFakeMcpTokensApi } from '../fake';
|
|
3
|
+
import { createConnectClaudeController } from '../controller';
|
|
4
|
+
|
|
5
|
+
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
6
|
+
async function settle(check: () => boolean) { for (let i = 0; i < 50 && !check(); i += 1) await tick(); }
|
|
7
|
+
const NOW = Date.parse('2026-11-03T12:00:00Z');
|
|
8
|
+
|
|
9
|
+
function setup(over: Parameters<typeof createFakeMcpTokensApi>[0] = {}, share = vi.fn(async () => true)) {
|
|
10
|
+
const api = createFakeMcpTokensApi(over);
|
|
11
|
+
const c = createConnectClaudeController({ api, share, now: () => NOW });
|
|
12
|
+
return { api, c, share };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('connect claude: list on open, mint only on a tap', () => {
|
|
16
|
+
it('lists the workspaces on open and mints nothing', async () => {
|
|
17
|
+
const { api, c } = setup();
|
|
18
|
+
await settle(() => c.getState().phase !== 'loading');
|
|
19
|
+
expect(c.getState().phase).toBe('ready');
|
|
20
|
+
expect(c.getState().foundries.map((f) => f.slug)).toEqual(['tandem']);
|
|
21
|
+
expect(api.calls.list).toBe(1);
|
|
22
|
+
expect(api.calls.mint).toEqual([]);
|
|
23
|
+
await c.refresh();
|
|
24
|
+
expect(api.calls.mint).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('preselects the only workspace, and waits for a choice when there are several', async () => {
|
|
28
|
+
const one = setup();
|
|
29
|
+
await settle(() => one.c.getState().phase === 'ready');
|
|
30
|
+
expect(one.c.getState().selected).toBe('tandem');
|
|
31
|
+
const many = setup({ foundries: [
|
|
32
|
+
{ slug: 'a', name: 'A', audience: 'a', mcp_url: 'https://a/mcp', state: 'active' },
|
|
33
|
+
{ slug: 'b', name: 'B', audience: 'b', mcp_url: 'https://b/mcp', state: 'active' },
|
|
34
|
+
] });
|
|
35
|
+
await settle(() => many.c.getState().phase === 'ready');
|
|
36
|
+
expect(many.c.getState().selected).toBe('');
|
|
37
|
+
await many.c.mint();
|
|
38
|
+
expect(many.api.calls.mint).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('mints once for the chosen workspace and ttl and keeps the token for display', async () => {
|
|
42
|
+
const { api, c } = setup();
|
|
43
|
+
await settle(() => c.getState().phase === 'ready');
|
|
44
|
+
c.setTtlDays(7);
|
|
45
|
+
await c.mint();
|
|
46
|
+
expect(api.calls.mint).toEqual([{ foundry: 'tandem', ttl_days: 7 }]);
|
|
47
|
+
expect(c.getState().minted?.token).toBe('fake-mcp-token-1');
|
|
48
|
+
expect(c.getState().minting).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('omits ttl when none was chosen, so the server default applies', async () => {
|
|
52
|
+
const { api, c } = setup();
|
|
53
|
+
await settle(() => c.getState().phase === 'ready');
|
|
54
|
+
await c.mint();
|
|
55
|
+
expect(api.calls.mint).toEqual([{ foundry: 'tandem' }]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('ignores a second tap while a mint is in flight', async () => {
|
|
59
|
+
const { api, c } = setup({ mintDelayMs: 5 });
|
|
60
|
+
await settle(() => c.getState().phase === 'ready');
|
|
61
|
+
await Promise.all([c.mint(), c.mint(), c.mint()]);
|
|
62
|
+
expect(api.calls.mint).toHaveLength(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('shows the refusal and mints nothing when central says no', async () => {
|
|
66
|
+
const { c } = setup({ mintError: Object.assign(new Error('No seat in this workspace.'), { status: 403 }) });
|
|
67
|
+
await settle(() => c.getState().phase === 'ready');
|
|
68
|
+
await c.mint();
|
|
69
|
+
expect(c.getState().minted).toBeNull();
|
|
70
|
+
expect(c.getState().error).toBe('No seat in this workspace.');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('reports a failed list as an error state', async () => {
|
|
74
|
+
const { c } = setup({ listError: new Error('offline') });
|
|
75
|
+
await settle(() => c.getState().phase !== 'loading');
|
|
76
|
+
expect(c.getState().phase).toBe('error');
|
|
77
|
+
expect(c.getState().error).toBe('offline');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('shares the token or the command through the system share sheet and says which', async () => {
|
|
81
|
+
const { c, share } = setup();
|
|
82
|
+
await settle(() => c.getState().phase === 'ready');
|
|
83
|
+
await c.mint();
|
|
84
|
+
await c.share('command');
|
|
85
|
+
expect(share).toHaveBeenLastCalledWith(c.getState().minted?.claude_code_command);
|
|
86
|
+
expect(c.getState().shared).toBe('command');
|
|
87
|
+
await c.share('token');
|
|
88
|
+
expect(share).toHaveBeenLastCalledWith('fake-mcp-token-1');
|
|
89
|
+
expect(c.getState().shared).toBe('token');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('a dismissed share sheet is not an error and does not claim it was shared', async () => {
|
|
93
|
+
const { c } = setup({}, vi.fn(async () => false));
|
|
94
|
+
await settle(() => c.getState().phase === 'ready');
|
|
95
|
+
await c.mint();
|
|
96
|
+
await c.share('token');
|
|
97
|
+
expect(c.getState().shared).toBe('');
|
|
98
|
+
expect(c.getState().error).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('Done forgets the token entirely', async () => {
|
|
102
|
+
const { c } = setup();
|
|
103
|
+
await settle(() => c.getState().phase === 'ready');
|
|
104
|
+
await c.mint();
|
|
105
|
+
c.done();
|
|
106
|
+
expect(c.getState().minted).toBeNull();
|
|
107
|
+
expect(JSON.stringify(c.getState())).not.toContain('fake-mcp-token-1');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('says when the token expires', async () => {
|
|
111
|
+
const { c } = setup();
|
|
112
|
+
await settle(() => c.getState().phase === 'ready');
|
|
113
|
+
await c.mint();
|
|
114
|
+
expect(c.getState().expiry).toMatch(/about \d+ days/);
|
|
115
|
+
});
|
|
116
|
+
});
|