@shaxpir/duiduidui-models 1.25.5 → 1.25.6
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/dist/models/Chat.d.ts +11 -0
- package/dist/models/Chat.js +30 -0
- package/package.json +1 -1
package/dist/models/Chat.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/models/Chat.js
CHANGED
|
@@ -212,15 +212,45 @@ 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
|
+
batch.setPathValue(['payload', 'cache_breakpoints', target], breakpoint);
|
|
227
|
+
batch.commit();
|
|
228
|
+
}
|
|
229
|
+
get cacheBreakpoints() {
|
|
230
|
+
return this.payload?.cache_breakpoints;
|
|
231
|
+
}
|
|
215
232
|
clearExpiredBreakpoints() {
|
|
216
233
|
this.checkDisposed('Chat.clearExpiredBreakpoints');
|
|
217
234
|
const now = shaxpir_common_1.ClockService.getClock().utc();
|
|
235
|
+
// Clear expired message-level breakpoints
|
|
218
236
|
for (let i = 0; i < this._messagesView.length; i++) {
|
|
219
237
|
const message = this._messagesView.get(i);
|
|
220
238
|
if (message.cache_breakpoint && shaxpir_common_1.Time.isDateTimeBefore(message.cache_breakpoint.expires_at, now)) {
|
|
221
239
|
this._messagesView.removeObjectPropertyAtIndex(i, 'cache_breakpoint');
|
|
222
240
|
}
|
|
223
241
|
}
|
|
242
|
+
// Clear expired conversation-level breakpoints
|
|
243
|
+
const cb = this.payload?.cache_breakpoints;
|
|
244
|
+
if (cb) {
|
|
245
|
+
const batch = new Operation_1.BatchOperation(this);
|
|
246
|
+
if (cb.system_prompt && shaxpir_common_1.Time.isDateTimeBefore(cb.system_prompt.expires_at, now)) {
|
|
247
|
+
batch.removeValueAtPath(['payload', 'cache_breakpoints', 'system_prompt']);
|
|
248
|
+
}
|
|
249
|
+
if (cb.tools && shaxpir_common_1.Time.isDateTimeBefore(cb.tools.expires_at, now)) {
|
|
250
|
+
batch.removeValueAtPath(['payload', 'cache_breakpoints', 'tools']);
|
|
251
|
+
}
|
|
252
|
+
batch.commit();
|
|
253
|
+
}
|
|
224
254
|
}
|
|
225
255
|
}
|
|
226
256
|
exports.Chat = Chat;
|