@assistant-ui/react-statewire 0.21.0 → 0.23.0

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.
@@ -121,6 +121,38 @@ export const sendFields = (
121
121
  runAnchorMessageId: viewedLeafId(messages),
122
122
  };
123
123
 
124
+ /** Rebuilds a failed send against the current thread: edits re-anchor at the source's current parent, sends whose target run is gone fall back to a fresh enqueue. */
125
+ export const retryCommand = (
126
+ messages: readonly { id: string; status?: { type: string } }[],
127
+ runId: string | null,
128
+ command:
129
+ | (StatewireThread.RunEnqueueCommand & {
130
+ message: StatewireThread.UserMessage;
131
+ })
132
+ | (StatewireThread.RunSteerCommand & {
133
+ message: StatewireThread.UserMessage;
134
+ })
135
+ | StatewireThread.RunEditCommand,
136
+ ): StatewireThread.RunCommand => {
137
+ if (command.type === "run/edit") {
138
+ const index = messages.findIndex((m) => m.id === command.sourceId);
139
+ if (index === -1)
140
+ throw new Error(
141
+ `statewire: run/edit source "${command.sourceId}" is unknown`,
142
+ );
143
+ return {
144
+ ...command,
145
+ runId: runId ?? crypto.randomUUID(),
146
+ runAnchorMessageId: messages[index - 1]?.id ?? null,
147
+ };
148
+ }
149
+ if (runId !== null && command.runId === runId) return command;
150
+ return {
151
+ type: "run/enqueue",
152
+ ...sendFields(messages, runId, command.message),
153
+ };
154
+ };
155
+
124
156
  export const createRunQueueAdapter = (
125
157
  messages: readonly { id: string }[],
126
158
  runId: string | null,