text stringlengths 0 1.47k |
|---|
* @param host - the client context, read through optional `get`. |
* @returns whether finished turns currently fold, observed live. |
*/ |
function foldingSource(host) { |
const forms = host.get("configForms"); |
if (hasMethod(forms, "get")) return observe(forms.get(CHAT_NAMESPACE), configFormsFolds); |
const scope = host.get("settingsScope"); |
if (hasMethod(scope, "bind")) return observe(scope.bind({ namespace: CHAT_NAMESPACE }), settingsScopeFolds); |
return { |
getSnapshot: () => false, |
subscribe: () => () => void 0 |
}; |
} |
//#endregion |
//#region src/client/TurnCards.tsx |
/** Definition kind and Turn data key; namespaced by package to stay unique. */ |
const TURN_CARDS_KEY = "dsh-visualize"; |
/** |
* Accept a successful root `visualize` result. The persisted meta names its |
* own kind, so no call-to-name bookkeeping is needed. |
* @param data - `tool/result` payload. |
* @returns the card descriptor, or undefined when unrelated or failed. |
*/ |
function resultMeta(data) { |
return data.message.isError === true ? void 0 : visualizeMetaFrom(data.meta); |
} |
/** |
* Fold one result into the turn's cards. A repeated call id (a later surface |
* replacement of the same result) keeps the first; a later card at an existing |
* path (an `update` patch) replaces that card in place, so a corrected card is |
* shown once, in its original position. |
* @param cards - cards so far. |
* @param card - the incoming card. |
* @returns the next card list, or the same list when unchanged. |
*/ |
function foldCard(cards, card) { |
if (cards.some((existing) => existing.callId === card.callId)) return cards; |
const index = cards.findIndex((existing) => existing.meta.path === card.meta.path); |
if (index === -1) return [...cards, card]; |
return cards.map((existing, at) => at === index ? card : existing); |
} |
/** Turn-local visualize accumulator; it publishes Turn data and no view Node. */ |
const turnCardsDefinition = { |
kind: TURN_CARDS_KEY, |
match: (event) => { |
if (event.type === "turn/start") return { |
id: String(event.data.turn), |
role: "start" |
}; |
if (event.type !== "tool/result") return null; |
const data = event.data; |
return resultMeta(data) === void 0 ? null : { |
id: String(data.turn), |
role: "update" |
}; |
}, |
start: (_context, match) => { |
if (match.event.type !== "turn/start") throw new Error("dsh-visualize: turn cards start requires turn/start"); |
return { |
turn: match.event.data.turn, |
cards: [] |
}; |
}, |
update: (context, match) => { |
if (match.event.type !== "tool/result") return context.state; |
const data = match.event.data; |
const meta = resultMeta(data); |
if (meta === void 0) return context.state; |
const cards = foldCard(context.state.cards, { |
callId: String(data.message.source.callId), |
seq: match.event.seq, |
meta |
}); |
return cards === context.state.cards ? context.state : { |
...context.state, |
cards |
}; |
}, |
buildLocationData: (context, scope, previous) => { |
if (scope !== "turn" || context.state === void 0) return null; |
const { turn, cards } = context.state; |
if (previous?.kind === "turn" && previous.turn === turn && previous.key === "dsh-visualize" && previous.value.cards === cards) return previous; |
return { |
kind: "turn", |
turn, |
key: TURN_CARDS_KEY, |
value: { cards } |
}; |
} |
}; |
/** |
* The cards settled before the turn's closing reply. |
* @param turn - the closing turn; older hosts may omit its data store. |
* @param seq - the closing assistant message's sequence number. |
* @returns the cards to show, possibly empty. |
*/ |
function cardsBefore(turn, seq) { |
return (turn?.data?.get("dsh-visualize")?.cards ?? []).filter((card) => card.seq < seq); |
} |
/** |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.