SimpleChatTC:ShowObjPropsEdit:Any depth trapping of ui setup

Maintain the current property hierarchy to its root over recursive
calls.

Allow callers to specify the props to be trapped using the prop
hierarchy.

Pass the prop hierarchy to the fTrapper.

This should allow one to trap any prop wrt its editing ui setup,
irrespective of whether it is a prop of the main object passed,
or a member of a child prop of the main object passed or so ...

Update the setting up of ChatHistoryInCtxt and ApiEndPoint to follow
the new semantic/flow.
This commit is contained in:
hanishkvc 2025-10-21 22:15:58 +05:30
parent b19e754322
commit 8d7eb68712
2 changed files with 14 additions and 12 deletions

View File

@ -1110,20 +1110,20 @@ class Me {
* @param {HTMLDivElement} elDiv * @param {HTMLDivElement} elDiv
*/ */
show_settings(elDiv) { show_settings(elDiv) {
ui.ui_show_obj_props_edit(elDiv, this, ["baseURL", "headers", "bStream", "tools", "apiRequestOptions", "TRAPME-apiEP", "TRAPME-iRecentUserMsgCnt", "bTrimGarbage", "bCompletionFreshChatAlways", "bCompletionInsertStandardRolePrefix"], "Settings", (prop, elProp)=>{ ui.ui_show_obj_props_edit(elDiv, "", this, ["baseURL", "headers", "bStream", "tools", "apiRequestOptions", "TRAPME-apiEP", "TRAPME-iRecentUserMsgCnt", "bTrimGarbage", "bCompletionFreshChatAlways", "bCompletionInsertStandardRolePrefix"], "Settings", (prop, elProp)=>{
if (prop == "headers:Authorization") { if (prop == "headers:Authorization") {
// @ts-ignore // @ts-ignore
elProp.placeholder = "Bearer OPENAI_API_KEY"; elProp.placeholder = "Bearer OPENAI_API_KEY";
} }
}, "TRAPME-", (tag, elParent)=>{ }, ["apiEP", "iRecentUserMsgCnt"], (propWithPath, prop, elParent)=>{
if (tag == "TRAPME-apiEP") { if (propWithPath == "apiEP") {
let sel = ui.el_creatediv_select("SetApiEP", "ApiEndPoint", ApiEP.Type, this.apiEP, (val)=>{ let sel = ui.el_creatediv_select("SetApiEP", "ApiEndPoint", ApiEP.Type, this.apiEP, (val)=>{
// @ts-ignore // @ts-ignore
this.apiEP = ApiEP.Type[val]; this.apiEP = ApiEP.Type[val];
}); });
elParent.appendChild(sel.div); elParent.appendChild(sel.div);
} }
if (tag == "TRAPME-iRecentUserMsgCnt") { if (propWithPath == "iRecentUserMsgCnt") {
let sel = ui.el_creatediv_select("SetChatHistoryInCtxt", "ChatHistoryInCtxt", this.sRecentUserMsgCnt, this.iRecentUserMsgCnt, (val)=>{ let sel = ui.el_creatediv_select("SetChatHistoryInCtxt", "ChatHistoryInCtxt", this.sRecentUserMsgCnt, this.iRecentUserMsgCnt, (val)=>{
this.iRecentUserMsgCnt = this.sRecentUserMsgCnt[val]; this.iRecentUserMsgCnt = this.sRecentUserMsgCnt[val];
}); });

View File

@ -246,14 +246,15 @@ export function el_creatediv_input(id, label, type, defaultValue, cb, className=
* * fTrapper will be called with the parent ui element * * fTrapper will be called with the parent ui element
* into which the new ui elements created for editting the prop, if any, should be attached * into which the new ui elements created for editting the prop, if any, should be attached
* @param {HTMLDivElement|HTMLFieldSetElement} elParent * @param {HTMLDivElement|HTMLFieldSetElement} elParent
* @param {string} propsTreeRoot
* @param {any} oObj * @param {any} oObj
* @param {Array<string>} lProps * @param {Array<string>} lProps
* @param {string} sLegend * @param {string} sLegend
* @param {((prop:string, elProp: HTMLElement)=>void)| undefined} fRefiner * @param {((prop:string, elProp: HTMLElement)=>void)| undefined} fRefiner
* @param {string | undefined} sTrapTag * @param {Array<string> | undefined} lTrapThese
* @param {((tagPlusProp: string, elParent: HTMLFieldSetElement)=>void) | undefined} fTrapper * @param {((propWithPath: string, prop: string, elParent: HTMLFieldSetElement)=>void) | undefined} fTrapper
*/ */
export function ui_show_obj_props_edit(elParent, oObj, lProps, sLegend, fRefiner=undefined, sTrapTag=undefined, fTrapper=undefined) { export function ui_show_obj_props_edit(elParent, propsTreeRoot, oObj, lProps, sLegend, fRefiner=undefined, lTrapThese=undefined, fTrapper=undefined) {
let typeDict = { let typeDict = {
"string": "text", "string": "text",
"number": "number", "number": "number",
@ -264,10 +265,11 @@ export function ui_show_obj_props_edit(elParent, oObj, lProps, sLegend, fRefiner
elFS.appendChild(elLegend); elFS.appendChild(elLegend);
elParent.appendChild(elFS); elParent.appendChild(elFS);
for(const k of lProps) { for(const k of lProps) {
if (sTrapTag) { let propsTreeRootNew = `${propsTreeRoot}:${k}`
if (k.startsWith(sTrapTag)) { if (lTrapThese) {
if (propsTreeRootNew in lTrapThese) {
if (fTrapper) { if (fTrapper) {
fTrapper(k, elFS) fTrapper(propsTreeRootNew, k, elFS)
} }
continue continue
} }
@ -294,12 +296,12 @@ export function ui_show_obj_props_edit(elParent, oObj, lProps, sLegend, fRefiner
} }
elFS.appendChild(bbtn.div); elFS.appendChild(bbtn.div);
} else if (type == "object") { } else if (type == "object") {
ui_show_obj_props_edit(elFS, val, Object.keys(val), k, (prop, elProp)=>{ ui_show_obj_props_edit(elFS, propsTreeRootNew, val, Object.keys(val), k, (prop, elProp)=>{
if (fRefiner) { if (fRefiner) {
let theProp = `${k}:${prop}` let theProp = `${k}:${prop}`
fRefiner(theProp, elProp) fRefiner(theProp, elProp)
} }
}) }, lTrapThese, fTrapper)
} }
} }
} }