@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.
Files changed (69) hide show
  1. package/agent/AgentDetailView.d.ts +7 -9
  2. package/agent/AgentDetailView.d.ts.map +1 -1
  3. package/agent/AgentDetailView.js +22 -30
  4. package/agent/AgentDetailView.js.map +1 -1
  5. package/index.d.ts +2 -2
  6. package/index.d.ts.map +1 -1
  7. package/index.js +2 -2
  8. package/index.js.map +1 -1
  9. package/package.json +4 -4
  10. package/sharing/AgentShareList.d.ts +44 -0
  11. package/sharing/AgentShareList.d.ts.map +1 -0
  12. package/sharing/AgentShareList.js +149 -0
  13. package/sharing/AgentShareList.js.map +1 -0
  14. package/sharing/ShareAgentDialog.d.ts +38 -25
  15. package/sharing/ShareAgentDialog.d.ts.map +1 -1
  16. package/sharing/ShareAgentDialog.js +131 -62
  17. package/sharing/ShareAgentDialog.js.map +1 -1
  18. package/sharing/index.d.ts +10 -8
  19. package/sharing/index.d.ts.map +1 -1
  20. package/sharing/index.js +5 -4
  21. package/sharing/index.js.map +1 -1
  22. package/sharing/useAgentShares.d.ts +42 -0
  23. package/sharing/useAgentShares.d.ts.map +1 -0
  24. package/sharing/useAgentShares.js +38 -0
  25. package/sharing/useAgentShares.js.map +1 -0
  26. package/sharing/useCanCreateAgentShare.d.ts +43 -0
  27. package/sharing/useCanCreateAgentShare.d.ts.map +1 -0
  28. package/sharing/useCanCreateAgentShare.js +44 -0
  29. package/sharing/useCanCreateAgentShare.js.map +1 -0
  30. package/sharing/useDeleteAgentShare.d.ts +42 -0
  31. package/sharing/useDeleteAgentShare.d.ts.map +1 -0
  32. package/sharing/useDeleteAgentShare.js +45 -0
  33. package/sharing/useDeleteAgentShare.js.map +1 -0
  34. package/sharing/useSaveAgentShare.d.ts +43 -18
  35. package/sharing/useSaveAgentShare.d.ts.map +1 -1
  36. package/sharing/useSaveAgentShare.js +55 -22
  37. package/sharing/useSaveAgentShare.js.map +1 -1
  38. package/src/agent/AgentDetailView.tsx +34 -43
  39. package/src/index.ts +11 -9
  40. package/src/sharing/AgentShareList.tsx +507 -0
  41. package/src/sharing/ShareAgentDialog.tsx +310 -112
  42. package/src/sharing/__tests__/AgentShareList.test.tsx +388 -0
  43. package/src/sharing/__tests__/ShareAgentDialog.test.tsx +311 -312
  44. package/src/sharing/__tests__/useAgentShares.test.tsx +145 -0
  45. package/src/sharing/__tests__/useCanCreateAgentShare.test.tsx +190 -0
  46. package/src/sharing/index.ts +10 -12
  47. package/src/sharing/useAgentShares.ts +68 -0
  48. package/src/sharing/useCanCreateAgentShare.ts +74 -0
  49. package/src/sharing/useDeleteAgentShare.ts +73 -0
  50. package/src/sharing/useSaveAgentShare.ts +73 -23
  51. package/styles.css +1 -1
  52. package/sharing/useAgentShare.d.ts +0 -49
  53. package/sharing/useAgentShare.d.ts.map +0 -1
  54. package/sharing/useAgentShare.js +0 -64
  55. package/sharing/useAgentShare.js.map +0 -1
  56. package/sharing/useCreateExternalShareLink.d.ts +0 -90
  57. package/sharing/useCreateExternalShareLink.d.ts.map +0 -1
  58. package/sharing/useCreateExternalShareLink.js +0 -65
  59. package/sharing/useCreateExternalShareLink.js.map +0 -1
  60. package/sharing/useShareAgent.d.ts +0 -69
  61. package/sharing/useShareAgent.d.ts.map +0 -1
  62. package/sharing/useShareAgent.js +0 -42
  63. package/sharing/useShareAgent.js.map +0 -1
  64. package/src/sharing/__tests__/useAgentShare.test.tsx +0 -210
  65. package/src/sharing/__tests__/useCreateExternalShareLink.test.tsx +0 -194
  66. package/src/sharing/__tests__/useShareAgent.test.tsx +0 -131
  67. package/src/sharing/useAgentShare.ts +0 -105
  68. package/src/sharing/useCreateExternalShareLink.tsx +0 -141
  69. 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` when the agent has
87
- * never been shared the save then creates the canonical share.
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 canonical share configuration.
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
- * 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.
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 this hook does not perform.
158
+ * operation ({@link useDeleteAgentShare}).
114
159
  *
115
- * `shareOrg` selects which org's channel a first save creates and
116
- * defaults to the agent's own org. Pass the viewer's org to create a
117
- * **cross-org share** (decision 013) — the server then authorizes on the
118
- * public agent's `can_execute` plus `can_create_agent_share` in the
119
- * sharing org, and bills that org.
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({ ...draft, enabled: true }, share);
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
- // manifest-created share may carry a non-default slug — apply
160
- // with the agent's slug would create a SECOND share), the
161
- // sharing org + the agent's slug when creating (the server's
162
- // own D2 default, made explicit).
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: current?.metadata?.name || agentName || agentSlug,
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 —