Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/browser-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
},
"dependencies": {
"@evaluate/components": "workspace:^",
"@evaluate/engine": "workspace:^",
"@evaluate/helpers": "workspace:^",
"@evaluate/shapes": "workspace:^",
"@evaluate/styles": "workspace:^",
"@evaluate/execute": "workspace:^",
"@evaluate/logger": "workspace:^",
"@evaluate/runtimes": "workspace:^",
"@evaluate/style": "workspace:^",
"@t3-oss/env-core": "^0.13.8",
"lucide-react": "^0.525.0",
"posthog-js": "^1.257.0",
Expand Down
26 changes: 8 additions & 18 deletions apps/browser-extension/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { executeCode } from '@evaluate/engine/execute';
import {
getRuntimeDefaultFileName,
searchRuntimes,
} from '@evaluate/engine/runtimes';
import type { ExecuteResult, PartialRuntime } from '@evaluate/shapes';
import { type ExecuteResult, executeCode } from '@evaluate/execute';
import { type Runtime, searchForRuntimes } from '@evaluate/runtimes';
import type { ProtocolWithReturn } from 'webext-bridge';
import { onMessage, sendMessage } from 'webext-bridge/background';
import browser from 'webextension-polyfill';
Expand All @@ -23,7 +19,7 @@ declare module 'webext-bridge' {
>;
executionFailed: ProtocolWithReturn<{ errorMessage: string }, void>;
executionFinished: ProtocolWithReturn<
{ code: string; runtimes: PartialRuntime[]; results: ExecuteResult[] },
{ code: string; runtimes: Runtime[]; results: ExecuteResult[] },
void
>;
getBackgroundSessionId: ProtocolWithReturn<void, string | undefined>;
Expand All @@ -47,7 +43,6 @@ browser.contextMenus.create({
});

browser.action.onClicked.addListener(async () => {
console.log(posthog);
posthog?.capture('clicked_browser_action');
browser.tabs.create({ url: `${env.VITE_PUBLIC_WEBSITE_URL}` });
});
Expand All @@ -60,7 +55,7 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {

const selection = await sendMessage('getSelectionInfo', void 0, endpoint);
const { code, resolvables } = selection;
const runtimes = (await searchRuntimes(...resolvables)).slice(0, 5);
const runtimes = (await searchForRuntimes(resolvables)).slice(0, 5);
if (!runtimes.length)
return sendMessage('unknownRuntime', { code }, endpoint);

Expand All @@ -70,17 +65,12 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {

const promises = [];
for (const runtime of runtimes) {
const fileName = getRuntimeDefaultFileName(runtime.id) ?? 'file.code';
const initialPromise = executeCode({
runtime: runtime.id,
files: { [fileName]: code },
entry: fileName,
})
.then((result) => {
const initialPromise = executeCode(runtime, { code })
.then(([result, options]) => {
posthog?.capture('executed_code', {
runtime_id: runtime.id,
code_length: code.length,
code_lines: code.split('\n').length,
code_length: options.length,
code_lines: options.lines,
compile_successful: result.compile?.success ?? null,
execution_successful: result.success,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
TabsList,
TabsTrigger,
} from '@evaluate/components/tabs';
import type { ExecuteResult, PartialRuntime } from '@evaluate/shapes';
import type { ExecuteResult } from '@evaluate/execute';
import type { Runtime } from '@evaluate/runtimes';
import browser from 'webextension-polyfill';
import env from '~/env';
import { ResultDialog } from './result';
Expand All @@ -25,7 +26,7 @@ export function ExecutionDialog({
}: {
portal: HTMLElement;
code: string;
runtimes: PartialRuntime[];
runtimes: Runtime[];
results: ExecuteResult[];
setResults: (results: ExecuteResult[]) => void;
}) {
Expand Down Expand Up @@ -68,7 +69,7 @@ export function ExecutionDialog({
{runtimes.map((runtime, i) => (
<TabsContent key={runtime.id} value={runtime.id}>
<ResultDialog
code={code}
options={{ code }}
runtime={runtime}
result={results[i]!}
/>
Expand Down
12 changes: 8 additions & 4 deletions apps/browser-extension/src/content-script/execution/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { toast } from '@evaluate/components/toast';
import type { ExecuteResult, PartialRuntime } from '@evaluate/shapes';
import { type ExecuteResult, makePickRuntimePathname } from '@evaluate/execute';
import type { Runtime } from '@evaluate/runtimes';
import { useEffect, useState } from 'react';
import { onMessage } from 'webext-bridge/content-script';
import { makePickRuntimeUrl } from '~/helpers/make-url';
import env from '~/env.js';
import { ExecutionDialog } from './dialog';

export function Execution({ dialogPortal }: { dialogPortal: HTMLElement }) {
const [code, setCode] = useState('');
const [runtimes, setRuntimes] = useState<PartialRuntime[]>([]);
const [runtimes, setRuntimes] = useState<Runtime[]>([]);
const [results, setResults] = useState<ExecuteResult[]>([]);

useEffect(() => {
Expand All @@ -16,7 +17,10 @@ export function Execution({ dialogPortal }: { dialogPortal: HTMLElement }) {
const removeUnknownRuntimeListener = onMessage(
'unknownRuntime',
({ data: { code } }) => {
const pickUrl = makePickRuntimeUrl(code);
const pickUrl = new URL(
makePickRuntimePathname({ code }),
env.VITE_PUBLIC_WEBSITE_URL,
);
toast.error('Could not determine runtime', {
description:
'Evaluate was unable to determine a runtime for the selected text.',
Expand Down
29 changes: 20 additions & 9 deletions apps/browser-extension/src/content-script/execution/result.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { Button } from '@evaluate/components/button';
import { Label } from '@evaluate/components/label';
import { Textarea } from '@evaluate/components/textarea';
import type { ExecuteResult, PartialRuntime } from '@evaluate/shapes';
import {
type ExecuteResult,
makeEditCodePathname,
makePickRuntimePathname,
} from '@evaluate/execute';
import type { Runtime } from '@evaluate/runtimes';
import { ExternalLinkIcon } from 'lucide-react';
import { twMerge as cn } from 'tailwind-merge';
import { makeEditCodeUrl, makePickRuntimeUrl } from '~/helpers/make-url';
import env from '~/env.js';

export function ResultDialog({
code,
runtime,
options,
result,
}: {
code: string;
runtime: PartialRuntime;
runtime: Runtime;
options: { code: string };
result: ExecuteResult;
}) {
let output = result.output;
Expand Down Expand Up @@ -41,25 +46,31 @@ export function ResultDialog({
</div>

<div className="flex justify-end gap-2">
{code && (
{options.code && (
<Button variant="secondary" asChild>
<a
target="_blank"
rel="noreferrer noopener"
href={makePickRuntimeUrl(code)}
href={new URL(
makePickRuntimePathname(options),
env.VITE_PUBLIC_WEBSITE_URL,
).toString()}
>
<span>Change Runtime</span>
<ExternalLinkIcon size={16} className="ml-1" />
</a>
</Button>
)}

{code && runtime && (
{options.code && runtime && (
<Button variant="secondary" asChild>
<a
target="_blank"
rel="noreferrer noopener"
href={makeEditCodeUrl(runtime, code)}
href={new URL(
makeEditCodePathname(runtime, options),
env.VITE_PUBLIC_WEBSITE_URL,
).toString()}
>
<span>Edit Code</span>
<ExternalLinkIcon size={16} className="ml-1" />
Expand Down
6 changes: 3 additions & 3 deletions apps/browser-extension/src/content-script/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Toaster } from '@evaluate/components/toast';
import { createRoot } from 'react-dom/client';
import sonnerCss from 'sonner/dist/styles.css?inline';
// import sonnerCss from 'sonner/dist/styles.css?inline';
import { onMessage, sendMessage } from 'webext-bridge/content-script';
import { extractRuntimeResolvables } from '~/helpers/runtime-resolvables';
import posthog, { sessionLog } from '~/services/posthog';
import tailwindCss from '../styles.css?inline';
import tailwindCss from '../style.css?inline';
import { Execution } from './execution';
import { createIsolatedElement } from './shadow-root';

Expand Down Expand Up @@ -33,7 +33,7 @@ const { parentElement, portalElement, isolatedElement } = createIsolatedElement(
styles: {
// TODO: Figure out why this is necessary
tailwind: tailwindCss.replaceAll('border-style:', '__ignore__:'),
sonner: sonnerCss,
// sonner: sonnerCss,
},
isolatedEvents: true,
},
Expand Down
23 changes: 0 additions & 23 deletions apps/browser-extension/src/helpers/make-url.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/browser-extension/src/services/posthog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createLogger } from '@evaluate/helpers/create-logger';
import createLogger from '@evaluate/logger';
import posthog from 'posthog-js';
import env from '~/env';

Expand Down
4 changes: 4 additions & 0 deletions apps/browser-extension/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import "@evaluate/style";
@import "@evaluate/components";
@import "sonner/dist/styles.css";
@source ".";
3 changes: 0 additions & 3 deletions apps/browser-extension/src/styles.css

This file was deleted.

10 changes: 5 additions & 5 deletions apps/discord-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"build": "pnpm tsup"
},
"dependencies": {
"@buape/carbon": "0.9.0",
"@evaluate/engine": "workspace:^",
"@evaluate/helpers": "workspace:^",
"@evaluate/shapes": "workspace:^",
"@buape/carbon": "^0.9.0",
"@evaluate/execute": "workspace:^",
"@evaluate/logger": "workspace:^",
"@evaluate/runtimes": "workspace:^",
"@t3-oss/env-core": "^0.13.8",
"date-fns": "^4.1.0",
"es-toolkit": "^1.39.7",
"posthog-node": "^5.5.1",
"zod": "4.0.5"
"zod": "^4.0.5"
},
"devDependencies": {
"tsup": "^8.5.0"
Expand Down
10 changes: 5 additions & 5 deletions apps/discord-bot/src/commands/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
type CommandInteraction,
type CommandOptions,
} from '@buape/carbon';
import { fetchRuntimes, searchRuntimes } from '@evaluate/engine/runtimes';
import { fetchAllRuntimes, searchForRuntimes } from '@evaluate/runtimes';
import { EvaluateModal } from '~/components/evaluate-modal';
import { handleEvaluating } from '~/handlers/evaluate';
import { getInteractionContext } from '~/helpers/session-context';
import { captureEvent } from '~/services/posthog';
import { getInteractionContext } from '~/utilities/session-context';

export class EvaluateCommand extends Command {
name = 'evaluate';
Expand Down Expand Up @@ -47,12 +47,12 @@ export class EvaluateCommand extends Command {
const runtime = interaction.options.getString('runtime');

if (runtime) {
const runtimes = await searchRuntimes(runtime);
const runtimes = await searchForRuntimes(runtime);
return interaction.respond(
runtimes.slice(0, 25).map((r) => ({ name: r.name, value: r.id })),
);
} else {
const runtimes = await fetchRuntimes();
const runtimes = await fetchAllRuntimes();
return interaction.respond(
runtimes.slice(0, 25).map((r) => ({ name: r.name, value: r.id })),
);
Expand All @@ -70,7 +70,7 @@ export class EvaluateCommand extends Command {
const args = use.options.getString('arguments');

if (runtime && code) {
return handleEvaluating(use, { runtime, code, args, input });
return handleEvaluating(use, runtime, { code, args, input });
} else {
const modal = new EvaluateModal({ runtime, code, args, input });
return use.showModal(modal);
Expand Down
6 changes: 3 additions & 3 deletions apps/discord-bot/src/components/edit-evaluation-button.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button, type ButtonInteraction, ButtonStyle } from '@buape/carbon';
import { getEvaluateOptions } from '~/helpers/evaluate-helpers';
import { resolveEmoji } from '~/helpers/resolve-emoji';
import { getInteractionContext } from '~/helpers/session-context';
import { captureEvent } from '~/services/posthog';
import { getEvaluateOptions } from '~/utilities/evaluate-helpers';
import { resolveEmoji } from '~/utilities/resolve-emoji';
import { getInteractionContext } from '~/utilities/session-context';
import { EvaluateModalEdit } from './evaluate-modal';

export class EditEvaluationButton extends Button {
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot/src/components/evaluate-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
TextInputStyle,
} from '@buape/carbon';
import { handleEvaluating } from '~/handlers/evaluate';
import { getInteractionContext } from '~/helpers/session-context';
import { captureEvent } from '~/services/posthog';
import { getInteractionContext } from '~/utilities/session-context';

export class EvaluateModal extends Modal {
title = 'Evaluate';
Expand Down Expand Up @@ -39,7 +39,7 @@ export class EvaluateModal extends Modal {
const args = submit.fields.getText('args');
const input = submit.fields.getText('input');

return handleEvaluating(submit, { runtime, code, args, input });
return handleEvaluating(submit, runtime, { code, args, input });
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot/src/components/open-evaluation-button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LinkButton } from '@buape/carbon';
import env from '~/env';
import { resolveEmoji } from '~/utilities/resolve-emoji';
import { resolveEmoji } from '~/helpers/resolve-emoji';

export class OpenEvaluationButton extends LinkButton {
label = 'Open Evaluation';
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createEnv } from '@t3-oss/env-core';
import { z } from 'zod/v4';
import z from 'zod/v4';

export default createEnv({
server: {
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot/src/events/application-authorised.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
type ApplicationWebhookEventType,
type ListenerEventData,
} from '@buape/carbon';
import { getUserContext } from '~/helpers/session-context';
import { captureEvent } from '~/services/posthog';
import { getUserContext } from '~/utilities/session-context';

export class ApplicationAuthorisedListener extends ApplicationAuthorizedListener {
async handle(
Expand Down
Loading