@stigmer/react 3.1.13 → 3.1.14
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/agent/AgentDetailView.d.ts +7 -9
- package/agent/AgentDetailView.d.ts.map +1 -1
- package/agent/AgentDetailView.js +22 -30
- package/agent/AgentDetailView.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/AgentShareList.d.ts +44 -0
- package/sharing/AgentShareList.d.ts.map +1 -0
- package/sharing/AgentShareList.js +149 -0
- package/sharing/AgentShareList.js.map +1 -0
- package/sharing/ShareAgentDialog.d.ts +38 -25
- package/sharing/ShareAgentDialog.d.ts.map +1 -1
- package/sharing/ShareAgentDialog.js +131 -62
- package/sharing/ShareAgentDialog.js.map +1 -1
- package/sharing/index.d.ts +10 -8
- package/sharing/index.d.ts.map +1 -1
- package/sharing/index.js +5 -4
- package/sharing/index.js.map +1 -1
- package/sharing/useAgentShares.d.ts +42 -0
- package/sharing/useAgentShares.d.ts.map +1 -0
- package/sharing/useAgentShares.js +38 -0
- package/sharing/useAgentShares.js.map +1 -0
- package/sharing/useCanCreateAgentShare.d.ts +43 -0
- package/sharing/useCanCreateAgentShare.d.ts.map +1 -0
- package/sharing/useCanCreateAgentShare.js +44 -0
- package/sharing/useCanCreateAgentShare.js.map +1 -0
- package/sharing/useDeleteAgentShare.d.ts +42 -0
- package/sharing/useDeleteAgentShare.d.ts.map +1 -0
- package/sharing/useDeleteAgentShare.js +45 -0
- package/sharing/useDeleteAgentShare.js.map +1 -0
- package/sharing/useSaveAgentShare.d.ts +43 -18
- package/sharing/useSaveAgentShare.d.ts.map +1 -1
- package/sharing/useSaveAgentShare.js +55 -22
- package/sharing/useSaveAgentShare.js.map +1 -1
- package/src/agent/AgentDetailView.tsx +34 -43
- package/src/index.ts +11 -9
- package/src/sharing/AgentShareList.tsx +507 -0
- package/src/sharing/ShareAgentDialog.tsx +310 -112
- package/src/sharing/__tests__/AgentShareList.test.tsx +388 -0
- package/src/sharing/__tests__/ShareAgentDialog.test.tsx +311 -312
- package/src/sharing/__tests__/useAgentShares.test.tsx +145 -0
- package/src/sharing/__tests__/useCanCreateAgentShare.test.tsx +190 -0
- package/src/sharing/index.ts +10 -12
- package/src/sharing/useAgentShares.ts +68 -0
- package/src/sharing/useCanCreateAgentShare.ts +74 -0
- package/src/sharing/useDeleteAgentShare.ts +73 -0
- package/src/sharing/useSaveAgentShare.ts +73 -23
- package/styles.css +1 -1
- package/sharing/useAgentShare.d.ts +0 -49
- package/sharing/useAgentShare.d.ts.map +0 -1
- package/sharing/useAgentShare.js +0 -64
- package/sharing/useAgentShare.js.map +0 -1
- package/sharing/useCreateExternalShareLink.d.ts +0 -90
- package/sharing/useCreateExternalShareLink.d.ts.map +0 -1
- package/sharing/useCreateExternalShareLink.js +0 -65
- package/sharing/useCreateExternalShareLink.js.map +0 -1
- package/sharing/useShareAgent.d.ts +0 -69
- package/sharing/useShareAgent.d.ts.map +0 -1
- package/sharing/useShareAgent.js +0 -42
- package/sharing/useShareAgent.js.map +0 -1
- package/src/sharing/__tests__/useAgentShare.test.tsx +0 -210
- package/src/sharing/__tests__/useCreateExternalShareLink.test.tsx +0 -194
- package/src/sharing/__tests__/useShareAgent.test.tsx +0 -131
- package/src/sharing/useAgentShare.ts +0 -105
- package/src/sharing/useCreateExternalShareLink.tsx +0 -141
- package/src/sharing/useShareAgent.tsx +0 -107
|
@@ -76,6 +76,48 @@ function sharingAudienceToProto(audience: SharingAudience): AgentShareAudience {
|
|
|
76
76
|
: AgentShareAudience.public;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Projects a share into the editable {@link AgentShareDraft} — the
|
|
81
|
+
* single constructor for the full-spec drafts every save requires.
|
|
82
|
+
* `null` (no share yet) seeds the same defaults the server would apply
|
|
83
|
+
* on first create.
|
|
84
|
+
*
|
|
85
|
+
* Shared by the Share dialog (draft seeding) and the share list's
|
|
86
|
+
* pause/resume toggle, so a toggle rebuilds the complete spec with only
|
|
87
|
+
* `enabled` flipped and can never wipe origins, messages, or credential
|
|
88
|
+
* bindings — the fails-closed posture {@link AgentShareDraft} exists to
|
|
89
|
+
* enforce.
|
|
90
|
+
*/
|
|
91
|
+
export function draftFromShare(share: AgentShare | null): AgentShareDraft {
|
|
92
|
+
const spec = share?.spec;
|
|
93
|
+
return {
|
|
94
|
+
enabled: spec?.enabled ?? false,
|
|
95
|
+
audience: sharingAudienceFromProto(spec?.audience),
|
|
96
|
+
allowedOrigins: spec?.allowedOrigins ?? [],
|
|
97
|
+
messages: {
|
|
98
|
+
rateLimited: spec?.messages?.rateLimited ?? "",
|
|
99
|
+
unavailable: spec?.messages?.unavailable ?? "",
|
|
100
|
+
conversationEnded: spec?.messages?.conversationEnded ?? "",
|
|
101
|
+
},
|
|
102
|
+
environmentRefs: (spec?.environmentRefs ?? []).map((ref) => ({
|
|
103
|
+
org: ref.org,
|
|
104
|
+
slug: ref.slug,
|
|
105
|
+
})),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Identity for a share being created: its display name and URL slug in
|
|
111
|
+
* the sharing org's namespace. Only consulted when `current` is `null`
|
|
112
|
+
* — an existing share's identity is immutable (decision 011 D2).
|
|
113
|
+
*/
|
|
114
|
+
export interface AgentShareCreateIdentity {
|
|
115
|
+
/** Display name for the new share. */
|
|
116
|
+
readonly name: string;
|
|
117
|
+
/** URL slug for the new share — appears in `/chat/<org>/<slug>`. */
|
|
118
|
+
readonly slug: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
79
121
|
/** Return value of {@link useSaveAgentShare}. */
|
|
80
122
|
export interface UseSaveAgentShareReturn {
|
|
81
123
|
/**
|
|
@@ -83,12 +125,14 @@ export interface UseSaveAgentShareReturn {
|
|
|
83
125
|
* persisted {@link AgentShare} — adopt it as the new baseline (its
|
|
84
126
|
* `status.shareLinkToken` carries the live link token).
|
|
85
127
|
*
|
|
86
|
-
* `current` is the share being edited, or `null`
|
|
87
|
-
*
|
|
128
|
+
* `current` is the share being edited, or `null` to create one —
|
|
129
|
+
* named by `createIdentity` when given, else the server's defaults
|
|
130
|
+
* (the agent's own name and slug).
|
|
88
131
|
*/
|
|
89
132
|
readonly save: (
|
|
90
133
|
draft: AgentShareDraft,
|
|
91
134
|
current: AgentShare | null,
|
|
135
|
+
createIdentity?: AgentShareCreateIdentity,
|
|
92
136
|
) => Promise<AgentShare | undefined>;
|
|
93
137
|
/** `true` while the RPC is in flight. */
|
|
94
138
|
readonly isPending: boolean;
|
|
@@ -97,36 +141,36 @@ export interface UseSaveAgentShareReturn {
|
|
|
97
141
|
}
|
|
98
142
|
|
|
99
143
|
/**
|
|
100
|
-
* Behavior hook that persists an agent's
|
|
144
|
+
* Behavior hook that persists an agent share's configuration.
|
|
101
145
|
*
|
|
102
146
|
* Commits via `stigmer.agentShare.apply()` — an idempotent upsert keyed
|
|
103
147
|
* on the share's `(org, slug)` identity — so one code path serves both
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
148
|
+
* creation (the server authorizes on the referenced agent's `can_edit`)
|
|
149
|
+
* and every later edit. There is deliberately no create/update
|
|
150
|
+
* branching: the share slug is unique per org, which makes
|
|
151
|
+
* apply-by-identity exact, and the generated `AgentShareInput` carries
|
|
152
|
+
* no `metadata.id` for an update to route by anyway. A create that
|
|
153
|
+
* collides on `(org, slug)` rejects with an already-exists error rather
|
|
154
|
+
* than touching the existing share.
|
|
110
155
|
*
|
|
111
156
|
* Disabling is a save with `enabled: false` — a config-preserving pause
|
|
112
157
|
* (decision 011 D1). Deleting the share is a separate, destructive
|
|
113
|
-
* operation
|
|
158
|
+
* operation ({@link useDeleteAgentShare}).
|
|
114
159
|
*
|
|
115
|
-
* `shareOrg` selects which org
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
160
|
+
* `shareOrg` selects which org owns a created share and defaults to the
|
|
161
|
+
* agent's own org. Pass the viewer's org to create a **cross-org
|
|
162
|
+
* share** (decision 013) — the server then authorizes on the public
|
|
163
|
+
* agent's `can_execute` plus `can_create_agent_share` in the sharing
|
|
164
|
+
* org, and bills that org.
|
|
120
165
|
*
|
|
121
166
|
* Pass `null` for `agent` to produce a stable no-op (useful while the
|
|
122
167
|
* agent is still loading).
|
|
123
168
|
*
|
|
124
169
|
* @example
|
|
125
170
|
* ```tsx
|
|
126
|
-
* const { share } = useAgentShare(agent);
|
|
127
171
|
* const { save, isPending } = useSaveAgentShare(agent);
|
|
128
172
|
*
|
|
129
|
-
* const persisted = await save({ ...
|
|
173
|
+
* const persisted = await save({ ...draftFromShare(share), enabled: true }, share);
|
|
130
174
|
* // persisted.status.shareLinkToken is the live link token
|
|
131
175
|
* ```
|
|
132
176
|
*/
|
|
@@ -147,6 +191,7 @@ export function useSaveAgentShare(
|
|
|
147
191
|
async (
|
|
148
192
|
draft: AgentShareDraft,
|
|
149
193
|
current: AgentShare | null,
|
|
194
|
+
createIdentity?: AgentShareCreateIdentity,
|
|
150
195
|
): Promise<AgentShare | undefined> => {
|
|
151
196
|
if (!agentOrg || !agentSlug) return undefined;
|
|
152
197
|
|
|
@@ -156,13 +201,18 @@ export function useSaveAgentShare(
|
|
|
156
201
|
try {
|
|
157
202
|
return await stigmer.agentShare.apply({
|
|
158
203
|
// Identity: the existing share's org/slug when editing (a
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
// sharing org + the
|
|
162
|
-
// own D2 default, made
|
|
204
|
+
// share may carry a non-default slug — apply with the agent's
|
|
205
|
+
// slug would create a SECOND share); when creating, the
|
|
206
|
+
// sharing org + the caller-chosen identity, falling back to
|
|
207
|
+
// the agent's own slug/name (the server's D2 default, made
|
|
208
|
+
// explicit).
|
|
163
209
|
org: current?.metadata?.org || resolvedShareOrg,
|
|
164
|
-
slug: current?.metadata?.slug || agentSlug,
|
|
165
|
-
name:
|
|
210
|
+
slug: current?.metadata?.slug || createIdentity?.slug || agentSlug,
|
|
211
|
+
name:
|
|
212
|
+
current?.metadata?.name ||
|
|
213
|
+
createIdentity?.name ||
|
|
214
|
+
agentName ||
|
|
215
|
+
agentSlug,
|
|
166
216
|
agentRef: { org: agentOrg, slug: agentSlug },
|
|
167
217
|
enabled: draft.enabled,
|
|
168
218
|
// Written as the explicit enum value, never left unspecified —
|