MCPcopy Create free account
hub / github.com/Noumena-Network/code / createPromptDraftController

Function createPromptDraftController

src/screens/promptDraftController.ts:26–102  ·  view source on GitHub ↗
(
  initialValue: string,
  initialOptions: PromptDraftControllerOptions,
)

Source from the content-addressed store, hash-verified

24const noopSubscribe = () => () => {}
25
26export function createPromptDraftController(
27 initialValue: string,
28 initialOptions: PromptDraftControllerOptions,
29): PromptDraftController {
30 let value = initialValue
31 let options = initialOptions
32 let suppressionTimer: ReturnType<typeof setTimeout> | null = null
33 const listeners = new Set<PromptDraftListener>()
34
35 const clearSuppressionTimer = () => {
36 if (suppressionTimer !== null) {
37 clearTimeout(suppressionTimer)
38 suppressionTimer = null
39 }
40 }
41
42 const notify = () => {
43 for (const listener of listeners) {
44 listener()
45 }
46 }
47
48 const setPromptSuppression = (nextValue: string) => {
49 const hasPromptText = nextValue.trim().length > 0
50 options.setPromptInputActive(hasPromptText)
51 clearSuppressionTimer()
52 if (!hasPromptText) {
53 return
54 }
55 suppressionTimer = setTimeout(() => {
56 options.setPromptInputActive(false)
57 suppressionTimer = null
58 }, options.promptSuppressionMs)
59 }
60
61 return {
62 destroy: () => {
63 clearSuppressionTimer()
64 listeners.clear()
65 },
66 getValue: () => value,
67 setOptions: nextOptions => {
68 options = nextOptions
69 },
70 setValue: nextValue => {
71 const prevValue = value
72 if (options.tryIntercept(prevValue, nextValue)) {
73 return
74 }
75
76 if (
77 prevValue === '' &&
78 nextValue !== '' &&
79 (options.shouldRepinScroll?.() ?? true) &&
80 Date.now() - options.getLastUserScrollTs() >=
81 options.recentScrollRepinWindowMs
82 ) {
83 options.repinScroll()

Callers 2

REPLFunction · 0.85

Calls 7

clearSuppressionTimerFunction · 0.85
recordLivePromptTraceFunction · 0.85
setPromptSuppressionFunction · 0.85
deleteMethod · 0.80
notifyFunction · 0.70
clearMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected