@stigmer/react 3.1.8 → 3.1.9
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/environment/EnvironmentPicker.d.ts +17 -1
- package/environment/EnvironmentPicker.d.ts.map +1 -1
- package/environment/EnvironmentPicker.js +3 -2
- package/environment/EnvironmentPicker.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/sharing/ShareAgentDialog.d.ts +10 -8
- package/sharing/ShareAgentDialog.d.ts.map +1 -1
- package/sharing/ShareAgentDialog.js +139 -54
- package/sharing/ShareAgentDialog.js.map +1 -1
- package/sharing/SharedAgentChat.d.ts +1 -1
- package/sharing/SharedAgentChat.d.ts.map +1 -1
- package/sharing/index.d.ts +4 -2
- package/sharing/index.d.ts.map +1 -1
- package/sharing/index.js +2 -1
- package/sharing/index.js.map +1 -1
- package/sharing/useAgentShare.d.ts +43 -0
- package/sharing/useAgentShare.d.ts.map +1 -0
- package/sharing/useAgentShare.js +54 -0
- package/sharing/useAgentShare.js.map +1 -0
- package/sharing/useRotateShareLink.d.ts +22 -19
- package/sharing/useRotateShareLink.d.ts.map +1 -1
- package/sharing/useRotateShareLink.js +22 -19
- package/sharing/useRotateShareLink.js.map +1 -1
- package/sharing/useSaveAgentShare.d.ts +105 -0
- package/sharing/useSaveAgentShare.d.ts.map +1 -0
- package/sharing/useSaveAgentShare.js +97 -0
- package/sharing/useSaveAgentShare.js.map +1 -0
- package/sharing/useShareAgent.d.ts +5 -4
- package/sharing/useShareAgent.d.ts.map +1 -1
- package/sharing/useShareAgent.js +5 -4
- package/sharing/useShareAgent.js.map +1 -1
- package/sharing/useShareToolReadiness.d.ts +29 -25
- package/sharing/useShareToolReadiness.d.ts.map +1 -1
- package/sharing/useShareToolReadiness.js +47 -51
- package/sharing/useShareToolReadiness.js.map +1 -1
- package/sharing/useSharedAgentProfile.d.ts +5 -4
- package/sharing/useSharedAgentProfile.d.ts.map +1 -1
- package/sharing/useSharedAgentProfile.js +6 -5
- package/sharing/useSharedAgentProfile.js.map +1 -1
- package/src/environment/EnvironmentPicker.tsx +23 -2
- package/src/index.ts +8 -4
- package/src/sharing/ShareAgentDialog.tsx +353 -119
- package/src/sharing/SharedAgentChat.tsx +1 -1
- package/src/sharing/__tests__/ShareAgentDialog.test.tsx +550 -369
- package/src/sharing/__tests__/useAgentShare.test.tsx +149 -0
- package/src/sharing/__tests__/useRotateShareLink.test.tsx +8 -8
- package/src/sharing/__tests__/useSaveAgentShare.test.tsx +241 -0
- package/src/sharing/__tests__/useShareAgent.test.tsx +6 -2
- package/src/sharing/__tests__/useShareToolReadiness.test.tsx +84 -47
- package/src/sharing/__tests__/useSharedAgentProfile.test.tsx +1 -1
- package/src/sharing/index.ts +9 -7
- package/src/sharing/useAgentShare.ts +91 -0
- package/src/sharing/useRotateShareLink.ts +30 -25
- package/src/sharing/useSaveAgentShare.ts +186 -0
- package/src/sharing/useShareAgent.tsx +5 -4
- package/src/sharing/useShareToolReadiness.ts +62 -60
- package/src/sharing/useSharedAgentProfile.ts +7 -6
- package/src/switch/Switch.tsx +6 -1
- package/src/switch/__tests__/Switch.test.tsx +19 -0
- package/switch/Switch.d.ts.map +1 -1
- package/switch/Switch.js +6 -1
- package/switch/Switch.js.map +1 -1
- package/sharing/useUpdateAgentSharing.d.ts +0 -86
- package/sharing/useUpdateAgentSharing.d.ts.map +0 -1
- package/sharing/useUpdateAgentSharing.js +0 -81
- package/sharing/useUpdateAgentSharing.js.map +0 -1
- package/src/sharing/__tests__/useUpdateAgentSharing.test.tsx +0 -200
- package/src/sharing/useUpdateAgentSharing.ts +0 -151
|
@@ -12,7 +12,7 @@ function createMockStigmer(overrides: {
|
|
|
12
12
|
getSharedProfileForMember?: (...args: unknown[]) => Promise<unknown>;
|
|
13
13
|
} = {}) {
|
|
14
14
|
return {
|
|
15
|
-
|
|
15
|
+
agentShare: {
|
|
16
16
|
getSharedProfile:
|
|
17
17
|
overrides.getSharedProfile ?? vi.fn().mockResolvedValue(null),
|
|
18
18
|
getSharedProfileForMember:
|
package/src/sharing/index.ts
CHANGED
|
@@ -5,17 +5,19 @@ export type {
|
|
|
5
5
|
} from "./useSharedAgentProfile.js";
|
|
6
6
|
export { SharedAgentChat } from "./SharedAgentChat.js";
|
|
7
7
|
export type { SharedAgentChatProps } from "./SharedAgentChat.js";
|
|
8
|
+
export { useAgentShare } from "./useAgentShare.js";
|
|
9
|
+
export type { UseAgentShareReturn } from "./useAgentShare.js";
|
|
8
10
|
export {
|
|
9
11
|
sharingAudienceFromProto,
|
|
10
|
-
|
|
11
|
-
} from "./
|
|
12
|
-
export { useRotateShareLink } from "./useRotateShareLink.js";
|
|
13
|
-
export type { UseRotateShareLinkReturn } from "./useRotateShareLink.js";
|
|
12
|
+
useSaveAgentShare,
|
|
13
|
+
} from "./useSaveAgentShare.js";
|
|
14
14
|
export type {
|
|
15
|
-
|
|
15
|
+
AgentShareDraft,
|
|
16
16
|
SharingAudience,
|
|
17
|
-
|
|
18
|
-
} from "./
|
|
17
|
+
UseSaveAgentShareReturn,
|
|
18
|
+
} from "./useSaveAgentShare.js";
|
|
19
|
+
export { useRotateShareLink } from "./useRotateShareLink.js";
|
|
20
|
+
export type { UseRotateShareLinkReturn } from "./useRotateShareLink.js";
|
|
19
21
|
export { ShareAgentDialog } from "./ShareAgentDialog.js";
|
|
20
22
|
export type { ShareAgentDialogProps } from "./ShareAgentDialog.js";
|
|
21
23
|
export { useShareAgent } from "./useShareAgent.js";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { create } from "@bufbuild/protobuf";
|
|
4
|
+
import type { Agent } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
5
|
+
import type { AgentShare } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/api_pb";
|
|
6
|
+
import { GetAgentSharesByAgentRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/io_pb";
|
|
7
|
+
import { useStigmer } from "../hooks.js";
|
|
8
|
+
import { useFetch } from "../internal/useFetch.js";
|
|
9
|
+
|
|
10
|
+
/** Return value of {@link useAgentShare}. */
|
|
11
|
+
export interface UseAgentShareReturn {
|
|
12
|
+
/**
|
|
13
|
+
* The agent's canonical share, or `null` while loading, on error, or
|
|
14
|
+
* when the agent has never been shared. `share === null && !isLoading
|
|
15
|
+
* && !error` means "no share exists yet" — the first save creates it.
|
|
16
|
+
*/
|
|
17
|
+
readonly share: AgentShare | null;
|
|
18
|
+
/** `true` while the initial fetch or a refetch is in flight. */
|
|
19
|
+
readonly isLoading: boolean;
|
|
20
|
+
/** `true` while a background refetch is in flight and stale data is shown. */
|
|
21
|
+
readonly isRefetching: boolean;
|
|
22
|
+
/** Error from the last failed request, or `null` when healthy. */
|
|
23
|
+
readonly error: Error | null;
|
|
24
|
+
/** Discard cached data and re-fetch the share from the server. */
|
|
25
|
+
readonly refetch: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The canonical share among an agent's shares: the one whose slug equals
|
|
30
|
+
* the agent's slug (the server's default when a share is created without
|
|
31
|
+
* an explicit slug), falling back to the first entry. The data model
|
|
32
|
+
* allows N shares per agent (decision 011 D3); the console manages the
|
|
33
|
+
* canonical one in Phase A, so extra shares created via manifests never
|
|
34
|
+
* confuse the dialog.
|
|
35
|
+
*/
|
|
36
|
+
function pickCanonicalShare(
|
|
37
|
+
shares: readonly AgentShare[],
|
|
38
|
+
agentSlug: string,
|
|
39
|
+
): AgentShare | null {
|
|
40
|
+
return (
|
|
41
|
+
shares.find((share) => share.metadata?.slug === agentSlug) ??
|
|
42
|
+
shares[0] ??
|
|
43
|
+
null
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Data hook that loads an agent's canonical {@link AgentShare} — the
|
|
49
|
+
* resource carrying the hosted-chat channel configuration (audience,
|
|
50
|
+
* allowed origins, visitor messages, tool credentials, link token).
|
|
51
|
+
*
|
|
52
|
+
* Sharing is channel configuration, not agent behavior (decision 011):
|
|
53
|
+
* it lives in its own resource, so reading the agent alone can never
|
|
54
|
+
* tell whether it is shared. This hook is how owner-side surfaces (the
|
|
55
|
+
* Share dialog) resolve that state.
|
|
56
|
+
*
|
|
57
|
+
* Pass `null` for `agent` to skip fetching (stable no-op) — useful
|
|
58
|
+
* while the agent is still loading. A resolved `null` share means the
|
|
59
|
+
* agent has never been shared; the first save creates the share.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* const { share, isLoading } = useAgentShare(agent);
|
|
64
|
+
*
|
|
65
|
+
* if (isLoading) return <Spinner />;
|
|
66
|
+
* const enabled = share?.spec?.enabled ?? false;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function useAgentShare(agent: Agent | null): UseAgentShareReturn {
|
|
70
|
+
const stigmer = useStigmer();
|
|
71
|
+
|
|
72
|
+
const agentId = agent?.metadata?.id ?? "";
|
|
73
|
+
const agentSlug = agent?.metadata?.slug ?? "";
|
|
74
|
+
|
|
75
|
+
const fetchFn = agentId
|
|
76
|
+
? async () => {
|
|
77
|
+
const result = await stigmer.agentShare.getByAgent(
|
|
78
|
+
create(GetAgentSharesByAgentRequestSchema, { agentId }),
|
|
79
|
+
);
|
|
80
|
+
return pickCanonicalShare(result.items, agentSlug);
|
|
81
|
+
}
|
|
82
|
+
: null;
|
|
83
|
+
|
|
84
|
+
const { data: share, isLoading, isRefetching, error, refetch } = useFetch(
|
|
85
|
+
fetchFn,
|
|
86
|
+
[agentId, agentSlug, stigmer],
|
|
87
|
+
null as AgentShare | null,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return { share, isLoading, isRefetching, error, refetch };
|
|
91
|
+
}
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import { useCallback, useState } from "react";
|
|
4
4
|
import { create } from "@bufbuild/protobuf";
|
|
5
|
-
import type {
|
|
6
|
-
import { RotateShareLinkInputSchema } from "@stigmer/protos/ai/stigmer/agentic/
|
|
5
|
+
import type { AgentShare } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/api_pb";
|
|
6
|
+
import { RotateShareLinkInputSchema } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/io_pb";
|
|
7
7
|
import { useStigmer } from "../hooks.js";
|
|
8
8
|
import { toError } from "../internal/toError.js";
|
|
9
9
|
|
|
10
10
|
/** Return value of {@link useRotateShareLink}. */
|
|
11
11
|
export interface UseRotateShareLinkReturn {
|
|
12
12
|
/**
|
|
13
|
-
* Rotate the
|
|
14
|
-
* Resolves with the updated
|
|
13
|
+
* Rotate the share's link token via the `rotateShareLink` RPC.
|
|
14
|
+
* Resolves with the updated share, whose `status.shareLinkToken`
|
|
15
15
|
* carries the new token for building the fresh share URL.
|
|
16
16
|
*/
|
|
17
|
-
readonly rotateShareLink: () => Promise<
|
|
17
|
+
readonly rotateShareLink: () => Promise<AgentShare | undefined>;
|
|
18
18
|
/** `true` while the RPC is in flight. */
|
|
19
19
|
readonly isPending: boolean;
|
|
20
20
|
/** The last error from the RPC, or `null`. */
|
|
@@ -22,47 +22,52 @@ export interface UseRotateShareLinkReturn {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Behavior hook that rotates
|
|
25
|
+
* Behavior hook that rotates a share's link token.
|
|
26
26
|
*
|
|
27
|
-
* Wraps the `stigmer.
|
|
28
|
-
* `can_edit`) with loading and error state management. The
|
|
29
|
-
* generates the token — there is nothing to supply — and the
|
|
30
|
-
* link stops working the moment the call resolves, including
|
|
31
|
-
* visitors mid-conversation. The token lives in
|
|
32
|
-
* (server-owned
|
|
33
|
-
*
|
|
27
|
+
* Wraps the `stigmer.agentShare.rotateShareLink()` RPC (authorized by
|
|
28
|
+
* the share's `can_edit`) with loading and error state management. The
|
|
29
|
+
* server generates the token — there is nothing to supply — and the
|
|
30
|
+
* previous link stops working the moment the call resolves, including
|
|
31
|
+
* for visitors mid-conversation. The token lives in
|
|
32
|
+
* `status.shareLinkToken` (server-owned; this RPC is its sole writer),
|
|
33
|
+
* so it is never part of a share draft and survives every apply.
|
|
34
34
|
*
|
|
35
|
-
* The hook is stateless with respect to the
|
|
36
|
-
*
|
|
37
|
-
* {@link
|
|
35
|
+
* The hook is stateless with respect to the share — adopt the returned
|
|
36
|
+
* share (or refetch) so the UI shows the new tokened link, matching the
|
|
37
|
+
* {@link useSaveAgentShare} convention.
|
|
38
38
|
*
|
|
39
|
-
* Pass `null` for `
|
|
40
|
-
*
|
|
39
|
+
* Pass `null` for `shareId` to produce a stable no-op (useful while the
|
|
40
|
+
* share is still loading, or before the agent has ever been shared —
|
|
41
|
+
* there is no token to rotate until a share exists).
|
|
41
42
|
*
|
|
42
43
|
* @example
|
|
43
44
|
* ```tsx
|
|
44
|
-
* const { rotateShareLink, isPending } = useRotateShareLink(
|
|
45
|
+
* const { rotateShareLink, isPending } = useRotateShareLink(
|
|
46
|
+
* share?.metadata?.id ?? null,
|
|
47
|
+
* );
|
|
45
48
|
*
|
|
46
49
|
* const updated = await rotateShareLink();
|
|
47
50
|
* // updated.status.shareLinkToken is the new token
|
|
48
51
|
* ```
|
|
49
52
|
*/
|
|
50
53
|
export function useRotateShareLink(
|
|
51
|
-
|
|
54
|
+
shareId: string | null,
|
|
52
55
|
): UseRotateShareLinkReturn {
|
|
53
56
|
const stigmer = useStigmer();
|
|
54
57
|
const [isPending, setIsPending] = useState(false);
|
|
55
58
|
const [error, setError] = useState<Error | null>(null);
|
|
56
59
|
|
|
57
|
-
const rotateShareLink = useCallback(async (): Promise<
|
|
58
|
-
|
|
60
|
+
const rotateShareLink = useCallback(async (): Promise<
|
|
61
|
+
AgentShare | undefined
|
|
62
|
+
> => {
|
|
63
|
+
if (!shareId) return undefined;
|
|
59
64
|
|
|
60
65
|
setIsPending(true);
|
|
61
66
|
setError(null);
|
|
62
67
|
|
|
63
68
|
try {
|
|
64
|
-
return await stigmer.
|
|
65
|
-
create(RotateShareLinkInputSchema, { resourceId:
|
|
69
|
+
return await stigmer.agentShare.rotateShareLink(
|
|
70
|
+
create(RotateShareLinkInputSchema, { resourceId: shareId }),
|
|
66
71
|
);
|
|
67
72
|
} catch (err) {
|
|
68
73
|
setError(toError(err));
|
|
@@ -70,7 +75,7 @@ export function useRotateShareLink(
|
|
|
70
75
|
} finally {
|
|
71
76
|
setIsPending(false);
|
|
72
77
|
}
|
|
73
|
-
}, [
|
|
78
|
+
}, [shareId, stigmer]);
|
|
74
79
|
|
|
75
80
|
return { rotateShareLink, isPending, error };
|
|
76
81
|
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
4
|
+
import type { Agent } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
5
|
+
import type { AgentShare } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/api_pb";
|
|
6
|
+
import { AgentShareAudience } from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/spec_pb";
|
|
7
|
+
import type { ResourceRef } from "@stigmer/sdk";
|
|
8
|
+
import { useStigmer } from "../hooks.js";
|
|
9
|
+
import { toError } from "../internal/toError.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Who can chat with a shared agent over its hosted link.
|
|
13
|
+
*
|
|
14
|
+
* - `"public"` — anyone with the link; visitors are anonymous guests.
|
|
15
|
+
* - `"org"` — signed-in members of the owning organization only.
|
|
16
|
+
* Membership is checked on every conversation turn, so access ends the
|
|
17
|
+
* moment a member leaves the org.
|
|
18
|
+
*/
|
|
19
|
+
export type SharingAudience = "public" | "org";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A complete share configuration to persist.
|
|
23
|
+
*
|
|
24
|
+
* Every field is required by design: saving **replaces the share's whole
|
|
25
|
+
* spec**, so a caller must always supply the full configuration. A
|
|
26
|
+
* partial type here would let a toggle change silently wipe
|
|
27
|
+
* `allowedOrigins`, `messages`, `environmentRefs`, or the `audience` —
|
|
28
|
+
* the required shape makes that mistake unrepresentable. (The rotatable
|
|
29
|
+
* link token is exempt: it is server-owned `status`, which survives
|
|
30
|
+
* every save verbatim.)
|
|
31
|
+
*/
|
|
32
|
+
export interface AgentShareDraft {
|
|
33
|
+
/** Whether hosted-chat access for the configured audience is enabled. */
|
|
34
|
+
readonly enabled: boolean;
|
|
35
|
+
/** Who can chat: anyone with the link, or org members only. */
|
|
36
|
+
readonly audience: SharingAudience;
|
|
37
|
+
/**
|
|
38
|
+
* Exact web origins allowed to embed the shared agent
|
|
39
|
+
* (e.g. `https://example.com`). Empty list = embeddable anywhere.
|
|
40
|
+
* Embedding is public-audience only.
|
|
41
|
+
*/
|
|
42
|
+
readonly allowedOrigins: readonly string[];
|
|
43
|
+
/** Owner-customized visitor refusal copy. Empty strings mean platform defaults. */
|
|
44
|
+
readonly messages: {
|
|
45
|
+
/** Shown when a visitor exceeds the message rate limit. */
|
|
46
|
+
readonly rateLimited: string;
|
|
47
|
+
/** Shown when the org's credits are exhausted (sharing fails closed). */
|
|
48
|
+
readonly unavailable: string;
|
|
49
|
+
/** Shown when a conversation hits its turn limit or inactivity timeout. */
|
|
50
|
+
readonly conversationEnded: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Org-shared environments whose values guest conversations receive —
|
|
54
|
+
* how a tool-using agent becomes chattable over a share link without
|
|
55
|
+
* touching its pristine default instance. Public-audience only (the
|
|
56
|
+
* proto CEL rule rejects bindings on org-audience shares, whose member
|
|
57
|
+
* sessions carry no share linkage in Phase A — decision 011 addendum).
|
|
58
|
+
*/
|
|
59
|
+
readonly environmentRefs: readonly ResourceRef[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Maps a proto {@link AgentShareAudience} to the SDK's string union.
|
|
64
|
+
* Unspecified means public by contract (a share created without an
|
|
65
|
+
* explicit audience is an anyone-with-link share).
|
|
66
|
+
*/
|
|
67
|
+
export function sharingAudienceFromProto(
|
|
68
|
+
audience: AgentShareAudience | undefined,
|
|
69
|
+
): SharingAudience {
|
|
70
|
+
return audience === AgentShareAudience.org ? "org" : "public";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function sharingAudienceToProto(audience: SharingAudience): AgentShareAudience {
|
|
74
|
+
return audience === "org"
|
|
75
|
+
? AgentShareAudience.org
|
|
76
|
+
: AgentShareAudience.public;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Return value of {@link useSaveAgentShare}. */
|
|
80
|
+
export interface UseSaveAgentShareReturn {
|
|
81
|
+
/**
|
|
82
|
+
* Persist the complete share configuration. Resolves with the
|
|
83
|
+
* persisted {@link AgentShare} — adopt it as the new baseline (its
|
|
84
|
+
* `status.shareLinkToken` carries the live link token).
|
|
85
|
+
*
|
|
86
|
+
* `current` is the share being edited, or `null` when the agent has
|
|
87
|
+
* never been shared — the save then creates the canonical share.
|
|
88
|
+
*/
|
|
89
|
+
readonly save: (
|
|
90
|
+
draft: AgentShareDraft,
|
|
91
|
+
current: AgentShare | null,
|
|
92
|
+
) => Promise<AgentShare | undefined>;
|
|
93
|
+
/** `true` while the RPC is in flight. */
|
|
94
|
+
readonly isPending: boolean;
|
|
95
|
+
/** The last error from the RPC, or `null`. */
|
|
96
|
+
readonly error: Error | null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Behavior hook that persists an agent's canonical share configuration.
|
|
101
|
+
*
|
|
102
|
+
* Commits via `stigmer.agentShare.apply()` — an idempotent upsert keyed
|
|
103
|
+
* on the share's `(org, slug)` identity — so one code path serves both
|
|
104
|
+
* the first enable (creates the share; the server authorizes on the
|
|
105
|
+
* referenced agent's `can_edit`) and every later edit. There is
|
|
106
|
+
* deliberately no create/update branching: the share slug is unique per
|
|
107
|
+
* org and defaults to the agent's slug, which makes apply-by-identity
|
|
108
|
+
* exact, and the generated `AgentShareInput` carries no `metadata.id`
|
|
109
|
+
* for an update to route by anyway.
|
|
110
|
+
*
|
|
111
|
+
* Disabling is a save with `enabled: false` — a config-preserving pause
|
|
112
|
+
* (decision 011 D1). Deleting the share is a separate, destructive
|
|
113
|
+
* operation this hook does not perform.
|
|
114
|
+
*
|
|
115
|
+
* Pass `null` for `agent` to produce a stable no-op (useful while the
|
|
116
|
+
* agent is still loading).
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```tsx
|
|
120
|
+
* const { share } = useAgentShare(agent);
|
|
121
|
+
* const { save, isPending } = useSaveAgentShare(agent);
|
|
122
|
+
*
|
|
123
|
+
* const persisted = await save({ ...draft, enabled: true }, share);
|
|
124
|
+
* // persisted.status.shareLinkToken is the live link token
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export function useSaveAgentShare(
|
|
128
|
+
agent: Agent | null,
|
|
129
|
+
): UseSaveAgentShareReturn {
|
|
130
|
+
const stigmer = useStigmer();
|
|
131
|
+
const [isPending, setIsPending] = useState(false);
|
|
132
|
+
const [error, setError] = useState<Error | null>(null);
|
|
133
|
+
|
|
134
|
+
const agentOrg = agent?.metadata?.org ?? "";
|
|
135
|
+
const agentSlug = agent?.metadata?.slug ?? "";
|
|
136
|
+
const agentName = agent?.metadata?.name ?? "";
|
|
137
|
+
|
|
138
|
+
const save = useCallback(
|
|
139
|
+
async (
|
|
140
|
+
draft: AgentShareDraft,
|
|
141
|
+
current: AgentShare | null,
|
|
142
|
+
): Promise<AgentShare | undefined> => {
|
|
143
|
+
if (!agentOrg || !agentSlug) return undefined;
|
|
144
|
+
|
|
145
|
+
setIsPending(true);
|
|
146
|
+
setError(null);
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
return await stigmer.agentShare.apply({
|
|
150
|
+
// Identity: the existing share's org/slug when editing (a
|
|
151
|
+
// manifest-created share may carry a non-default slug — apply
|
|
152
|
+
// with the agent's slug would create a SECOND share), the
|
|
153
|
+
// agent's when creating (the server's own D2 default, made
|
|
154
|
+
// explicit).
|
|
155
|
+
org: current?.metadata?.org || agentOrg,
|
|
156
|
+
slug: current?.metadata?.slug || agentSlug,
|
|
157
|
+
name: current?.metadata?.name || agentName || agentSlug,
|
|
158
|
+
agentRef: { org: agentOrg, slug: agentSlug },
|
|
159
|
+
enabled: draft.enabled,
|
|
160
|
+
// Written as the explicit enum value, never left unspecified —
|
|
161
|
+
// a share persisted as "public" can't be silently downgraded
|
|
162
|
+
// by tooling that relies on the unspecified-means-public rule.
|
|
163
|
+
audience: sharingAudienceToProto(draft.audience),
|
|
164
|
+
allowedOrigins: [...draft.allowedOrigins],
|
|
165
|
+
messages: {
|
|
166
|
+
rateLimited: draft.messages.rateLimited,
|
|
167
|
+
unavailable: draft.messages.unavailable,
|
|
168
|
+
conversationEnded: draft.messages.conversationEnded,
|
|
169
|
+
},
|
|
170
|
+
environmentRefs: draft.environmentRefs.map((ref) => ({
|
|
171
|
+
org: ref.org,
|
|
172
|
+
slug: ref.slug,
|
|
173
|
+
})),
|
|
174
|
+
});
|
|
175
|
+
} catch (err) {
|
|
176
|
+
setError(toError(err));
|
|
177
|
+
throw err;
|
|
178
|
+
} finally {
|
|
179
|
+
setIsPending(false);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
[agentOrg, agentSlug, agentName, stigmer],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
return { save, isPending, error };
|
|
186
|
+
}
|
|
@@ -54,10 +54,11 @@ export interface UseShareAgentReturn {
|
|
|
54
54
|
* the running agent (billed to the owning org).
|
|
55
55
|
*
|
|
56
56
|
* Owns the open-state and the `can_edit` gate — the same permission the
|
|
57
|
-
*
|
|
58
|
-
* whose changes would be rejected.
|
|
59
|
-
* agent is loading or the user cannot
|
|
60
|
-
* unconditionally fold `action` into its actions
|
|
57
|
+
* AgentShare create/apply handlers enforce on the referenced agent, so
|
|
58
|
+
* the action never appears to a user whose changes would be rejected.
|
|
59
|
+
* Returns a `null` action while the agent is loading or the user cannot
|
|
60
|
+
* edit, so the host can unconditionally fold `action` into its actions
|
|
61
|
+
* array.
|
|
61
62
|
*
|
|
62
63
|
* @example
|
|
63
64
|
* ```tsx
|
|
@@ -1,106 +1,106 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
4
|
import type { Agent } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
5
5
|
import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
|
|
6
6
|
import { useStigmer } from "../hooks.js";
|
|
7
7
|
import { useDeploymentMode } from "../deployment-mode.js";
|
|
8
|
+
import type { AgentShareDraft } from "./useSaveAgentShare.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Readiness of a
|
|
11
|
-
* teammate) executions.
|
|
11
|
+
* Readiness of a share's tool credentials for visitor executions.
|
|
12
12
|
*
|
|
13
|
-
* - `na` — nothing to check: the agent uses no MCP tools,
|
|
14
|
-
*
|
|
13
|
+
* - `na` — nothing to check: the agent uses no MCP tools, sharing is
|
|
14
|
+
* off, the audience is org (bindings are public-audience only), or
|
|
15
|
+
* the deployment cannot serve guest chat (local mode).
|
|
16
|
+
* - `needs-credentials` — the agent uses MCP tools but the share has no
|
|
17
|
+
* environments bound: visitors' tool calls will fail until the owner
|
|
18
|
+
* binds credentials.
|
|
15
19
|
* - `checking` — lookups in flight.
|
|
16
|
-
* - `ready` — every environment bound to the
|
|
17
|
-
*
|
|
20
|
+
* - `ready` — every environment bound to the share is shared with the
|
|
21
|
+
* organization.
|
|
18
22
|
* - `blocked` — one or more bound environments are private; their
|
|
19
23
|
* `org/slug` references are listed for the hint copy.
|
|
20
24
|
*/
|
|
21
25
|
export type ShareToolReadiness =
|
|
22
26
|
| { readonly status: "na" }
|
|
27
|
+
| { readonly status: "needs-credentials" }
|
|
23
28
|
| { readonly status: "checking" }
|
|
24
29
|
| { readonly status: "ready" }
|
|
25
30
|
| { readonly status: "blocked"; readonly privateEnvironments: readonly string[] };
|
|
26
31
|
|
|
27
32
|
const NA: ShareToolReadiness = { status: "na" };
|
|
33
|
+
const NEEDS_CREDENTIALS: ShareToolReadiness = { status: "needs-credentials" };
|
|
28
34
|
|
|
29
35
|
/**
|
|
30
36
|
* Data hook that checks whether a tool-using shared agent's credentials
|
|
31
|
-
* will work for visitors — i.e. whether the
|
|
32
|
-
*
|
|
37
|
+
* will work for visitors — i.e. whether the share binds environments
|
|
38
|
+
* (`environment_refs`) and each one is shared with the organization
|
|
39
|
+
* (`visibility_org`).
|
|
33
40
|
*
|
|
34
|
-
* Guest
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
41
|
+
* Guest executions receive credentials exclusively from the share's own
|
|
42
|
+
* `environment_refs`, resolved through the org-shared environment seam
|
|
43
|
+
* (decision 011 — the agent's default instance stays pristine and is
|
|
44
|
+
* never consulted). So a tool-using agent with an empty binding list is
|
|
45
|
+
* *guaranteed* broken for visitors, and this hook says so explicitly
|
|
46
|
+
* (`needs-credentials`) instead of staying silent — the gap that made
|
|
47
|
+
* session 12's misconfiguration invisible until a visitor's first
|
|
48
|
+
* message failed.
|
|
40
49
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* The check runs only when `enabled` is true, the deployment is cloud
|
|
48
|
-
* (local mode has no guest runtime or secret gating), and the agent
|
|
49
|
-
* declares MCP server usages. All lookups run as the owner viewing the
|
|
50
|
-
* dialog, who can read the bound environments.
|
|
50
|
+
* The check runs only when the share is enabled with a public audience
|
|
51
|
+
* (org-audience shares reject bindings at the proto boundary), the
|
|
52
|
+
* deployment is cloud (local mode has no guest runtime or secret
|
|
53
|
+
* gating), and the agent declares MCP server usages. All lookups run as
|
|
54
|
+
* the owner viewing the dialog, who can read the bound environments.
|
|
51
55
|
*/
|
|
52
56
|
export function useShareToolReadiness(
|
|
53
57
|
agent: Agent,
|
|
54
|
-
|
|
58
|
+
draft: AgentShareDraft,
|
|
55
59
|
): ShareToolReadiness {
|
|
56
60
|
const stigmer = useStigmer();
|
|
57
61
|
const deploymentMode = useDeploymentMode();
|
|
58
|
-
const [
|
|
62
|
+
const [checked, setChecked] = useState<ShareToolReadiness>(NA);
|
|
59
63
|
|
|
60
|
-
const agentId = agent.metadata?.id ?? "";
|
|
61
64
|
const hasMcpTools = (agent.spec?.mcpServerUsages?.length ?? 0) > 0;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
enabled &&
|
|
65
|
+
const applicable =
|
|
66
|
+
draft.enabled &&
|
|
67
|
+
draft.audience === "public" &&
|
|
66
68
|
deploymentMode === "cloud" &&
|
|
67
|
-
hasMcpTools
|
|
68
|
-
|
|
69
|
+
hasMcpTools;
|
|
70
|
+
|
|
71
|
+
// Stable key for the effect: the visibility lookups depend only on
|
|
72
|
+
// which environments are bound, not on the array's identity.
|
|
73
|
+
const refsKey = useMemo(
|
|
74
|
+
() => draft.environmentRefs.map((ref) => `${ref.org}/${ref.slug}`).join(","),
|
|
75
|
+
[draft.environmentRefs],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const shouldFetch = applicable && refsKey !== "";
|
|
69
79
|
|
|
70
80
|
useEffect(() => {
|
|
71
|
-
if (!
|
|
72
|
-
|
|
81
|
+
if (!shouldFetch) {
|
|
82
|
+
setChecked(NA);
|
|
73
83
|
return;
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
let cancelled = false;
|
|
77
|
-
|
|
87
|
+
setChecked({ status: "checking" });
|
|
78
88
|
|
|
79
89
|
(async (): Promise<ShareToolReadiness> => {
|
|
80
|
-
const instance = await stigmer.agentInstance.get(defaultInstanceId);
|
|
81
|
-
const refs = instance.spec?.environmentRefs ?? [];
|
|
82
|
-
if (refs.length === 0) {
|
|
83
|
-
// No bound environments to assess. The tools may need no
|
|
84
|
-
// credentials at all — do not warn on a guess.
|
|
85
|
-
return NA;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
90
|
const privateRefs: string[] = [];
|
|
89
|
-
for (const ref of
|
|
91
|
+
for (const ref of refsKey.split(",")) {
|
|
92
|
+
const [org, slug] = ref.split("/");
|
|
90
93
|
try {
|
|
91
|
-
const env = await stigmer.environment.getByReference({
|
|
92
|
-
org: ref.org,
|
|
93
|
-
slug: ref.slug,
|
|
94
|
-
});
|
|
94
|
+
const env = await stigmer.environment.getByReference({ org, slug });
|
|
95
95
|
if (
|
|
96
96
|
env.metadata?.visibility !== ApiResourceVisibility.visibility_org
|
|
97
97
|
) {
|
|
98
|
-
privateRefs.push(
|
|
98
|
+
privateRefs.push(ref);
|
|
99
99
|
}
|
|
100
100
|
} catch {
|
|
101
|
-
// Unreadable ref (deleted, foreign): the runtime will
|
|
102
|
-
// for visitors too — surface it as blocking.
|
|
103
|
-
privateRefs.push(
|
|
101
|
+
// Unreadable ref (deleted, foreign): the runtime's merge will
|
|
102
|
+
// skip it for visitors too — surface it as blocking.
|
|
103
|
+
privateRefs.push(ref);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -109,21 +109,23 @@ export function useShareToolReadiness(
|
|
|
109
109
|
: { status: "blocked", privateEnvironments: privateRefs };
|
|
110
110
|
})().then(
|
|
111
111
|
(result) => {
|
|
112
|
-
if (!cancelled)
|
|
112
|
+
if (!cancelled) setChecked(result);
|
|
113
113
|
},
|
|
114
114
|
() => {
|
|
115
115
|
// The hint is best-effort pre-flight advice — a failed check must
|
|
116
116
|
// never block the dialog. The runtime error path still diagnoses.
|
|
117
|
-
if (!cancelled)
|
|
117
|
+
if (!cancelled) setChecked(NA);
|
|
118
118
|
},
|
|
119
119
|
);
|
|
120
120
|
|
|
121
121
|
return () => {
|
|
122
122
|
cancelled = true;
|
|
123
123
|
};
|
|
124
|
-
|
|
125
|
-
// matter (instance id, MCP usage presence) are covered explicitly.
|
|
126
|
-
}, [shouldCheck, defaultInstanceId, agentId, stigmer]);
|
|
124
|
+
}, [shouldFetch, refsKey, stigmer]);
|
|
127
125
|
|
|
128
|
-
return
|
|
126
|
+
if (!applicable) return NA;
|
|
127
|
+
// Zero bindings needs no lookup: a tool-using agent without bound
|
|
128
|
+
// credentials is broken for visitors by construction.
|
|
129
|
+
if (refsKey === "") return NEEDS_CREDENTIALS;
|
|
130
|
+
return checked;
|
|
129
131
|
}
|
|
@@ -4,11 +4,11 @@ import { create } from "@bufbuild/protobuf";
|
|
|
4
4
|
import {
|
|
5
5
|
GetSharedProfileRequestSchema,
|
|
6
6
|
type SharedAgentProfile,
|
|
7
|
-
} from "@stigmer/protos/ai/stigmer/agentic/
|
|
7
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentshare/v1/io_pb";
|
|
8
8
|
import { isNotFound } from "@stigmer/sdk";
|
|
9
9
|
import { useStigmer } from "../hooks.js";
|
|
10
10
|
import { useFetch } from "../internal/useFetch.js";
|
|
11
|
-
import type { SharingAudience } from "./
|
|
11
|
+
import type { SharingAudience } from "./useSaveAgentShare.js";
|
|
12
12
|
|
|
13
13
|
/** Options for {@link useSharedAgentProfile}. */
|
|
14
14
|
export interface UseSharedAgentProfileOptions {
|
|
@@ -53,8 +53,9 @@ export interface UseSharedAgentProfileReturn {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Data hook that fetches a shared agent's public profile by
|
|
57
|
-
*
|
|
56
|
+
* Data hook that fetches a shared agent's public profile by the org and
|
|
57
|
+
* slug from the share URL (the share's slug — it defaults to the
|
|
58
|
+
* agent's, so existing links resolve unchanged).
|
|
58
59
|
*
|
|
59
60
|
* By default this hook calls the `getSharedProfile` endpoint, which is
|
|
60
61
|
* **public** — it requires no authentication. The server returns a
|
|
@@ -110,8 +111,8 @@ export function useSharedAgentProfile(
|
|
|
110
111
|
// is gated by live membership, and token-locked public shares
|
|
111
112
|
// deliberately refuse there (see getSharedProfileForMember).
|
|
112
113
|
return audience === "org"
|
|
113
|
-
? await stigmer.
|
|
114
|
-
: await stigmer.
|
|
114
|
+
? await stigmer.agentShare.getSharedProfileForMember({ org, slug })
|
|
115
|
+
: await stigmer.agentShare.getSharedProfile(
|
|
115
116
|
create(GetSharedProfileRequestSchema, { org, slug, linkToken }),
|
|
116
117
|
);
|
|
117
118
|
} catch (err) {
|