@shaxpir/duiduidui-models 1.25.4 → 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 +14 -2
- package/dist/models/Chat.js +31 -1
- package/package.json +1 -1
package/dist/models/Chat.d.ts
CHANGED
|
@@ -31,8 +31,9 @@ export interface ThinkingBlock {
|
|
|
31
31
|
thinking: string;
|
|
32
32
|
}
|
|
33
33
|
export type ContentBlock = TextBlock | ImageBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock;
|
|
34
|
+
export type CacheTTL = 'ephemeral_5m' | 'ephemeral_1h';
|
|
34
35
|
export interface CacheBreakpoint {
|
|
35
|
-
ttl:
|
|
36
|
+
ttl: CacheTTL;
|
|
36
37
|
created_at: CompactDateTime;
|
|
37
38
|
expires_at: CompactDateTime;
|
|
38
39
|
}
|
|
@@ -78,6 +79,10 @@ export interface ChatError {
|
|
|
78
79
|
code?: string;
|
|
79
80
|
retryable: boolean;
|
|
80
81
|
}
|
|
82
|
+
export interface ChatCacheBreakpoints {
|
|
83
|
+
system_prompt?: CacheBreakpoint;
|
|
84
|
+
tools?: CacheBreakpoint;
|
|
85
|
+
}
|
|
81
86
|
export interface ChatPayload {
|
|
82
87
|
title?: string;
|
|
83
88
|
participants: SocialUser[];
|
|
@@ -87,6 +92,7 @@ export interface ChatPayload {
|
|
|
87
92
|
};
|
|
88
93
|
status: ChatStatus;
|
|
89
94
|
error?: ChatError;
|
|
95
|
+
cache_breakpoints?: ChatCacheBreakpoints;
|
|
90
96
|
}
|
|
91
97
|
export interface ChatBody extends ContentBody {
|
|
92
98
|
meta: ContentMeta;
|
|
@@ -123,7 +129,13 @@ export declare class Chat extends SharedContent {
|
|
|
123
129
|
hasUnread(userId: ContentId): boolean;
|
|
124
130
|
toStub(): ChatStub;
|
|
125
131
|
appendMessage(message: ChatMessage): void;
|
|
126
|
-
setBreakpoint(messageIndex: number, ttl:
|
|
132
|
+
setBreakpoint(messageIndex: number, ttl: CacheTTL): void;
|
|
127
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;
|
|
128
140
|
clearExpiredBreakpoints(): void;
|
|
129
141
|
}
|
package/dist/models/Chat.js
CHANGED
|
@@ -197,7 +197,7 @@ class Chat extends SharedContent_1.SharedContent {
|
|
|
197
197
|
if (messageIndex < 0 || messageIndex >= this._messagesView.length)
|
|
198
198
|
return;
|
|
199
199
|
const now = shaxpir_common_1.ClockService.getClock().utc();
|
|
200
|
-
const durationMinutes = ttl === '
|
|
200
|
+
const durationMinutes = ttl === 'ephemeral_5m' ? 5 : 60;
|
|
201
201
|
const expiresAt = shaxpir_common_1.Time.plus(now, durationMinutes, 'minutes');
|
|
202
202
|
const breakpoint = {
|
|
203
203
|
ttl,
|
|
@@ -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;
|