Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python interop #65

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
coverage
.eslintrc.cjs
app-executor/bin/executor-bundle.js
*.bundle.cjs
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ packages/app-executor/bin/executor-bundle.js
.turbo

.idea

packages/python/rivet.bundle.cjs

packages/core/meta.json

packages/python/__pycache__/
298 changes: 203 additions & 95 deletions .pnp.cjs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
"rust-analyzer.linkedProjects": ["packages/app/src-tauri/Cargo.toml"],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"zx": "^7.2.3"
},
"resolutions": {
"jest-mock": "^28.1.0"
"jest-mock": "^28.1.0",
"autoevals": "portal:/Users/Shared/ironclad/github/autoevals"
},
"volta": {
"node": "20.4.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/app-executor/scripts/build-executor.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ const resolveRivet: esbuild.Plugin = {
setup(build) {
build.onResolve({ filter: /^@ironclad\/rivet-/ }, (args) => {
const rivetPackage = args.path.replace(/^@ironclad\/rivet-/, '');

if (rivetPackage.includes('FetchHttpProvider')) {
return {
path: resolve('../core/src/FetchHttpProvider.ts'),
};
}

return {
path: resolve(`../${rivetPackage}/src/index.ts`),
};
Expand Down
78 changes: 47 additions & 31 deletions packages/app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
windows_subsystem = "windows"
)]

use tauri::{CustomMenuItem, Menu, MenuItem, Submenu};
use tauri::{CustomMenuItem, Manager, Menu, MenuItem, Submenu};

#[tauri::command]
fn set_recent_project_files(recent_files: Vec<&str>, window: tauri::Window) {
let menu = window.menu_handle();
let item = menu.get_item("new_project");
}

fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_persisted_scope::init())
.plugin(tauri_plugin_window_state::Builder::default().build())
.invoke_handler(tauri::generate_handler![get_environment_variable])
.invoke_handler(tauri::generate_handler![
get_environment_variable,
set_recent_project_files
])
.menu(create_menu())
.on_menu_event(|event| match event.menu_item_id() {
"toggle_devtools" => {
Expand Down Expand Up @@ -90,37 +99,44 @@ fn create_menu() -> Menu {
)),
);

let open_recent = Submenu::new("Open Recent", Menu::new());

let file_menu = Submenu::new(
"File",
Menu::new()
.add_item(
CustomMenuItem::new("new_project".to_string(), "New Project")
.accelerator("CmdOrCtrl+N"),
)
.add_native_item(MenuItem::Separator)
.add_item(
CustomMenuItem::new("open_project".to_string(), "Open Project...")
.accelerator("CmdOrCtrl+O"),
)
.add_submenu(open_recent)
.add_native_item(MenuItem::Separator)
.add_item(
CustomMenuItem::new("save_project".to_string(), "Save Project")
.accelerator("CmdOrCtrl+S"),
)
.add_item(
CustomMenuItem::new("save_project_as".to_string(), "Save Project As...")
.accelerator("CmdOrCtrl+Shift+S"),
)
.add_native_item(MenuItem::Separator)
.add_item(
CustomMenuItem::new("export_graph".to_string(), "Export Graph...")
.accelerator("CmdOrCtrl+Shift+E"),
)
.add_item(
CustomMenuItem::new("import_graph".to_string(), "Import Graph...")
.accelerator("CmdOrCtrl+Shift+I"),
),
);

Menu::new()
.add_submenu(about_menu)
.add_submenu(Submenu::new(
"File",
Menu::new()
.add_item(
CustomMenuItem::new("new_project", "New Project").accelerator("CmdOrCtrl+N"),
)
.add_native_item(MenuItem::Separator)
.add_item(
CustomMenuItem::new("open_project", "Open Project...")
.accelerator("CmdOrCtrl+O"),
)
.add_native_item(MenuItem::Separator)
.add_item(
CustomMenuItem::new("save_project", "Save Project").accelerator("CmdOrCtrl+S"),
)
.add_item(
CustomMenuItem::new("save_project_as", "Save Project As...")
.accelerator("CmdOrCtrl+Shift+S"),
)
.add_native_item(MenuItem::Separator)
.add_item(
CustomMenuItem::new("export_graph", "Export Graph...")
.accelerator("CmdOrCtrl+Shift+E"),
)
.add_item(
CustomMenuItem::new("import_graph", "Import Graph...")
.accelerator("CmdOrCtrl+Shift+I"),
),
))
.add_submenu(file_menu)
.add_submenu(edit_menu)
.add_submenu(Submenu::new(
"Run",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/DefaultNodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import clsx from 'clsx';
import { projectState } from '../state/savedGraphs.js';
import { useRecoilValue } from 'recoil';
import { orderBy } from 'lodash-es';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { LazyCodeEditor, LazyTripleBarColorPicker } from './LazyComponents';
import { ioProvider } from '../utils/globals';
import Button from '@atlaskit/button';
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/NodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Select from '@atlaskit/select';
import Button from '@atlaskit/button';
import Popup from '@atlaskit/popup';
import { orderBy } from 'lodash-es';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { ErrorBoundary } from 'react-error-boundary';
import { projectState } from '../state/savedGraphs';

Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/components/PromptDesigner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { Field } from '@atlaskit/form';
import Tabs, { Tab, TabList, TabPanel } from '@atlaskit/tabs';
import Select from '@atlaskit/select';
import Toggle from '@atlaskit/toggle';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { TauriNativeApi } from '../model/native/TauriNativeApi.js';
import { settingsState } from '../state/settings.js';
import { GraphSelector } from './DefaultNodeEditor.js';
Expand All @@ -50,6 +50,7 @@ import { useStableCallback } from '../hooks/useStableCallback.js';
import { toast } from 'react-toastify';
import { produce } from 'immer';
import { overlayOpenState } from '../state/ui';
import { FetchHttpProvider } from '@ironclad/rivet-core/FetchHttpProvider';

const styles = css`
position: fixed;
Expand Down Expand Up @@ -981,6 +982,7 @@ async function runAdHocChat(messages: ChatMessage[], config: AdHocChatConfig) {
},
},
{
httpProvider: new FetchHttpProvider(),
contextValues: {},
createSubProcessor: undefined!,
settings,
Expand Down Expand Up @@ -1042,6 +1044,7 @@ function useRunTestGroup() {
{
nativeApi: new TauriNativeApi(),
settings,
httpProvider: new FetchHttpProvider(),
},
{
['conditions' as PortId]: {
Expand Down
9 changes: 8 additions & 1 deletion packages/app/src/components/RivetApp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphBuilder } from './GraphBuilder.js';
import { OverlayTabs } from './OverlayTabs.js';
import { FC } from 'react';
import { FC, useEffect } from 'react';
import { css } from '@emotion/react';
import { SettingsModal } from './SettingsModal.js';
import { setGlobalTheme } from '@atlaskit/tokens';
Expand All @@ -17,6 +17,7 @@ import { ChatViewerRenderer } from './ChatViewer';
import { useRecoilValue } from 'recoil';
import { themeState } from '../state/settings';
import clsx from 'clsx';
import { setRecentProjectFiles } from '../utils/tauri';

const styles = css`
overflow: hidden;
Expand All @@ -34,6 +35,12 @@ export const RivetApp: FC = () => {
onRunGraph: tryRunGraph,
});

useEffect(() => {
(async () => {
setRecentProjectFiles(['a.rivet-project', 'b.rivet-project']);
})();
}, []);

return (
<div className={clsx('app', theme ? `theme-${theme}` : 'theme-default')} css={styles}>
<OverlayTabs />
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/trivet/Trivet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { css } from '@emotion/react';
import Button from '@atlaskit/button';
import { TestSuiteList } from './TestSuiteList';
import { TestSuiteRenderer } from './TestSuite';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { TryRunTests } from './api';
import { overlayOpenState } from '../../state/ui';
import { NoTestSuitesSplash } from './NoTestSuitesSplash';
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/hooks/useDuplicateGraph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphId, NodeGraph, NodeId } from '@ironclad/rivet-core';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { useLoadGraph } from './useLoadGraph.js';
import { useStableCallback } from './useStableCallback.js';
import { useSetRecoilState } from 'recoil';
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/hooks/useFactorIntoSubgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@ironclad/rivet-core';
import { projectState } from '../state/savedGraphs.js';
import { isNotNull } from '../utils/genericUtilFunctions.js';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { useLoadGraph } from './useLoadGraph.js';

export function useFactorIntoSubgraph() {
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/hooks/useLocalExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { lastRecordingState, loadedRecordingState } from '../state/execution';
import { fillMissingSettingsFromEnvironmentVariables } from '../utils/tauri';
import { trivetState } from '../state/trivet';
import { runTrivet } from '@ironclad/trivet';
import { FetchHttpProvider } from '@ironclad/rivet-core/FetchHttpProvider';

export function useLocalExecutor() {
const project = useRecoilValue(projectState);
Expand Down Expand Up @@ -125,6 +126,7 @@ export function useLocalExecutor() {
globalRivetNodeRegistry.getPlugins(),
),
nativeApi: new TauriNativeApi(),
httpProvider: new FetchHttpProvider(),
});
}

Expand Down Expand Up @@ -181,6 +183,7 @@ export function useLocalExecutor() {
globalRivetNodeRegistry.getPlugins(),
),
nativeApi: new TauriNativeApi(),
httpProvider: new FetchHttpProvider(),
},
inputs,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/hooks/useNewProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSetRecoilState } from 'recoil';
import { loadedProjectState, projectState } from '../state/savedGraphs.js';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { Project, ProjectId, emptyNodeGraph } from '@ironclad/rivet-core';
import { graphState } from '../state/graph.js';
import { trivetState } from '../state/trivet';
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/hooks/useSaveCurrentGraph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { produce } from 'immer';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { GraphId } from '@ironclad/rivet-core';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { graphState } from '../state/graph.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/hooks/useTestSuite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo } from 'react';
import { useStableCallback } from './useStableCallback';
import { TrivetTestSuite } from '@ironclad/trivet';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { trivetState } from '../state/trivet';
import { GraphInputNode, GraphOutputNode, NodeGraph } from '@ironclad/rivet-core';
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/state/savedGraphs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DefaultValue, atom, selector } from 'recoil';
import { nanoid } from 'nanoid';
import { nanoid } from 'nanoid/non-secure';
import { produce } from 'immer';
import { GraphId, NodeGraph, Project, ProjectId } from '@ironclad/rivet-core';
import { blankProject } from '../hooks/useNewProject.js';
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/utils/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ export async function fillMissingSettingsFromEnvironmentVariables(settings: Part

return fullSettings;
}

export async function setRecentProjectFiles(recentFiles: string[]) {
await invoke('set_recent_project_files', { recentFiles });
}
1 change: 1 addition & 0 deletions packages/app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
preserveSymlinks: true,

alias: {
'@ironclad/rivet-core/FetchHttpProvider': resolve('../core/src/FetchHttpProvider.ts'),
'@ironclad/rivet-core': resolve('../core/src/index.ts'),
'@ironclad/trivet': resolve('../trivet/src/index.ts'),
},
Expand Down
Loading