panel.svelte 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <script lang="ts">
  2. import { ChevronDown, ChevronUp, StickyNote } from '@lucide/svelte';
  3. import type { ClassValue } from 'svelte/elements';
  4. import { slide } from 'svelte/transition';
  5. import Empty from '$lib/components/common/empty/empty.svelte';
  6. import { Button } from '$lib/components/controls/button';
  7. import { Switch } from '$lib/components/controls/switch';
  8. import * as Table from '$lib/components/controls/table';
  9. import type { StackCR } from '$lib/types/custom-resources';
  10. import type { RuntimeTemplate, Stack } from '$lib/types/entities';
  11. interface StackComponent {
  12. name: string;
  13. label: string;
  14. description: string;
  15. getSpec: (stack: Stack) => { enabled: boolean; runtime?: RuntimeTemplate };
  16. getStatus: (status: StackCR['status']) => string;
  17. }
  18. let {
  19. class: className = '',
  20. stack,
  21. status,
  22. active = $bindable(false),
  23. onchange,
  24. }: {
  25. class?: ClassValue;
  26. stack: Stack;
  27. status?: StackCR['status'];
  28. active?: boolean;
  29. onchange?: (stack: Stack) => void;
  30. } = $props();
  31. const STACK_COMPONENTS: StackComponent[] = [
  32. {
  33. name: 'gateway',
  34. label: 'Gateway',
  35. description:
  36. 'Routing model calls, tool calls, and agent calls. Responsible for observability and cost management.',
  37. getSpec: (stack: Stack) => stack.gateway || { enabled: false },
  38. getStatus: (status: StackCR['status']) => status?.componentStatus?.gateway || 'disabled',
  39. },
  40. {
  41. name: 'vectorStore',
  42. label: 'Vector Store',
  43. description:
  44. 'Storing embeddings and performing vector searches. Required by knowledge bases.',
  45. getSpec: (stack: Stack) => stack.vectorStore || { enabled: false },
  46. getStatus: (status: StackCR['status']) => status?.componentStatus?.vectorStore || 'disabled',
  47. },
  48. {
  49. name: 'graphStore',
  50. label: 'Graph Store',
  51. description: 'Storing and querying graph data. Optionally required by knowledge bases.',
  52. getSpec: (stack: Stack) => stack.graphStore || { enabled: false },
  53. getStatus: (status: StackCR['status']) => status?.componentStatus?.graphStore || 'disabled',
  54. },
  55. {
  56. name: 'database',
  57. label: 'Database',
  58. description: 'Storing application data. Required by some gateway and observability features.',
  59. getSpec: (stack: Stack) => stack.database || { enabled: false },
  60. getStatus: (status: StackCR['status']) => status?.componentStatus?.database || 'disabled',
  61. },
  62. {
  63. name: 'observability',
  64. label: 'Observability',
  65. description: 'Monitoring and tracing agent calls.',
  66. getSpec: (stack: Stack) => stack.observability || { enabled: false },
  67. getStatus: (status: StackCR['status']) =>
  68. status?.componentStatus?.observability || 'disabled',
  69. },
  70. ];
  71. const onToggleComponent = (component: StackComponent) => {
  72. const enabled = component.getStatus(status) !== 'disabled';
  73. stack = {
  74. ...stack,
  75. [component.name]: {
  76. ...component.getSpec(stack),
  77. enabled: !enabled,
  78. },
  79. };
  80. onchange?.(stack);
  81. };
  82. </script>
  83. <div class={['overflow-hidden rounded-md border border-white/10', className]}>
  84. <div class="bg-white/5">
  85. <div class="flex items-center justify-between p-2">
  86. <div class="p-2 font-thin">{stack.name}</div>
  87. <div class="flex items-center gap-1">
  88. <Button size="icon-sm" variant="ghost" onclick={() => (active = !active)}>
  89. {#if active}
  90. <ChevronUp size={14} />
  91. {:else}
  92. <ChevronDown size={14} />
  93. {/if}
  94. </Button>
  95. </div>
  96. </div>
  97. </div>
  98. {#if active}
  99. <div class="overflow-hidden" transition:slide={{ duration: 200 }}>
  100. <Table.Root>
  101. <Table.Body>
  102. {#each STACK_COMPONENTS as component (component.name)}
  103. <Table.Row>
  104. <Table.Cell class="w-12">
  105. <Switch
  106. checked={component.getStatus(status) !== 'disabled'}
  107. onCheckedChange={() => onToggleComponent(component)}
  108. />
  109. </Table.Cell>
  110. <Table.Cell class="w-32 text-right text-white/75">
  111. {component.label}
  112. </Table.Cell>
  113. <Table.Cell>
  114. {@const componentStatus = component.getStatus(status)}
  115. {#if componentStatus === 'disabled'}
  116. <span class="text-white/50">Disabled</span>
  117. {:else}
  118. <span>{component.getStatus(status)}</span>
  119. {/if}
  120. </Table.Cell>
  121. <Table.Cell class="text-xs text-white/25">{component.description}</Table.Cell>
  122. </Table.Row>
  123. {:else}
  124. <Empty icon={StickyNote}>
  125. {#snippet caption()}
  126. <div>No components</div>
  127. {/snippet}
  128. </Empty>
  129. {/each}
  130. </Table.Body>
  131. </Table.Root>
  132. </div>
  133. {/if}
  134. </div>