|
23 | 23 | Code, |
24 | 24 | Save, |
25 | 25 | X, |
26 | | - Check |
| 26 | + Check, |
| 27 | + Settings2 |
27 | 28 | } from 'lucide-svelte' |
28 | 29 | import CaptureIcon from '$lib/components/triggers/CaptureIcon.svelte' |
29 | 30 | import FlowInputEditor from './FlowInputEditor.svelte' |
|
84 | 85 |
|
85 | 86 | // Detect if we're in "review mode" (AI has made schema changes that are pending) |
86 | 87 | const hasAiSchemaChanges = $derived( |
87 | | - Boolean(diffManager?.moduleActions[SPECIAL_MODULE_IDS.INPUT]?.pending && diffManager?.beforeFlow?.schema) |
| 88 | + Boolean( |
| 89 | + diffManager?.moduleActions[SPECIAL_MODULE_IDS.INPUT]?.pending && |
| 90 | + diffManager?.beforeFlow?.schema |
| 91 | + ) |
88 | 92 | ) |
89 | 93 |
|
90 | 94 | let chatInputEnabled = $state(Boolean(flowStore.val.value?.chat_input_enabled)) |
|
98 | 102 | ) |
99 | 103 | }) |
100 | 104 | let showChatModeWarning = $state(false) |
| 105 | + let showAdditionalInputs = $state(false) |
| 106 | + let chatInputsEditTab = $state(false) |
| 107 | + let chatInputsAddPropertyV2: AddPropertyV2 | undefined = $state(undefined) |
101 | 108 |
|
102 | 109 | let addPropertyV2: AddPropertyV2 | undefined = $state(undefined) |
103 | 110 | let previewSchema: Record<string, any> | undefined = $state(undefined) |
|
435 | 442 | const parentPath = path.slice(0, -1) |
436 | 443 |
|
437 | 444 | const getSchemaAtPath = (schema: Record<string, any>) => |
438 | | - parentPath.length === 0 |
439 | | - ? schema |
440 | | - : getNestedProperty(schema, parentPath, 'properties') |
| 445 | + parentPath.length === 0 ? schema : getNestedProperty(schema, parentPath, 'properties') |
441 | 446 |
|
442 | 447 | const getProperties = (schema: Record<string, any>) => getSchemaAtPath(schema)?.properties |
443 | 448 |
|
|
457 | 462 | if (targetProperties && arg.label in targetProperties) { |
458 | 463 | delete targetProperties[arg.label] |
459 | 464 | if (targetSchemaAtPath?.order) { |
460 | | - targetSchemaAtPath.order = targetSchemaAtPath.order.filter( |
461 | | - (x: string) => x !== arg.label |
462 | | - ) |
| 465 | + targetSchemaAtPath.order = targetSchemaAtPath.order.filter((x: string) => x !== arg.label) |
463 | 466 | } |
464 | 467 | } |
465 | 468 | } |
|
502 | 505 |
|
503 | 506 | async function runFlowWithMessage( |
504 | 507 | message: string, |
505 | | - conversationId: string |
| 508 | + conversationId: string, |
| 509 | + additionalInputs?: Record<string, any> |
506 | 510 | ): Promise<string | undefined> { |
507 | | - previewArgs.val = { user_message: message } |
| 511 | + previewArgs.val = { |
| 512 | + user_message: message, |
| 513 | + ...(additionalInputs ?? {}) |
| 514 | + } |
508 | 515 | const jobId = await onTestFlow?.(conversationId) |
509 | 516 | return jobId |
510 | 517 | } |
|
641 | 648 | <FlowCard {noEditor} title="Flow Input"> |
642 | 649 | {#snippet action()} |
643 | 650 | {#if !disabled} |
644 | | - <Toggle |
645 | | - size="sm" |
646 | | - bind:checked={chatInputEnabled} |
647 | | - on:change={() => { |
648 | | - handleToggleChatMode() |
649 | | - }} |
650 | | - options={{ |
651 | | - right: 'Chat Mode', |
652 | | - rightTooltip: |
653 | | - 'When enabled, the flow execution page will show a chat interface where each message sent runs the flow with the message as "user_message" input parameter. The flow schema will be automatically set to accept only a user_message string input.' |
654 | | - }} |
655 | | - /> |
| 651 | + <div class="flex items-center gap-2"> |
| 652 | + <Toggle |
| 653 | + size="sm" |
| 654 | + bind:checked={chatInputEnabled} |
| 655 | + on:change={() => { |
| 656 | + handleToggleChatMode() |
| 657 | + }} |
| 658 | + options={{ |
| 659 | + right: 'Chat Mode', |
| 660 | + rightTooltip: |
| 661 | + 'When enabled, the flow execution page will show a chat interface where each message sent runs the flow with the message as "user_message" input parameter. The flow schema will be automatically set to accept only a user_message string input.' |
| 662 | + }} |
| 663 | + /> |
| 664 | + {#if flowStore.val.value?.chat_input_enabled} |
| 665 | + <Button |
| 666 | + size="xs" |
| 667 | + variant="border" |
| 668 | + color={showAdditionalInputs ? 'blue' : 'light'} |
| 669 | + startIcon={{ icon: Settings2 }} |
| 670 | + title="Manage inputs" |
| 671 | + on:click={() => (showAdditionalInputs = !showAdditionalInputs)} |
| 672 | + > |
| 673 | + Manage inputs |
| 674 | + </Button> |
| 675 | + {/if} |
| 676 | + </div> |
656 | 677 | {/if} |
657 | 678 | {/snippet} |
658 | 679 | {#if !disabled} |
659 | 680 | <div class="flex flex-col h-full"> |
660 | 681 | {#if flowStore.val.value?.chat_input_enabled} |
661 | 682 | <div class="flex flex-col h-full"> |
| 683 | + {#if showAdditionalInputs} |
| 684 | + <div class="border-b p-2"> |
| 685 | + <EditableSchemaForm |
| 686 | + bind:schema={flowStore.val.schema} |
| 687 | + hiddenArgs={['user_message']} |
| 688 | + isFlowInput |
| 689 | + editTab={chatInputsEditTab ? 'inputEditor' : undefined} |
| 690 | + showDynOpt |
| 691 | + bind:dynCode |
| 692 | + bind:dynLang |
| 693 | + on:delete={(e) => { |
| 694 | + chatInputsAddPropertyV2?.handleDeleteArgument([e.detail]) |
| 695 | + }} |
| 696 | + > |
| 697 | + {#snippet openEditTab()} |
| 698 | + <Button |
| 699 | + size="xs" |
| 700 | + variant={chatInputsEditTab ? 'contained' : 'border'} |
| 701 | + color={chatInputsEditTab ? 'blue' : 'light'} |
| 702 | + startIcon={{ icon: chatInputsEditTab ? ChevronRight : Pen }} |
| 703 | + title={chatInputsEditTab ? 'Close editor' : 'Edit inputs'} |
| 704 | + onClick={() => { |
| 705 | + chatInputsEditTab = !chatInputsEditTab |
| 706 | + }} |
| 707 | + /> |
| 708 | + {/snippet} |
| 709 | + {#snippet addProperty()} |
| 710 | + <AddPropertyV2 |
| 711 | + bind:this={chatInputsAddPropertyV2} |
| 712 | + bind:schema={flowStore.val.schema} |
| 713 | + onAddNew={() => {}} |
| 714 | + > |
| 715 | + {#snippet trigger()} |
| 716 | + <Button |
| 717 | + size="xs" |
| 718 | + color="light" |
| 719 | + startIcon={{ icon: Plus }} |
| 720 | + title="Add additional input" |
| 721 | + > |
| 722 | + Add input |
| 723 | + </Button> |
| 724 | + {/snippet} |
| 725 | + </AddPropertyV2> |
| 726 | + {/snippet} |
| 727 | + </EditableSchemaForm> |
| 728 | + </div> |
| 729 | + {/if} |
662 | 730 | <FlowChat |
663 | 731 | onRunFlow={runFlowWithMessage} |
664 | 732 | path={$pathStore} |
665 | 733 | hideSidebar={true} |
666 | 734 | useStreaming={shouldUseStreaming} |
| 735 | + inputSchema={flowStore.val.schema} |
667 | 736 | /> |
668 | 737 | </div> |
669 | 738 | {:else} |
|
756 | 825 | disabled={!previewSchema} |
757 | 826 | shortCut={{ Icon: CornerDownLeft, hide: false, withoutModifier: true }} |
758 | 827 | startIcon={{ icon: Check }} |
759 | | - on:click={() => { |
| 828 | + onClick={() => { |
760 | 829 | applySchemaAndArgs() |
761 | 830 | connectFirstNode() |
762 | 831 | }} |
|
774 | 843 | size="xs" |
775 | 844 | startIcon={{ icon: X }} |
776 | 845 | shortCut={{ key: 'esc', withoutModifier: true }} |
777 | | - on:click={() => { |
| 846 | + onClick={() => { |
778 | 847 | if (hasAiSchemaChanges) { |
779 | 848 | if (diffManager?.beforeFlow?.schema) { |
780 | 849 | diffManager.rejectModule(SPECIAL_MODULE_IDS.INPUT, flowStore) |
|
928 | 997 | disabled={runDisabled || !isValid} |
929 | 998 | size="xs" |
930 | 999 | shortCut={{ Icon: CornerDownLeft, hide: false }} |
931 | | - on:click={() => { |
| 1000 | + onClick={() => { |
932 | 1001 | runPreview() |
933 | 1002 | }} |
934 | 1003 | > |
|
0 commit comments