@notis_ai/cli 0.2.32 → 0.2.33
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 +74 -9
- package/dist/agent-hooks/notis-agent-hook.mjs +4330 -891
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +7 -3
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +5 -3
- package/dist/base-skills/notis-spaces/references/comments.md +94 -0
- package/dist/base-skills/notis-spaces/references/context.md +20 -19
- package/dist/base-skills/notis-spaces/references/design.md +3 -2
- package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
- package/dist/base-skills/notis-spaces/references/store.md +24 -1
- package/dist/sdk/src/components/SelectionActionBar.tsx +42 -7
- package/dist/sdk/src/components/SpaceTextComments.tsx +284 -0
- package/dist/sdk/src/config.ts +3 -1
- package/dist/sdk/src/functions.ts +203 -0
- package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +7 -2
- package/dist/sdk/src/hooks/useConnection.ts +102 -0
- package/dist/sdk/src/hooks/useFunction.ts +42 -0
- package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
- package/dist/sdk/src/index.ts +15 -4
- package/dist/sdk/src/runtime.ts +16 -1
- package/dist/sdk/src/space.ts +333 -33
- package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
- package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
- package/dist/skill-sync/index.js +239 -30
- package/dist/skill-sync-worker.mjs +453 -124
- package/dist/space-harness/host.js +213 -92
- package/dist/space-sdk/dist/chunk-4GWS2IFO.js +3 -0
- package/dist/space-sdk/dist/index.js +3 -3
- package/dist/space-sdk/dist/ui.js +8 -7
- package/dist/space-sdk/src/config.ts +3 -1
- package/dist/space-sdk/src/functions.ts +203 -0
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +2 -0
- package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
- package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
- package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
- package/dist/space-sdk/src/index.d.ts +10 -4
- package/dist/space-sdk/src/runtime.d.ts +14 -1
- package/dist/space-sdk/src/space.ts +333 -33
- package/dist/space-sdk/src/tailwind-candidates.d.ts +185 -152
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +7 -4
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +10 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +55 -88
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
- package/dist/space-sdk/src/ui/comments/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +27 -5
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +64 -74
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
- package/dist/space-sdk/src/ui/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
- package/dist/view-renderer/dist/host.js +280 -159
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
- package/skills/notis-spaces/cli.md +3 -3
- package/src/cli.js +2 -1
- package/src/command-specs/index.js +3 -0
- package/src/command-specs/repository-secrets.js +171 -0
- package/src/command-specs/spaces.js +3 -3
- package/src/runtime/agent-credential.js +175 -0
- package/src/runtime/agent-identity.js +92 -15
- package/src/runtime/app-platform.js +8 -0
- package/src/runtime/auth-recovery.js +14 -0
- package/src/runtime/profiles.js +15 -0
- package/src/runtime/skill-sync/index.ts +3 -2
- package/src/runtime/skill-sync/symlink-manager.ts +354 -35
- package/src/runtime/skill-sync/types.ts +10 -1
- package/src/runtime/space-functions.js +211 -0
- package/src/runtime/space-platform.js +12 -3
- package/src/runtime/space-source.js +116 -13
- package/src/runtime/space-test-server.js +22 -4
- package/src/runtime/space-verification.js +3 -1
- package/src/runtime/transport.js +15 -0
- package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
- package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
- package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
4
4
|
import { useQuery } from './useQuery';
|
|
5
5
|
import { useNotisRuntime } from '../provider';
|
|
6
6
|
import { pick, w, type Words } from '../words/types';
|
|
@@ -13,11 +13,8 @@ export const AGENT_QUEUE_WORDS = Object.freeze({
|
|
|
13
13
|
idle: w('Idle', 'Inactif'),
|
|
14
14
|
queued: w('Queued', 'En file d’attente'),
|
|
15
15
|
working: w('Working', 'En cours'),
|
|
16
|
-
waiting: w('Waiting for you', 'Attend ta réponse'),
|
|
17
16
|
failed: w('Failed', 'Échec'),
|
|
18
17
|
done: w('Done', 'Terminé'),
|
|
19
|
-
approvalRequired: w('Allow this agent to answer your comments', 'Autorise cet agent à répondre à tes commentaires'),
|
|
20
|
-
approve: w('Allow', 'Autoriser'),
|
|
21
18
|
openThread: w('Open the conversation', 'Ouvrir la conversation'),
|
|
22
19
|
unavailable: w('Agents are not available here', 'Les agents ne sont pas disponibles ici'),
|
|
23
20
|
} satisfies Record<string, Words>);
|
|
@@ -28,19 +25,12 @@ export interface UseAgentQueueResult {
|
|
|
28
25
|
label: string;
|
|
29
26
|
/** The thread the agent works in for this scope; null until it first woke. */
|
|
30
27
|
threadId: string | null;
|
|
31
|
-
/** Items waiting in the quiet window
|
|
28
|
+
/** Items waiting in the quiet window. */
|
|
32
29
|
pending: number;
|
|
33
|
-
/** True until the viewer allows this version's agents; offer `approve()`. */
|
|
34
|
-
approvalRequired: boolean;
|
|
35
|
-
/** Ask the viewer's permission for this Space version's agents. Held comments then wake their thread. */
|
|
36
|
-
approve: () => Promise<boolean>;
|
|
37
30
|
/** Open the agent's thread in the side chat. Resolves false when there is none or the host has no side chat. */
|
|
38
31
|
openThread: () => Promise<boolean>;
|
|
39
32
|
/** The link label in the viewer's language. */
|
|
40
33
|
openLabel: string;
|
|
41
|
-
/** Why to allow (`approvalRequired`) and the Allow button, in the viewer's language. */
|
|
42
|
-
approvalLabel: string;
|
|
43
|
-
approveLabel: string;
|
|
44
34
|
loading: boolean;
|
|
45
35
|
error: Error | null;
|
|
46
36
|
/** False on hosts without agents (Sites, links, the dev harness). */
|
|
@@ -48,7 +38,7 @@ export interface UseAgentQueueResult {
|
|
|
48
38
|
refresh: () => Promise<Error | null>;
|
|
49
39
|
}
|
|
50
40
|
|
|
51
|
-
const IDLE: SpaceAgentQueue = { status: 'idle', thread_id: null, pending: 0,
|
|
41
|
+
const IDLE: SpaceAgentQueue = { status: 'idle', thread_id: null, pending: 0, updated_at: null };
|
|
52
42
|
const ACTIVE_POLL_MS = 4_000;
|
|
53
43
|
const IDLE_POLL_MS = 15_000;
|
|
54
44
|
|
|
@@ -58,14 +48,13 @@ function visible(): boolean {
|
|
|
58
48
|
|
|
59
49
|
/**
|
|
60
50
|
* One declared agent's latest wake-up for the signed-in viewer: Queued (in the 20 second quiet window),
|
|
61
|
-
* Working,
|
|
51
|
+
* Working, Failed or Done, with a link to its thread. A comment wakes its agent with no approval first.
|
|
62
52
|
*
|
|
63
53
|
* ```tsx
|
|
64
54
|
* const queue = useAgentQueue('editor', deckKey);
|
|
65
55
|
* return (
|
|
66
56
|
* <span>
|
|
67
57
|
* {queue.label}
|
|
68
|
-
* {queue.approvalRequired ? <Button onClick={() => void queue.approve()}>{queue.approveLabel}</Button> : null}
|
|
69
58
|
* {queue.threadId ? <Button onClick={() => void queue.openThread()}>{queue.openLabel}</Button> : null}
|
|
70
59
|
* </span>
|
|
71
60
|
* );
|
|
@@ -83,40 +72,40 @@ export function useAgentQueue(agentId: string, scope?: string | null): UseAgentQ
|
|
|
83
72
|
const query = useQuery<SpaceAgentQueue>(['agent-queue', agentId, scopeKey], async () => {
|
|
84
73
|
if (!transport) return IDLE;
|
|
85
74
|
const status = await transport.agentStatus(agentId, scopeKey ?? undefined);
|
|
86
|
-
return status.queue ? { ...IDLE, ...status.queue } :
|
|
75
|
+
return status.queue ? { ...IDLE, ...status.queue } : IDLE;
|
|
87
76
|
}, { readOnly: true, enabled: Boolean(transport) && Boolean(agentId), staleTimeMs: 2_000 });
|
|
88
77
|
const queue = query.data ?? IDLE;
|
|
89
78
|
const active = queue.status === 'queued' || queue.status === 'working' || queue.pending > 0;
|
|
90
79
|
const refetch = query.refetch;
|
|
80
|
+
// A read still on its way is never replaced by the next tick: a refetch drops the read in flight, so a status read
|
|
81
|
+
// slower than the 4 second tick (a busy account) never landed and the label kept its first answer for good.
|
|
82
|
+
const fetching = useRef(false);
|
|
83
|
+
fetching.current = query.isFetching;
|
|
91
84
|
// An interval, not a timeout keyed on the answer: a run reads the same "working" for minutes, and a
|
|
92
85
|
// timeout that waits for a changed answer stopped after one read and left "Working" on screen. While
|
|
93
86
|
// idle it still reads now and then, so a comment (yours or someone else's) shows "Queued" without a reload.
|
|
94
87
|
useEffect(() => {
|
|
95
88
|
if (!transport) return undefined;
|
|
96
|
-
|
|
89
|
+
let reading = false;
|
|
90
|
+
const timer = setInterval(() => {
|
|
91
|
+
if (!visible() || reading || fetching.current) return;
|
|
92
|
+
reading = true;
|
|
93
|
+
void refetch().finally(() => { reading = false; });
|
|
94
|
+
}, active ? ACTIVE_POLL_MS : IDLE_POLL_MS);
|
|
97
95
|
return () => clearInterval(timer);
|
|
98
96
|
}, [active, refetch, transport]);
|
|
99
|
-
const approve = useCallback(async () => {
|
|
100
|
-
if (!transport) return false;
|
|
101
|
-
const result = await transport.approveAgents();
|
|
102
|
-
await refetch();
|
|
103
|
-
return result.approved === true;
|
|
104
|
-
}, [refetch, transport]);
|
|
105
97
|
const openThread = useCallback(async () => {
|
|
106
98
|
if (!transport || !queue.thread_id) return false;
|
|
107
99
|
return transport.open(queue.thread_id);
|
|
108
100
|
}, [queue.thread_id, transport]);
|
|
109
101
|
return {
|
|
110
102
|
status: queue.status,
|
|
111
|
-
|
|
103
|
+
// A status this SDK has no word for (an older API's 'waiting', or none) reads as idle, never a crash.
|
|
104
|
+
label: pick(transport ? (AGENT_QUEUE_WORDS[queue.status] ?? AGENT_QUEUE_WORDS.idle) : AGENT_QUEUE_WORDS.unavailable, locale),
|
|
112
105
|
threadId: queue.thread_id,
|
|
113
106
|
pending: queue.pending,
|
|
114
|
-
approvalRequired: queue.approval_required,
|
|
115
|
-
approve,
|
|
116
107
|
openThread,
|
|
117
108
|
openLabel: pick(AGENT_QUEUE_WORDS.openThread, locale),
|
|
118
|
-
approvalLabel: pick(AGENT_QUEUE_WORDS.approvalRequired, locale),
|
|
119
|
-
approveLabel: pick(AGENT_QUEUE_WORDS.approve, locale),
|
|
120
109
|
loading: query.loading,
|
|
121
110
|
error: query.error,
|
|
122
111
|
available: Boolean(transport),
|
|
@@ -123,6 +123,8 @@ export interface CollectionInteractionController<T> {
|
|
|
123
123
|
* that removes the active item continues this way (iOS Photos), else the other way at the edge.
|
|
124
124
|
*/
|
|
125
125
|
travelDirection: () => TravelDirection;
|
|
126
|
+
/** Moves the active item one step, as J/K or the arrows do (a swipe between open items on a phone). */
|
|
127
|
+
move: (direction: CollectionNavigationDirection) => void;
|
|
126
128
|
getActionBarProps: () => Pick<MultiSelectActionBarProps, 'selectedCount' | 'actions' | 'collectionOwnerId' | 'isAvailable' | 'shortcutsEnabled' | 'onClearSelection'>;
|
|
127
129
|
|
|
128
130
|
isSelected: (id: string) => boolean;
|
|
@@ -325,7 +327,7 @@ export function useCollectionInteractions<T>(
|
|
|
325
327
|
const next = id && selectableIdsRef.current.includes(id) ? id : null;
|
|
326
328
|
if (activeIdRef.current === next) return;
|
|
327
329
|
// A click or focus further up or down sets the way; keys set it themselves (moveActive), a wrap included.
|
|
328
|
-
const travel = reason === 'items-changed' ? null : travelBetween(selectableIdsRef.current, activeIdRef.current, next);
|
|
330
|
+
const travel = reason === 'items-changed' || reason === 'navigate' ? null : travelBetween(selectableIdsRef.current, activeIdRef.current, next);
|
|
329
331
|
if (travel) travelRef.current = travel;
|
|
330
332
|
activeIdRef.current = next;
|
|
331
333
|
if (controlledActiveId === undefined) setUncontrolledActiveId(next);
|
|
@@ -515,8 +517,9 @@ export function useCollectionInteractions<T>(
|
|
|
515
517
|
keyboardRangeBaseRef.current = new Set();
|
|
516
518
|
setAnchor(next, 'navigate');
|
|
517
519
|
}
|
|
518
|
-
|
|
520
|
+
// Set before the change is reported, so the page reads the way of this very move (a wrap included).
|
|
519
521
|
travelRef.current = forward ? 'next' : 'previous';
|
|
522
|
+
setActive(next, extend ? 'range' : 'navigate');
|
|
520
523
|
const nextId = next;
|
|
521
524
|
requestAnimationFrame(() => focusItem(nextId));
|
|
522
525
|
}, [focusItem, replaceRange, setActive, setAnchor]);
|
|
@@ -689,6 +692,7 @@ export function useCollectionInteractions<T>(
|
|
|
689
692
|
|
|
690
693
|
const getSelectedItems = useCallback(() => getItemsForIds(selectedIdsRef.current), [getItemsForIds]);
|
|
691
694
|
const travelDirection = useCallback(() => travelRef.current, []);
|
|
695
|
+
const move = useCallback((direction: CollectionNavigationDirection) => moveActive(direction), [moveActive]);
|
|
692
696
|
const isSelected = useCallback((id: string) => selectedIds.has(id), [selectedIds]);
|
|
693
697
|
|
|
694
698
|
const actionContext = useMemo<CollectionActionContext<T>>(() => ({
|
|
@@ -757,6 +761,7 @@ export function useCollectionInteractions<T>(
|
|
|
757
761
|
dragRect,
|
|
758
762
|
actions: resolvedActions,
|
|
759
763
|
travelDirection,
|
|
764
|
+
move,
|
|
760
765
|
getActionBarProps,
|
|
761
766
|
isSelected,
|
|
762
767
|
getSelectedItems,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from 'react';
|
|
4
|
+
import { useQuery } from './useQuery';
|
|
5
|
+
import { useNotisRuntime } from '../provider';
|
|
6
|
+
import { queryKey } from '../queryCache';
|
|
7
|
+
import { SPACE_TOOLKIT_SLUG, spaceQueryKey, type SpaceConnection } from '../space';
|
|
8
|
+
import type { NotisRuntime } from '../runtime';
|
|
9
|
+
|
|
10
|
+
/** Cache key of one toolkit's read; every mounted `useConnection(toolkit)` reads again after a connect. */
|
|
11
|
+
export function connectionQueryKey(toolkit: string) {
|
|
12
|
+
return ['connection', toolkit] as const;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Marks a toolkit's read stale in the host cache, so every mounted `useConnection` of it reads again. */
|
|
16
|
+
export function invalidateConnection(runtime: NotisRuntime | null, toolkit: string): void {
|
|
17
|
+
try {
|
|
18
|
+
runtime?.queryClient?.invalidate(queryKey(spaceQueryKey(runtime, connectionQueryKey(toolkit))));
|
|
19
|
+
} catch {
|
|
20
|
+
// A host without a Space access context has no shared cache to refresh.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UseConnectionResult {
|
|
25
|
+
/** False where the host cannot answer (Sites, shared links, verification, previews offline, older hosts). */
|
|
26
|
+
available: boolean;
|
|
27
|
+
/** The viewer's own account in this app works now. */
|
|
28
|
+
connected: boolean;
|
|
29
|
+
/** The GitHub login for GitHub, else the name the person gave the account, else null. */
|
|
30
|
+
account: string | null;
|
|
31
|
+
/** The newest account's state (`ACTIVE`, `EXPIRED`, `FAILED`...), null when there is none or while loading. */
|
|
32
|
+
status: string | null;
|
|
33
|
+
loading: boolean;
|
|
34
|
+
/** The connect window is open and the host is waiting for the account to work. */
|
|
35
|
+
connecting: boolean;
|
|
36
|
+
error: Error | null;
|
|
37
|
+
/**
|
|
38
|
+
* Opens the Portal's connect flow for this app (a sign-in window on the web, the browser in Desktop). Call it from
|
|
39
|
+
* the person's own click: the host refuses a call no click started. Resolves true once the account works, false
|
|
40
|
+
* when the person closed the window or it timed out, and rejects with a message to show when the host refused.
|
|
41
|
+
*/
|
|
42
|
+
connect: () => Promise<boolean>;
|
|
43
|
+
/** Read again. */
|
|
44
|
+
refresh: () => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const unavailable = (toolkit: string): SpaceConnection =>
|
|
48
|
+
({ toolkit, available: false, connected: false, account: null, status: null });
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The signed-in viewer's own account in one connected app, and a button's way to connect it.
|
|
52
|
+
*
|
|
53
|
+
* ```tsx
|
|
54
|
+
* const github = useConnection('github');
|
|
55
|
+
* if (!github.available) return <OpenInNotis />;
|
|
56
|
+
* return github.connected
|
|
57
|
+
* ? <p>GitHub: {github.account}</p>
|
|
58
|
+
* : <Button onClick={() => github.connect()} disabled={github.connecting}>Connect GitHub</Button>;
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Needs no declaration: it reads only the viewer's own account and never a credential. On a Site, a shared link, in
|
|
62
|
+
* verification and in the vite preview it answers `available: false`; keep a fallback (a link to Integrations).
|
|
63
|
+
*/
|
|
64
|
+
export function useConnection(toolkit: string): UseConnectionResult {
|
|
65
|
+
const runtime = useNotisRuntime();
|
|
66
|
+
const slug = typeof toolkit === 'string' ? toolkit.trim().toLowerCase() : '';
|
|
67
|
+
const valid = SPACE_TOOLKIT_SLUG.test(slug);
|
|
68
|
+
const transport = valid ? runtime?.spaceConnections : undefined;
|
|
69
|
+
const [connecting, setConnecting] = useState(false);
|
|
70
|
+
const query = useQuery<SpaceConnection>(connectionQueryKey(slug), async () => (
|
|
71
|
+
transport ? transport.read(slug) : unavailable(slug)
|
|
72
|
+
), { readOnly: true, staleTimeMs: 30_000 });
|
|
73
|
+
|
|
74
|
+
const connect = useCallback(async () => {
|
|
75
|
+
if (!transport) throw new Error('Connect this app from the Space in Notis.');
|
|
76
|
+
setConnecting(true);
|
|
77
|
+
try {
|
|
78
|
+
// Called before anything awaits: the host opens its window inside the person's click.
|
|
79
|
+
const after = await transport.connect(slug);
|
|
80
|
+
invalidateConnection(runtime, slug);
|
|
81
|
+
await query.refetch();
|
|
82
|
+
return after.connected;
|
|
83
|
+
} finally {
|
|
84
|
+
setConnecting(false);
|
|
85
|
+
}
|
|
86
|
+
}, [query.refetch, runtime, slug, transport]);
|
|
87
|
+
|
|
88
|
+
const refresh = useCallback(async () => { await query.refetch(); }, [query.refetch]);
|
|
89
|
+
const data = query.data ?? (!transport ? unavailable(slug) : null);
|
|
90
|
+
return {
|
|
91
|
+
// A read that failed keeps the hook available: `error` says why, and `refresh` or `connect` still work.
|
|
92
|
+
available: Boolean(transport) && data?.available !== false,
|
|
93
|
+
connected: data?.connected === true,
|
|
94
|
+
account: data?.account ?? null,
|
|
95
|
+
status: data?.status ?? null,
|
|
96
|
+
loading: query.loading,
|
|
97
|
+
connecting,
|
|
98
|
+
error: query.error,
|
|
99
|
+
connect,
|
|
100
|
+
refresh,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from 'react';
|
|
4
|
+
import { useNotisRuntime } from '../provider';
|
|
5
|
+
import { useQuery, type UseQueryOptions, type UseQueryResult } from './useQuery';
|
|
6
|
+
import type { SpaceFunctionCallOptions } from '../functions';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Call one of this Space's functions exposed to its views (`expose: ['page']`). The handler runs on Notis's side;
|
|
10
|
+
* the page only gets its result.
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const settle = useFunction<{ thread: string }, { settled: boolean }>('settle_thread');
|
|
14
|
+
* <Button disabled={settle.loading} onClick={() => void settle.call({ thread: id })}>Settle</Button>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function useFunction<TInput extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>(name: string): {
|
|
18
|
+
call: (input: TInput, options?: SpaceFunctionCallOptions) => Promise<TResult>; loading: boolean; error: Error | null;
|
|
19
|
+
/** False on hosts that cannot run functions, or when this view may not call this one. */
|
|
20
|
+
available: boolean;
|
|
21
|
+
} {
|
|
22
|
+
const runtime = useNotisRuntime();
|
|
23
|
+
const [pending, setPending] = useState(0);
|
|
24
|
+
const [error, setError] = useState<Error | null>(null);
|
|
25
|
+
const available = runtime?.resource?.kind === 'space' && Boolean(runtime.callFunction)
|
|
26
|
+
&& Boolean(runtime.space?.functions && Object.hasOwn(runtime.space.functions, name));
|
|
27
|
+
const call = useCallback(async (input: TInput, options?: SpaceFunctionCallOptions) => {
|
|
28
|
+
if (runtime?.resource?.kind !== 'space' || !runtime.callFunction) throw new Error('A Space function runtime is required.');
|
|
29
|
+
setPending((value) => value + 1); setError(null);
|
|
30
|
+
try { return await runtime.callFunction<TResult>(name, input, options); }
|
|
31
|
+
catch (cause) { const failure = cause instanceof Error ? cause : new Error(String(cause)); setError(failure); throw failure; }
|
|
32
|
+
finally { setPending((value) => value - 1); }
|
|
33
|
+
}, [runtime, name]);
|
|
34
|
+
return { call, loading: pending > 0, error, available };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A `read` function as a cached query: it runs again when `input` changes. */
|
|
38
|
+
export function useFunctionQuery<TResult = unknown>(name: string, input: Record<string, unknown>,
|
|
39
|
+
options: UseQueryOptions = { readOnly: true }): UseQueryResult<TResult> {
|
|
40
|
+
const { call } = useFunction<Record<string, unknown>, TResult>(name);
|
|
41
|
+
return useQuery(['function', name, input], () => call(input), options);
|
|
42
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { useNotisRuntime } from '../provider';
|
|
5
|
+
import { settledNavigation } from './useNotisNavigation';
|
|
6
|
+
|
|
7
|
+
/** A Settings place a Space may open. Only the Cloud Computer's repository secrets for now. */
|
|
8
|
+
export interface NotisSettingsTarget {
|
|
9
|
+
page: 'cloud-computer';
|
|
10
|
+
section: 'repository-secrets';
|
|
11
|
+
/**
|
|
12
|
+
* The repository the form is prefilled with: its short name (`naturalisation-switzerland`) or `owner/name`, whose
|
|
13
|
+
* short name is kept. Repository secrets are keyed by the short name, in lower case.
|
|
14
|
+
*/
|
|
15
|
+
repository?: string;
|
|
16
|
+
/** Open the Add env file (`env_file`) or Add variable (`variable`) form. Without it the section is only shown. */
|
|
17
|
+
add?: 'env_file' | 'variable';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UseNotisSettingsResult {
|
|
21
|
+
/** False on a Site, a link, a release preview, a page framed inside another, verify and the vite preview: offer your
|
|
22
|
+
* own fallback there. */
|
|
23
|
+
available: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Opens Settings on the target, above the Space. Resolves once the host has taken it; rejects on a host that cannot
|
|
26
|
+
* open Settings, on a target it does not know, or when the view is no longer the one on screen. Values are never
|
|
27
|
+
* prefilled: the person types or chooses them in Settings.
|
|
28
|
+
*/
|
|
29
|
+
openSettings: (target: NotisSettingsTarget) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type NotisSettingsNavigation = {
|
|
33
|
+
kind: 'settings'; page: 'cloud-computer'; section: 'repository-secrets';
|
|
34
|
+
repository?: string; add?: 'env_file' | 'variable';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The repository-secrets store's rule for a repository (server/lib/database_schema.py SECRET_REPOSITORY_SLUG). */
|
|
38
|
+
const REPOSITORY = /^[a-z0-9](?:[a-z0-9._-]{0,62}[a-z0-9])?$/;
|
|
39
|
+
/** A GitHub owner: letters, digits and dashes. */
|
|
40
|
+
const OWNER = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/;
|
|
41
|
+
|
|
42
|
+
/** The short name a repository is kept under (`owner/name` keeps `name`, lower case), or null when it is not one. */
|
|
43
|
+
export function settingsRepositoryName(value: unknown): string | null {
|
|
44
|
+
if (typeof value !== 'string') return null;
|
|
45
|
+
const parts = value.trim().split('/');
|
|
46
|
+
if (parts.length > 2 || (parts.length === 2 && !OWNER.test(parts[0]))) return null;
|
|
47
|
+
const name = parts[parts.length - 1].toLowerCase();
|
|
48
|
+
return REPOSITORY.test(name) ? name : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const TARGET_KEYS = ['page', 'section', 'repository', 'add'];
|
|
52
|
+
|
|
53
|
+
/** The payload `openSettings` sends the host, or an Error naming what is wrong. Hosts check it again with this. */
|
|
54
|
+
export function settingsNavigation(target: unknown): NotisSettingsNavigation | Error {
|
|
55
|
+
if (!target || typeof target !== 'object' || Array.isArray(target)) return new Error('Name the Settings page to open.');
|
|
56
|
+
const fields = target as Record<string, unknown>;
|
|
57
|
+
if (Object.keys(fields).some(key => fields[key] !== undefined && !TARGET_KEYS.includes(key))) {
|
|
58
|
+
return new Error('openSettings takes page, section, repository and add.');
|
|
59
|
+
}
|
|
60
|
+
if (fields.page !== 'cloud-computer' || fields.section !== 'repository-secrets') {
|
|
61
|
+
return new Error("Spaces open Settings on { page: 'cloud-computer', section: 'repository-secrets' }.");
|
|
62
|
+
}
|
|
63
|
+
if (fields.add !== undefined && fields.add !== 'env_file' && fields.add !== 'variable') {
|
|
64
|
+
return new Error("add is 'env_file' or 'variable'.");
|
|
65
|
+
}
|
|
66
|
+
let repository: string | undefined;
|
|
67
|
+
if (fields.repository !== undefined) {
|
|
68
|
+
const name = settingsRepositoryName(fields.repository);
|
|
69
|
+
if (!name) return new Error('Name the repository by its short name or owner/name.');
|
|
70
|
+
repository = name;
|
|
71
|
+
}
|
|
72
|
+
return { kind: 'settings', page: 'cloud-computer', section: 'repository-secrets',
|
|
73
|
+
...(repository ? { repository } : {}), ...(fields.add ? { add: fields.add as 'env_file' | 'variable' } : {}) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Opens the host's Settings from a Space view, such as the repository secrets form for one repository.
|
|
78
|
+
*
|
|
79
|
+
* ```tsx
|
|
80
|
+
* const settings = useNotisSettings();
|
|
81
|
+
* <button disabled={!settings.available}
|
|
82
|
+
* onClick={() => settings.openSettings({ page: 'cloud-computer', section: 'repository-secrets',
|
|
83
|
+
* repository: 'naturalisation-switzerland', add: 'env_file' })}>Add .env file</button>
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* The same place has a plain address a Space or an email can link to:
|
|
87
|
+
* `/manage?settings=cloud&settings_section=repository-secrets&settings_repository=<name>&settings_add=env_file`.
|
|
88
|
+
*/
|
|
89
|
+
export function useNotisSettings(): UseNotisSettingsResult {
|
|
90
|
+
const runtime = useNotisRuntime();
|
|
91
|
+
const available = Boolean(runtime?.settingsAvailable && runtime.navigate);
|
|
92
|
+
const openSettings = useCallback(async (target: NotisSettingsTarget) => {
|
|
93
|
+
if (!runtime?.settingsAvailable || !runtime.navigate) {
|
|
94
|
+
throw new Error('Settings open only from a Space page in Notis, signed in.');
|
|
95
|
+
}
|
|
96
|
+
const payload = settingsNavigation(target);
|
|
97
|
+
if (payload instanceof Error) throw payload;
|
|
98
|
+
await settledNavigation(() => runtime.navigate!(payload));
|
|
99
|
+
}, [runtime]);
|
|
100
|
+
return { available, openSettings };
|
|
101
|
+
}
|
package/dist/sdk/src/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type { SpaceViewParam, SpaceViewParamType, SpaceViewFilter, SpaceShows, S
|
|
|
28
28
|
export { SPACE_VIEWER_READ_OPERATIONS } from './space';
|
|
29
29
|
export { SPACE_CLOUD_COMPUTER_OPERATIONS, spaceCloudComputerAllows } from './space';
|
|
30
30
|
export { spaceCloudComputerAccess } from './space';
|
|
31
|
-
export type { SpaceCloudComputerLevel, SpaceCloudComputerOperation, SpaceCloudComputerStatus, SpaceCloudComputerRelease, SpaceCloudComputerRunInput,
|
|
31
|
+
export type { SpaceCloudComputerLevel, SpaceCloudComputerOperation, SpaceCloudComputerStatus, SpaceCloudComputerRelease, SpaceCloudComputerCopy, SpaceCloudComputerRunInput,
|
|
32
32
|
SpaceCloudComputerRunResult, SpaceCloudComputerUploadInput, SpaceCloudComputerUploadResult, SpaceCloudComputerTransport,
|
|
33
33
|
SpaceCloudComputerDeclaration, SpaceCloudComputerService, SpaceCloudComputerJobOperation, SpaceCloudComputerJobInput,
|
|
34
34
|
SpaceCloudComputerJobStatus, SpaceCloudComputerJobLogs, SpaceCloudComputerJobResult, SpaceCloudComputerLeaseInput,
|
|
@@ -41,7 +41,9 @@ export type { SpaceViewerReadFamily, SpaceViewerReadOperation, SpaceViewerReadIn
|
|
|
41
41
|
export type { SpaceAgentDeclaration, SpaceItemThread, SpaceAgentQueue, SpaceAgentsStatus, SpaceThreadsTransport,
|
|
42
42
|
SpaceThreadItemText, SpaceThreadItemCondition, SpaceThreadItemState, SpaceThreadItemConfirm, SpaceThreadItemAction,
|
|
43
43
|
SpaceThreadItemKind, SpaceThreadItem, SpaceThreadItemRun, SpaceThreadItemTransport,
|
|
44
|
-
SpaceCommentSource, SpaceCommentsTransport, SpaceCommentViewer, SpaceCommentThreadRef, SpaceCommentThreadPick
|
|
44
|
+
SpaceCommentSource, SpaceCommentsTransport, SpaceCommentViewer, SpaceCommentThreadRef, SpaceCommentThreadPick,
|
|
45
|
+
SpaceCommentAnchor, SpaceCommentAttachment, SpaceCommentChange, SpaceCommentFile, SpaceCommentInsert, SpaceCommentMode,
|
|
46
|
+
SpaceCommentNeeds, SpaceCommentPage, SpaceCommentPageKey, SpaceCommentReply, SpaceCommentRow, SpaceCommentStatus } from './space';
|
|
45
47
|
export { SpaceActionError, SpaceNavigationCancelled, isSpaceNavigationCancelled } from './space';
|
|
46
48
|
export { spaceAudience, spaceMarksEditorsOnly, publicSpaceDescriptor, withoutEditorColumns } from './space';
|
|
47
49
|
export type { SpaceAudience, SpaceEditorsOnly, SpaceResourceColumns, EditorOnlyColumns, AudienceRow } from './space';
|
|
@@ -76,9 +78,18 @@ export { useHandover } from './hooks/useHandover';
|
|
|
76
78
|
export type { UseHandoverResult } from './hooks/useHandover';
|
|
77
79
|
export { useCloudComputer } from './hooks/useCloudComputer';
|
|
78
80
|
export type { UseCloudComputerResult } from './hooks/useCloudComputer';
|
|
81
|
+
export { useConnection } from './hooks/useConnection';
|
|
82
|
+
export type { UseConnectionResult } from './hooks/useConnection';
|
|
83
|
+
export type { SpaceConnection, SpaceConnectionsTransport } from './space';
|
|
79
84
|
export { useItemThread } from './hooks/useItemThread';
|
|
80
85
|
export type { UseItemThreadResult } from './hooks/useItemThread';
|
|
81
86
|
export { useThreadItem } from './hooks/useThreadItem';
|
|
87
|
+
export { useFunction, useFunctionQuery } from './hooks/useFunction';
|
|
88
|
+
export { threadHookInput, threadSettleInput, commentOptionInput } from './functions';
|
|
89
|
+
export type { SpaceFunctionDeclaration, SpaceFunctionHandler, SpaceFunctionContext, SpaceFunctionKind, SpaceFunctionExposure,
|
|
90
|
+
SpaceFunctionRole, SpaceFunctionUses, SpaceThreadOperation, SpaceThreadHookEvent, SpaceThreadHookInput, SpaceThreadSettleInput,
|
|
91
|
+
SpaceCommentOption, SpaceCommentOptionInput, SpaceFunctionThread, SpaceFunctionThreadItem, SpaceFunctionCloudComputer, SpaceFunctionDescriptor,
|
|
92
|
+
SpaceFunctionCallOptions } from './functions';
|
|
82
93
|
export type { UseThreadItemResult } from './hooks/useThreadItem';
|
|
83
94
|
export { useAgentQueue, AGENT_QUEUE_WORDS } from './hooks/useAgentQueue';
|
|
84
95
|
export type { UseAgentQueueResult, AgentQueueStatus } from './hooks/useAgentQueue';
|
|
@@ -90,6 +101,8 @@ export { useCloudComputerJob } from './hooks/useCloudComputerJob';
|
|
|
90
101
|
export type { UseCloudComputerJobOptions, UseCloudComputerJobResult } from './hooks/useCloudComputerJob';
|
|
91
102
|
export { CLOUD_COMPUTER_WORDS, cloudComputerPriceWords, formatHourlyPrice } from './cloudComputerWords';
|
|
92
103
|
export { useNotisNavigation } from './hooks/useNotisNavigation';
|
|
104
|
+
export { useNotisSettings } from './hooks/useNotisSettings';
|
|
105
|
+
export type { NotisSettingsTarget, UseNotisSettingsResult } from './hooks/useNotisSettings';
|
|
93
106
|
export { useTopBarSearch } from './hooks/useTopBarSearch';
|
|
94
107
|
export { useTopBarTitleLeaf } from './hooks/useTopBarTitleLeaf';
|
|
95
108
|
export { useBackend } from './hooks/useBackend';
|
|
@@ -234,7 +247,5 @@ export { isInteractionElementVisible } from './interactions/visibility';
|
|
|
234
247
|
|
|
235
248
|
export type { AgentContextContent, AgentContextItem, ContextAttachment } from './agentContext';
|
|
236
249
|
export { useAgentContext } from './hooks/useAgentContext';
|
|
237
|
-
export { NotisCommentBoundary, NotisCommentBox } from './components/NotisCommentBoundary';
|
|
238
|
-
export type { NotisCommentBoundaryProps, NotisCommentBoxProps } from './components/NotisCommentBoundary';
|
|
239
250
|
export { VIEW_PERIODS, isViewDate, isViewPeriod, resolveViewPeriod } from './viewPeriod';
|
|
240
251
|
export { journalViewParams, tasksViewParams, tasksViewFilter } from './standardViewParams';
|
package/dist/sdk/src/runtime.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { AgentContextContent, AgentContextItem, AgentContextSource } from '
|
|
|
11
11
|
import type { ComponentType, ReactNode } from 'react';
|
|
12
12
|
import type { NotisQueryClient } from './queryCache';
|
|
13
13
|
import type { NotisSpaceSkeleton } from './skeleton';
|
|
14
|
-
import type { SpaceRuntimeDescriptor, SpaceActionOptions, SpaceDocumentBodyRequest, SpaceDocumentBodyResult, SpaceViewerReadOperation, SpaceShownOptions, SpaceCloudComputerTransport, SpaceFilesTransport, SpaceThreadsTransport, SpaceThreadItemTransport, SpaceCommentsTransport } from './space';
|
|
14
|
+
import type { SpaceRuntimeDescriptor, SpaceActionOptions, SpaceDocumentBodyRequest, SpaceDocumentBodyResult, SpaceViewerReadOperation, SpaceShownOptions, SpaceCloudComputerTransport, SpaceConnectionsTransport, SpaceFilesTransport, SpaceThreadsTransport, SpaceThreadItemTransport, SpaceCommentsTransport } from './space';
|
|
15
15
|
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
17
|
// Database types
|
|
@@ -596,6 +596,9 @@ export interface RuntimeResource {
|
|
|
596
596
|
export interface NotisRuntime {
|
|
597
597
|
space?: SpaceRuntimeDescriptor;
|
|
598
598
|
callAction?<TResult = unknown>(actionId: string, inputs?: Record<string, unknown>, options?: SpaceActionOptions): Promise<TResult>;
|
|
599
|
+
/** Space-only: run one of the Space's functions exposed to its views. Absent on hosts that predate functions. */
|
|
600
|
+
callFunction?<TResult = unknown>(name: string, input?: Record<string, unknown>,
|
|
601
|
+
options?: import('./functions').SpaceFunctionCallOptions): Promise<TResult>;
|
|
599
602
|
documentBody?(request: SpaceDocumentBodyRequest): Promise<SpaceDocumentBodyResult>;
|
|
600
603
|
/**
|
|
601
604
|
* Space-only declared viewer read (`viewerReads`): what the signed-in viewer can open,
|
|
@@ -619,6 +622,11 @@ export interface NotisRuntime {
|
|
|
619
622
|
* viewer allows it. Absent on Sites, links, verification harnesses and older hosts.
|
|
620
623
|
*/
|
|
621
624
|
spaceCloudComputer?: SpaceCloudComputerTransport;
|
|
625
|
+
/**
|
|
626
|
+
* Space-only connected apps (`useConnection`): the signed-in viewer's own account in one app, and the Portal's
|
|
627
|
+
* connect flow from the person's click. Absent on Sites, links, verification harnesses and older hosts.
|
|
628
|
+
*/
|
|
629
|
+
spaceConnections?: SpaceConnectionsTransport;
|
|
622
630
|
/**
|
|
623
631
|
* Space-only files attached from a view to a database's files column (comment pictures): the signed-in Editor's
|
|
624
632
|
* own upload into Notis's private EU storage. Absent on Sites, previews, verification harnesses and older hosts.
|
|
@@ -705,6 +713,13 @@ export interface NotisRuntime {
|
|
|
705
713
|
*/
|
|
706
714
|
navigate?: (payload: { kind: string; [key: string]: unknown }) => NotisNavigationAnswer | Promise<NotisNavigationAnswer>;
|
|
707
715
|
|
|
716
|
+
/**
|
|
717
|
+
* True when this host opens its own Settings from `navigate({ kind: 'settings', ... })` (`useNotisSettings()`):
|
|
718
|
+
* a signed-in viewer's Space page in the Portal. Absent on a Site, a link, a release preview, verify and the vite
|
|
719
|
+
* preview.
|
|
720
|
+
*/
|
|
721
|
+
settingsAvailable?: boolean;
|
|
722
|
+
|
|
708
723
|
registerTopBarSearch?: (
|
|
709
724
|
config:
|
|
710
725
|
| {
|