@shaxpir/duiduidui-models 1.25.5 → 1.25.7

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.
@@ -79,6 +79,10 @@ export interface ChatError {
79
79
  code?: string;
80
80
  retryable: boolean;
81
81
  }
82
+ export interface ChatCacheBreakpoints {
83
+ system_prompt?: CacheBreakpoint;
84
+ tools?: CacheBreakpoint;
85
+ }
82
86
  export interface ChatPayload {
83
87
  title?: string;
84
88
  participants: SocialUser[];
@@ -88,6 +92,7 @@ export interface ChatPayload {
88
92
  };
89
93
  status: ChatStatus;
90
94
  error?: ChatError;
95
+ cache_breakpoints?: ChatCacheBreakpoints;
91
96
  }
92
97
  export interface ChatBody extends ContentBody {
93
98
  meta: ContentMeta;
@@ -126,5 +131,11 @@ export declare class Chat extends SharedContent {
126
131
  appendMessage(message: ChatMessage): void;
127
132
  setBreakpoint(messageIndex: number, ttl: CacheTTL): void;
128
133
  removeBreakpoint(messageIndex: number): void;
134
+ /**
135
+ * Set a cache breakpoint for the system prompt or tools at the conversation level.
136
+ * These record that the server is using prompt caching for API calls in this chat.
137
+ */
138
+ setCacheBreakpoint(target: 'system_prompt' | 'tools', ttl: CacheTTL): void;
139
+ get cacheBreakpoints(): ChatCacheBreakpoints | undefined;
129
140
  clearExpiredBreakpoints(): void;
130
141
  }
@@ -212,15 +212,53 @@ class Chat extends SharedContent_1.SharedContent {
212
212
  return;
213
213
  this._messagesView.removeObjectPropertyAtIndex(messageIndex, 'cache_breakpoint');
214
214
  }
215
+ /**
216
+ * Set a cache breakpoint for the system prompt or tools at the conversation level.
217
+ * These record that the server is using prompt caching for API calls in this chat.
218
+ */
219
+ setCacheBreakpoint(target, ttl) {
220
+ this.checkDisposed('Chat.setCacheBreakpoint');
221
+ const now = shaxpir_common_1.ClockService.getClock().utc();
222
+ const durationMinutes = ttl === 'ephemeral_5m' ? 5 : 60;
223
+ const expiresAt = shaxpir_common_1.Time.plus(now, durationMinutes, 'minutes');
224
+ const breakpoint = { ttl, created_at: now, expires_at: expiresAt };
225
+ const batch = new Operation_1.BatchOperation(this);
226
+ // If cache_breakpoints doesn't exist on the payload yet, create the
227
+ // entire object in one operation. OT can't insert into a non-existent
228
+ // parent, so we must create the parent first.
229
+ if (!this.payload.cache_breakpoints) {
230
+ batch.setPathValue(['payload', 'cache_breakpoints'], { [target]: breakpoint });
231
+ }
232
+ else {
233
+ batch.setPathValue(['payload', 'cache_breakpoints', target], breakpoint);
234
+ }
235
+ batch.commit();
236
+ }
237
+ get cacheBreakpoints() {
238
+ return this.payload?.cache_breakpoints;
239
+ }
215
240
  clearExpiredBreakpoints() {
216
241
  this.checkDisposed('Chat.clearExpiredBreakpoints');
217
242
  const now = shaxpir_common_1.ClockService.getClock().utc();
243
+ // Clear expired message-level breakpoints
218
244
  for (let i = 0; i < this._messagesView.length; i++) {
219
245
  const message = this._messagesView.get(i);
220
246
  if (message.cache_breakpoint && shaxpir_common_1.Time.isDateTimeBefore(message.cache_breakpoint.expires_at, now)) {
221
247
  this._messagesView.removeObjectPropertyAtIndex(i, 'cache_breakpoint');
222
248
  }
223
249
  }
250
+ // Clear expired conversation-level breakpoints
251
+ const cb = this.payload?.cache_breakpoints;
252
+ if (cb) {
253
+ const batch = new Operation_1.BatchOperation(this);
254
+ if (cb.system_prompt && shaxpir_common_1.Time.isDateTimeBefore(cb.system_prompt.expires_at, now)) {
255
+ batch.removeValueAtPath(['payload', 'cache_breakpoints', 'system_prompt']);
256
+ }
257
+ if (cb.tools && shaxpir_common_1.Time.isDateTimeBefore(cb.tools.expires_at, now)) {
258
+ batch.removeValueAtPath(['payload', 'cache_breakpoints', 'tools']);
259
+ }
260
+ batch.commit();
261
+ }
224
262
  }
225
263
  }
226
264
  exports.Chat = Chat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.25.5",
3
+ "version": "1.25.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"