Fragments: support placeholders with purpose

This commit is contained in:
Enrico Ros
2025-02-23 03:15:27 -08:00
parent ccdcd24d22
commit 5557de6dc3
2 changed files with 7 additions and 7 deletions
+6 -6
View File
@@ -153,7 +153,7 @@ type DMessageToolEnvironment = 'upstream' | 'server' | 'client';
type DVoidModelAuxPart = { pt: 'ma', aType: 'reasoning' | string, aText: string };
type DVoidPlaceholderPart = { pt: 'ph', pText: string };
type DVoidPlaceholderPart = { pt: 'ph', pText: string, pType?: 'chat-gen-follow-up', /* 2025-02-23: added for non-pure-text placeholders */ };
type _SentinelPart = { pt: '_pt_sentinel' };
@@ -292,8 +292,8 @@ export function createModelAuxVoidFragment(aType: DVoidModelAuxPart['aType'], aT
return _createVoidFragment(_create_ModelAux_Part(aType, aText));
}
export function createPlaceholderVoidFragment(placeholderText: string): DMessageVoidFragment {
return _createVoidFragment(_create_Placeholder_Part(placeholderText));
export function createPlaceholderVoidFragment(placeholderText: string, placeholderType?: DVoidPlaceholderPart['pType']): DMessageVoidFragment {
return _createVoidFragment(_create_Placeholder_Part(placeholderText, placeholderType));
}
function _createVoidFragment(part: DMessageVoidFragment['part']): DMessageVoidFragment {
@@ -372,8 +372,8 @@ function _create_ModelAux_Part(aType: DVoidModelAuxPart['aType'], aText: string)
return { pt: 'ma', aType, aText };
}
function _create_Placeholder_Part(placeholderText: string): DVoidPlaceholderPart {
return { pt: 'ph', pText: placeholderText };
function _create_Placeholder_Part(placeholderText: string, pType?: DVoidPlaceholderPart['pType']): DVoidPlaceholderPart {
return { pt: 'ph', pText: placeholderText, ...(pType ? { pType } : undefined) };
}
function _create_Sentinel_Part(): _SentinelPart {
@@ -396,7 +396,7 @@ function _duplicate_Part<TPart extends (DMessageContentFragment | DMessageAttach
return _create_ModelAux_Part(part.aType, part.aText) as TPart;
case 'ph':
return _create_Placeholder_Part(part.pText) as TPart;
return _create_Placeholder_Part(part.pText, part.pType) as TPart;
case 'text':
return _create_Text_Part(part.text) as TPart;
+1 -1
View File
@@ -112,7 +112,7 @@ export function createDMessageTextContent(role: DMessageRole, text: string): DMe
}
export function createDMessagePlaceholderIncomplete(role: DMessageRole, placeholderText: string): DMessage {
const placeholderFragment = createPlaceholderVoidFragment(placeholderText);
const placeholderFragment = createPlaceholderVoidFragment(placeholderText, undefined);
const message = createDMessageFromFragments(role, [placeholderFragment]);
message.pendingIncomplete = true;
return message;