Skip to content

Commit

Permalink
Merge branch 'main' into release-vsce-1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes committed Nov 8, 2024
2 parents 4a4d147 + 4338a98 commit cc860fc
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:

jobs:
release-docker:
runs-on: ubuntu-latest
runs-on: buildjet-2vcpu-ubuntu-2204
permissions:
contents: read
packages: write
Expand Down
14 changes: 10 additions & 4 deletions clients/vscode/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ThemeIcon,
QuickPickItem,
ViewColumn,
Range,
} from "vscode";
import os from "os";
import path from "path";
Expand Down Expand Up @@ -86,8 +87,11 @@ export class Commands {
this.chatViewProvider.addRelevantContext(fileContext);
}
};
commands.executeCommand("tabby.chatView.focus");

commands.executeCommand("tabby.chatView.focus").then(addContext);
if (this.chatViewProvider.webview?.visible) {
addContext();
}
}

commands: Record<string, (...args: never[]) => void> = {
Expand Down Expand Up @@ -295,18 +299,20 @@ export class Commands {

chatPanelViewProvider.resolveWebviewView(panel);
},
"chat.edit.start": async (userCommand?: string) => {
"chat.edit.start": async (userCommand?: string, range?: Range) => {
const editor = window.activeTextEditor;
if (!editor) {
return;
}

const editRange = range || editor.selection;

const editLocation = {
uri: editor.document.uri.toString(),
range: {
start: { line: editor.selection.start.line, character: 0 },
start: { line: editRange.start.line, character: 0 },
end: {
line: editor.selection.end.character === 0 ? editor.selection.end.line : editor.selection.end.line + 1,
line: editRange.end.character === 0 ? editRange.end.line : editRange.end.line + 1,
character: 0,
},
},
Expand Down
28 changes: 24 additions & 4 deletions clients/vscode/src/code-action/QuickFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
} from "vscode";
import { ContextVariables } from "../ContextVariables";
import { getLogger } from "../logger";

export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
private readonly logger = getLogger("QuickFixCodeActionProvider");
constructor(private readonly contextVariables: ContextVariables) {}

provideCodeActions(
Expand All @@ -22,33 +24,51 @@ export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
if (token.isCancellationRequested) {
return;
}

if (!this.contextVariables.chatEnabled) {
return;
}
if (context.diagnostics.length === 0) {
return [];
}

const getMergedDiagnosticRange = () => {
return context.diagnostics.reduce(
(mergedRange, diagnostic) => {
if (!mergedRange) {
return diagnostic.range;
}
return mergedRange.union(diagnostic.range);
},
null as Range | null,
);
};

const mergedRange = getMergedDiagnosticRange();
if (!mergedRange) {
return [];
}

const lspErrors = context.diagnostics
.map((diagnostic, idx) => "Error " + idx + ": " + diagnostic.message)
.join("\n");

const quickFixCmd = `Here is some error information that occurred in the selection:
${lspErrors}
Please provide the correct command to fix the error.`;
getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);
this.logger.trace("LSP Errors collections: ", lspErrors);
this.logger.debug("QuickFix Range: ", mergedRange);

const quickFixEditing = new CodeAction("Fix using Tabby", CodeActionKind.QuickFix);

quickFixEditing.command = {
command: "tabby.chat.edit.start",
title: "Fix using Tabby",
arguments: [quickFixCmd],
arguments: [quickFixCmd, mergedRange],
};

const explainErrorCmd = `\nHere is some error information that occurred in the selection:
${lspErrors}
Please provide an explanation for the error.`;

const explainError = new CodeAction("Explain using Tabby", CodeActionKind.QuickFix);
explainError.command = {
command: "tabby.chat.explainCodeBlock",
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-schema/src/schema/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl LicenseInfo {
}

pub fn seat_limits_for_team_license() -> usize {
200
50
}

pub fn guard_seat_limit(mut self) -> Self {
Expand Down
15 changes: 7 additions & 8 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ impl Query {
ctx: &Context,
backend: ModelHealthBackend,
) -> Result<ModelBackendHealthInfo, TestModelConnectionError> {
check_user_allow_auth_token(ctx).await?;
check_admin(ctx).await?;

// count request time in milliseconds
let start = Instant::now();
Expand All @@ -741,16 +741,15 @@ impl Query {
.expect("Failed to build completion options");

let (first, _) = completion
.generate("hello Tabby", options)
.generate("def fib(n):\n", options)
.await
.into_future()
.await;
if let Some(first) = first {
if !first.is_empty() {
return Ok(ModelBackendHealthInfo {
latency_ms: start.elapsed().as_millis() as i32,
});
}

if first.is_some() {
return Ok(ModelBackendHealthInfo {
latency_ms: start.elapsed().as_millis() as i32,
});
}

Err(TestModelConnectionError::FailedToConnect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const PLANS: Plan[] = [
{
name: 'Team',
pricing: '$19 per user/month',
limit: 'Up to 200 users'
limit: 'Up to 50 users'
},
{
name: 'Enterprise',
Expand Down Expand Up @@ -145,7 +145,7 @@ const FEATURES: FeatureGroup[] = [
{
name: 'User count',
community: 'Up to 5',
team: 'Up to 200',
team: 'Up to 50',
enterprise: 'Unlimited'
},
{
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-ui/app/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import Image from 'next/image'
import { useRouter } from 'next/navigation'
import tabbyUrl from '@/assets/logo-dark.png'
import { useQuery } from 'urql'
import { useStore } from 'zustand'

import { SESSION_STORAGE_KEY } from '@/lib/constants'
import { useHealth } from '@/lib/hooks/use-health'
import { useMe } from '@/lib/hooks/use-me'
import { useSelectedModel } from '@/lib/hooks/use-models'
import { useIsChatEnabled } from '@/lib/hooks/use-server-info'
import { useStore } from '@/lib/hooks/use-store'
import { updateSelectedModel } from '@/lib/stores/chat-actions'
import {
clearHomeScrollPosition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as z from 'zod'

import { MARKDOWN_CITATION_REGEX } from '@/lib/constants/regex'
import { MessageAttachmentCode } from '@/lib/gql/generates/graphql'
import { useEnterSubmit } from '@/lib/hooks/use-enter-submit'
import { AttachmentDocItem, RelevantCodeContext } from '@/lib/types'
import {
cn,
Expand Down Expand Up @@ -532,7 +531,6 @@ function MessageContentForm({
const { content } = form.watch()
const isEmptyContent = !content || isEmpty(content.trim())
const [draftMessage] = useState<ConversationMessage>(message)
const { formRef, onKeyDown } = useEnterSubmit()

const handleSubmit = async (values: z.infer<typeof formSchema>) => {
const errorMessage = await onSubmit({
Expand All @@ -546,7 +544,7 @@ function MessageContentForm({

return (
<Form {...form}>
<form ref={formRef} onSubmit={form.handleSubmit(handleSubmit)}>
<form onSubmit={form.handleSubmit(handleSubmit)}>
<FormField
control={form.control}
name="content"
Expand All @@ -558,7 +556,6 @@ function MessageContentForm({
minRows={2}
maxRows={20}
className="w-full rounded-lg border bg-background p-4 outline-ring"
onKeyDown={onKeyDown}
{...field}
/>
</FormControl>
Expand Down
34 changes: 24 additions & 10 deletions ee/tabby-ui/components/chat/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { RefObject } from 'react'
import type { UseChatHelpers } from 'ai/react'
import type { Context } from 'tabby-chat-panel'

import { cn } from '@/lib/utils'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
Expand Down Expand Up @@ -110,10 +111,14 @@ function ChatPanelRenderer(
<Badge
variant="outline"
key={`${activeSelection.filepath}_active_selection`}
className="inline-flex items-center gap-0.5 rounded text-sm font-semibold"
className="inline-flex flex-nowrap items-center gap-1.5 overflow-hidden rounded text-sm font-semibold"
>
<span className="text-foreground">
{getContextLabel(activeSelection)}
<ContextLabel
context={activeSelection}
className="flex-1 truncate"
/>
<span className="shrink-0 text-muted-foreground">
Current file
</span>
</Badge>
) : null}
Expand All @@ -122,13 +127,11 @@ function ChatPanelRenderer(
<Badge
variant="outline"
key={item.filepath + idx}
className="inline-flex items-center gap-0.5 rounded text-sm font-semibold"
className="inline-flex flex-nowrap items-center gap-0.5 overflow-hidden rounded text-sm font-semibold"
>
<span className="text-foreground">
{getContextLabel(item)}
</span>
<ContextLabel context={item} />
<IconRemove
className="cursor-pointer text-muted-foreground transition-all hover:text-red-300"
className="shrink-0 cursor-pointer text-muted-foreground transition-all hover:text-red-300"
onClick={removeRelevantContext.bind(null, idx)}
/>
</Badge>
Expand All @@ -155,12 +158,23 @@ export const ChatPanel = React.forwardRef<ChatPanelRef, ChatPanelProps>(
ChatPanelRenderer
)

function getContextLabel(context: Context) {
function ContextLabel({
context,
className
}: {
context: Context
className?: string
}) {
const [fileName] = context.filepath.split('/').slice(-1)
const line =
context.range.start === context.range.end
? `${context.range.start}`
: `${context.range.start}-${context.range.end}`

return `${fileName}: ${line}`
return (
<span className={cn('truncate text-foreground', className)}>
{fileName}
<span className="text-muted-foreground">{`:${line}`}</span>
</span>
)
}
16 changes: 6 additions & 10 deletions ee/tabby-ui/lib/hooks/use-models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import { useEffect } from 'react'
import { Maybe } from 'graphql/jsutils/Maybe'
import useSWR, { SWRResponse } from 'swr'
import { useStore } from 'zustand'

import fetcher from '@/lib/tabby/fetcher'

import { updateSelectedModel } from '../stores/chat-actions'
import { useChatStore } from '../stores/chat-store'
import { useStore } from './use-store'

export interface ModelInfo {
completion: Maybe<Array<string>>
Expand All @@ -33,24 +33,20 @@ export function useModels(): SWRResponse<ModelInfo> {

export function useSelectedModel() {
const { data: modelData, isLoading: isFetchingModel } = useModels()
const isModelHydrated = useStore(useChatStore, state => state._hasHydrated)

const selectedModel = useStore(useChatStore, state => state.selectedModel)

// once model hydrated, try to init model
useEffect(() => {
if (isModelHydrated && !isFetchingModel) {
// check if current model is valid
if (!isFetchingModel) {
// init model
const validModel = getModelFromModelInfo(selectedModel, modelData?.chat)
if (selectedModel !== validModel) {
updateSelectedModel(validModel)
}
updateSelectedModel(validModel)
}
}, [isModelHydrated, isFetchingModel])
}, [isFetchingModel])

return {
// fetching model data or trying to get selected model from localstorage
isModelLoading: isFetchingModel || !isModelHydrated,
isModelLoading: isFetchingModel,
selectedModel,
models: modelData?.chat
}
Expand Down

0 comments on commit cc860fc

Please sign in to comment.