150
return [{ ...first, message: { ...first.message, text: userPrompt } }, ...turns.slice(1)];
151
}
153
>
/**
154
>
* In-memory backing for an additional (non-default) peer chat. Records the SDK
155
>
* chat id that backs the chat so it can be re-resumed after a process restart,
156
>
* along with any model override chosen at creation time. This is also the shape
157
>
* serialized into the opaque, agent-owned `providerData` blob the orchestrator
158
>
* persists in its chat catalog and hands back on restore.
159
>
*/
160
>
export interface IPersistedChat {
161
>
readonly sdkSessionId: string;
162
>
readonly model?: ModelSelection;
163
>
readonly sideChat?: IPersistedSideChat;
164
>
}
165
>
166
>
export interface IResolvedAgentChat<TSession extends IDisposable> {
167
>
readonly chatSession: TSession;
168
>
readonly isDefault: boolean;
169
>
}
170
>
171
>
/**
172
>
* Serializes a peer-chat backing into the opaque `providerData` token the
173
>
* orchestrator persists verbatim. The encoding is the agent's private business
174
>
* — today it is the JSON of {@link IPersistedChat}.
175
>
*/
176
>
export function encodeProviderData(backing: IPersistedChat): string {
177
return JSON.stringify(backing);
178
}
180
>
/**
181
>
* Decodes an opaque `providerData` token produced by {@link encodeProviderData}
182
>
* back into a peer-chat backing, tolerating corrupt/foreign blobs by returning
183
>
* `undefined` (the same drop-on-corrupt policy as the legacy chat catalog read).
184
>
*/
185
>
export function decodeProviderData(providerData: string): IPersistedChat | undefined {
186
try {
187
const value = JSON.parse(providerData) as { sdkSessionId?: unknown; model?: unknown; sideChat?: unknown };