1111
1212 const duration = 200 ;
1313 const textLimit = 1024 ;
14- const actionLimit = 10 ;
1514
1615 /** @type {import('$agentTypes').AgentRule} */
1716 export let rule;
3130 /** @type {any[]} */
3231 export let criteriaOptions = [];
3332
34- /** @type {any[]} */
35- export let actionOptions = [];
36-
3733 /** @type {number} */
3834 export let windowWidth;
3935
6258 });
6359 }
6460
65- /**
66- * @param {any} e
67- * @param {string} field
68- * @param {number} idx
69- */
70- function toggleRuleAction (e , field , idx ) {
71- svelteDispatch (' toggle' , {
72- ruleIdx: ruleIndex,
73- field: field,
74- itemIdx: idx,
75- checked: e .target .checked
76- });
77- }
78-
79- /**
80- * @param {any} e
81- * @param {string} field
82- * @param {number} idx
83- */
84- function changeRuleAction (e , field , idx ) {
85- svelteDispatch (' change' , {
86- ruleIdx: ruleIndex,
87- field: field,
88- itemIdx: idx,
89- value: e? .target ? .value || e? .detail ? .text || ' '
90- });
91- }
92-
93- /**
94- * @param {string} field
95- */
96- function addRuleItem (field ) {
97- svelteDispatch (' add' , {
98- ruleIdx: ruleIndex,
99- field: field
100- });
101- }
102-
10361 /**
10462 * @param {string} field
10563 */
11068 });
11169 }
11270
113- /**
114- * @param {string} field
115- * @param {number} idx
116- */
117- function deleteRuleItem (field , idx ) {
118- svelteDispatch (' delete' , {
119- ruleIdx: ruleIndex,
120- field: field,
121- itemIdx: idx
122- });
123- }
124-
12571 function toggleCollapse () {
12672 svelteDispatch (' collapse' , {
12773 ruleIdx: ruleIndex,
343289 {/ if }
344290 < / div>
345291 < / div>
346-
347- < div class = " utility-row utility-row-secondary" transition: slide= {{ duration: duration }}>
348- {#each rule .rule_actions || [] as action, aid (aid)}
349- < div class = " utility-content" style= {` ${ aid > 0 ? ' border-top-style: none' : ' ' } ` }>
350- < div class = " utility-list-item" >
351- < div class = " utility-label line-align-center" >
352- < div class = " d-flex gap-1" >
353- < div class = " line-align-center" >
354- {` Action #${ aid + 1 } ` }
355- < / div>
356- < div class = " line-align-center" >
357- < Input
358- type= " checkbox"
359- checked= {! action? .disabled }
360- on: change= {e => toggleRuleAction (e, ' action' , aid)}
361- / >
362- < / div>
363- < / div>
364- < / div>
365- < div class = " utility-value" >
366- < div class = " utility-input line-align-center" >
367- < Input
368- type= " select"
369- disabled= {!! action? .disabled }
370- on: change= {e => changeRuleAction (e, ' action' , aid)}
371- >
372- {#each [... actionOptions] as option}
373- < option value= {` ${ option .name } #${ option .defaultConfig } ` } selected= {option .name == action? .name }>
374- {option .name }
375- < / option>
376- {/ each}
377- < / Input>
378- < / div>
379- < div class = " utility-delete line-align-center" >
380- < i
381- class = " bx bxs-no-entry text-danger clickable fs-6"
382- role= " link"
383- tabindex= " 0"
384- on: keydown= {() => {}}
385- on: click= {() => deleteRuleItem (' action' , aid)}
386- / >
387- < / div>
388- < / div>
389- < / div>
390- {#if action? .name }
391- < div class = " utility-list-item" >
392- < div class = " utility-label line-align-center" >
393- < div class = " d-flex gap-1" >
394- < div class = " line-align-center" >
395- {' Skipping' }
396- < / div>
397- < / div>
398- < / div>
399- < div class = " utility-value" >
400- < div class = " utility-input line-align-center" >
401- < Input
402- type= " text"
403- disabled= {!! action? .disabled }
404- maxlength= {4096 }
405- value= {action? .skippingExpression }
406- on: input= {e => changeRuleAction (e, ' action-skipping-expression' , aid)}
407- / >
408- < / div>
409- < div class = " utility-delete line-align-center" >< / div>
410- < / div>
411- < / div>
412- < div class = " utility-list-item" >
413- < div class = " utility-label line-align-center" >
414- < div class = " d-flex gap-1" >
415- < div class = " line-align-center" >
416- {' Config' }
417- < / div>
418- < / div>
419- < / div>
420- < div class = " utility-value" >
421- < div class = " utility-input line-align-center" >
422- < CodeScript
423- language= " json"
424- containerClasses= " agent-rule-config"
425- hideLineNumber= {true }
426- editable= {! action? .disabled }
427- scriptText= {JSON .stringify (action? .config || {}, null , 2 )}
428- on: change= {(e ) => changeRuleAction (e, ' action-config' , aid)}
429- / >
430- < / div>
431- < div class = " utility-delete line-align-center" >< / div>
432- < / div>
433- < / div>
434- {/ if }
435- < / div>
436- {/ each}
437-
438- {#if rule .rule_actions ? .length < actionLimit}
439- < div class = " utility-content" style= " border-top: none;" >
440- < div class = " utility-list-item" >
441- < div class = " utility-label" >
442- {rule .rule_actions .length === 0 ? ' Actions' : ' ' }
443- < / div>
444- < div class = " utility-value" >
445- < i
446- class = " bx bx-list-plus add-list clickable fs-6"
447- data- bs- toggle= " tooltip"
448- data- bs- placement= " top"
449- title= " Add action"
450- role= " link"
451- tabindex= " 0"
452- on: keydown= {() => {}}
453- on: click= {() => addRuleItem (' action' )}
454- / >
455- < / div>
456- < / div>
457- < / div>
458- {/ if }
459- < / div>
460292 {/ if }
461293< / div>
0 commit comments