Skip to content

Commit

Permalink
feat: add chat sidepanel in sheet & migrate API v2 (#410)
Browse files Browse the repository at this point in the history
* feat: add chat sidepanel

* feat: shinkai sheet chat

* fixes

* feat: create_job, send_message, create_files_inbox, add_file_to_inbox V2

* feat: getLLMProviders, getWorkflowList, getWorkflowSearch v2

* refactor

* create_job, get_llm_providers, workflow list & search V2

* clean up

* more api migrations

* more api migrations

* migrate all tools endpoints

* feat: implement auth token

* more updates

* fixes

* build fixes shinkai mobile

* fixes

* fix use_registration_code
  • Loading branch information
paulclindo authored Aug 28, 2024
1 parent 7f8d438 commit 47099ba
Show file tree
Hide file tree
Showing 137 changed files with 2,197 additions and 1,850 deletions.
12 changes: 2 additions & 10 deletions apps/shinkai-app/src/pages/AddAgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
IonSelectOption,
IonTitle,
} from '@ionic/react';
import { useAddLLMProvider } from '@shinkai_network/shinkai-node-state/lib/mutations/addLLMProvider/useAddLLMProvider';
import { useAddLLMProvider } from '@shinkai_network/shinkai-node-state/v2/mutations/addLLMProvider/useAddLLMProvider';
import { Controller, useForm } from 'react-hook-form';
import { useHistory } from 'react-router';
import z from 'zod';
Expand Down Expand Up @@ -60,8 +60,7 @@ const AddAgent: React.FC = () => {
if (!auth) return;
addLLMProvider({
nodeAddress: auth.node_address,
sender_subidentity: auth.profile,
node_name: auth.shinkai_identity,
token: auth.api_v2_key,
agent: {
allowed_message_senders: [],
api_key: data.apikey,
Expand All @@ -75,13 +74,6 @@ const AddAgent: React.FC = () => {
[model]: modelMapping[model],
},
},
setupDetailsState: {
my_device_encryption_sk: auth.my_device_encryption_sk,
my_device_identity_sk: auth.my_device_identity_sk,
node_encryption_pk: auth.node_encryption_pk,
profile_encryption_sk: auth.profile_encryption_sk,
profile_identity_sk: auth.profile_identity_sk,
},
});
};

Expand Down
8 changes: 5 additions & 3 deletions apps/shinkai-app/src/pages/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
generateEncryptionKeys,
generateSignatureKeys,
} from '@shinkai_network/shinkai-message-ts/utils';
import { useSubmitRegistration } from '@shinkai_network/shinkai-node-state/lib/mutations/submitRegistation/useSubmitRegistration';
import { useSubmitRegistrationNoCode } from '@shinkai_network/shinkai-node-state/lib/mutations/submitRegistation/useSubmitRegistrationNoCode';
import { useSubmitRegistration } from '@shinkai_network/shinkai-node-state/v2/mutations/submitRegistation/useSubmitRegistration';
import { useSubmitRegistrationNoCode } from '@shinkai_network/shinkai-node-state/v2/mutations/submitRegistation/useSubmitRegistrationNoCode';
import { useQueryClient } from '@tanstack/react-query';
// import { QrScanner, QrScannerProps } from '@yudiel/react-qr-scanner';
import { BrowserQRCodeReader } from '@zxing/browser';
Expand Down Expand Up @@ -128,6 +128,7 @@ const Connect = () => {
profile_identity_sk: values.profile_identity_sk,
profile_encryption_pk: values.profile_encryption_pk,
profile_encryption_sk: values.profile_encryption_sk,
api_v2_key: '',
});
history.push('/home');
},
Expand Down Expand Up @@ -294,7 +295,7 @@ const Connect = () => {
/>
</div>
</div>
<div className="flex grow overflow-auto bg-white p-10 md:rounded-[1.25rem] dark:bg-slate-800 ">
<div className="flex grow overflow-auto bg-white p-10 md:rounded-[1.25rem] dark:bg-slate-800">
<div className="mx-auto w-full max-w-[31.5rem] pt-10">
<a href="https://shinkai.com/" rel="noreferrer" target="_blank">
<img
Expand Down Expand Up @@ -705,6 +706,7 @@ function AutomaticForm() {
profile_identity_sk: values.profile_identity_sk,
profile_encryption_pk: values.profile_encryption_pk,
profile_encryption_sk: values.profile_encryption_sk,
api_v2_key: response?.data?.api_v2_key ?? '',
});
history.push('/home');
},
Expand Down
25 changes: 6 additions & 19 deletions apps/shinkai-app/src/pages/CreateJob.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
IonTitle,
} from '@ionic/react';
import { buildInboxIdFromJobId } from '@shinkai_network/shinkai-message-ts/utils';
import { useCreateJob } from '@shinkai_network/shinkai-node-state/lib/mutations/createJob/useCreateJob';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/lib/queries/getLLMProviders/useGetLLMProviders';
import { useCreateJob } from '@shinkai_network/shinkai-node-state/v2/mutations/createJob/useCreateJob';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/v2/queries/getLLMProviders/useGetLLMProviders';
import { Controller, useForm } from 'react-hook-form';
import { useHistory } from 'react-router';
import z from 'zod';
Expand All @@ -33,14 +33,7 @@ const CreateJob: React.FC = () => {
const auth = useAuth((state) => state.auth);
const { llmProviders } = useGetLLMProviders({
nodeAddress: auth?.node_address ?? '',
sender: auth?.shinkai_identity ?? '',
senderSubidentity: `${auth?.profile}`,
shinkaiIdentity: auth?.shinkai_identity ?? '',
my_device_encryption_sk: auth?.profile_encryption_sk ?? '',
my_device_identity_sk: auth?.profile_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});

const history = useHistory();
Expand All @@ -60,17 +53,11 @@ const CreateJob: React.FC = () => {
if (!auth) return;
createJob({
nodeAddress: auth.node_address,
shinkaiIdentity: auth.shinkai_identity,
profile: auth.profile,
agentId: data.model,
token: auth?.api_v2_key ?? '',
llmProvider: data.model,
content: data.description,
files_inbox: '',
files: [],
my_device_encryption_sk: auth.my_device_encryption_sk,
my_device_identity_sk: auth.my_device_identity_sk,
node_encryption_pk: auth.node_encryption_pk,
profile_encryption_sk: auth.profile_encryption_sk,
profile_identity_sk: auth.profile_identity_sk,
isHidden: false,
});
};

Expand Down
17 changes: 4 additions & 13 deletions apps/shinkai-app/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
IonText,
IonTitle,
} from '@ionic/react';
import { SmartInbox } from '@shinkai_network/shinkai-message-ts/models';
import { Inbox } from '@shinkai_network/shinkai-message-ts/api/jobs/types';
import { useUpdateInboxName } from '@shinkai_network/shinkai-node-state/lib/mutations/updateInboxName/useUpdateInboxName';
import { useGetInboxes } from '@shinkai_network/shinkai-node-state/lib/queries/getInboxes/useGetInboxes';
import { useGetInboxes } from '@shinkai_network/shinkai-node-state/v2/queries/getInboxes/useGetInboxes';
import { addOutline, arrowForward } from 'ionicons/icons';
import { Edit3Icon } from 'lucide-react';
import React, { useState } from 'react';
Expand All @@ -33,7 +33,7 @@ const updateInboxNameSchema = z.object({
inboxName: z.string(),
});

const MessageButton = ({ inbox }: { inbox: SmartInbox }) => {
const MessageButton = ({ inbox }: { inbox: Inbox }) => {
const history = useHistory();
const auth = useAuth((state) => state.auth);
const [isEditable, setIsEditable] = useState(false);
Expand Down Expand Up @@ -145,16 +145,7 @@ const Home: React.FC = () => {

const { inboxes } = useGetInboxes({
nodeAddress: auth?.node_address ?? '',
sender: auth?.shinkai_identity ?? '',
senderSubidentity: auth?.profile ?? '',
// Assuming receiver and target_shinkai_name_profile are the same as sender
receiver: auth?.shinkai_identity ?? '',
targetShinkaiNameProfile: `${auth?.shinkai_identity}/${auth?.profile}`,
my_device_encryption_sk: auth?.my_device_encryption_sk ?? '',
my_device_identity_sk: auth?.my_device_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});
const history = useHistory();

Expand Down
1 change: 1 addition & 0 deletions apps/shinkai-app/src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type SetupData = {
my_device_identity_pk: string;
identity_type?: string;
registration_code?: string;
api_v2_key: string;
};

type AuthStore = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useGetHealth } from '@shinkai_network/shinkai-node-state/lib/queries/getHealth/useGetHealth';
import { useGetInboxes } from '@shinkai_network/shinkai-node-state/lib/queries/getInboxes/useGetInboxes';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/lib/queries/getLLMProviders/useGetLLMProviders';
// import { useGetMySharedFolders } from '@shinkai_network/shinkai-node-state/lib/queries/getMySharedFolders/useGetMySharedFolders';
import { useGetVRPathSimplified } from '@shinkai_network/shinkai-node-state/lib/queries/getVRPathSimplified/useGetVRPathSimplified';
import { getFlatChildItems } from '@shinkai_network/shinkai-node-state/lib/utils/files';
import { useGetHealth } from '@shinkai_network/shinkai-node-state/v2/queries/getHealth/useGetHealth';
import { useGetInboxes } from '@shinkai_network/shinkai-node-state/v2/queries/getInboxes/useGetInboxes';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/v2/queries/getLLMProviders/useGetLLMProviders';
import { useMap } from '@shinkai_network/shinkai-ui/hooks';
import { useEffect } from 'react';

Expand All @@ -19,33 +19,18 @@ export const useOnboardingSteps = () => {
);

const { nodeInfo, isSuccess } = useGetHealth(
{ node_address: auth?.node_address ?? '' },
{ nodeAddress: auth?.node_address ?? '' },
{ enabled: !!auth },
);

const { llmProviders } = useGetLLMProviders({
nodeAddress: auth?.node_address ?? '',
sender: auth?.shinkai_identity ?? '',
senderSubidentity: `${auth?.profile}`,
shinkaiIdentity: auth?.shinkai_identity ?? '',
my_device_encryption_sk: auth?.profile_encryption_sk ?? '',
my_device_identity_sk: auth?.profile_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});

const { inboxes } = useGetInboxes({
nodeAddress: auth?.node_address ?? '',
sender: auth?.shinkai_identity ?? '',
senderSubidentity: auth?.profile ?? '',
receiver: auth?.shinkai_identity ?? '',
targetShinkaiNameProfile: `${auth?.shinkai_identity}/${auth?.profile}`,
my_device_encryption_sk: auth?.my_device_encryption_sk ?? '',
my_device_identity_sk: auth?.my_device_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});

const { data: VRFiles } = useGetVRPathSimplified({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface SelectedCell {
type TableSheetStore = {
selectedCell: SelectedCell | null;
setSelectedCell: (cell?: SelectedCell | null) => void;
showChatPanel: boolean;
setShowChatPanel: (show: boolean) => void;
toggleChatPanel: () => void;
};

const createTableSheetStore = () =>
Expand All @@ -19,6 +22,15 @@ const createTableSheetStore = () =>
set({
selectedCell: cell,
}),
showChatPanel: false,
setShowChatPanel: (show) =>
set({
showChatPanel: show,
}),
toggleChatPanel: () =>
set((state) => ({
showChatPanel: !state.showChatPanel,
})),
}));

const TableSheetContext = createContext<ReturnType<
Expand Down
21 changes: 4 additions & 17 deletions apps/shinkai-desktop/src/components/sheet/data-table-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
import { useAddRowsSheet } from '@shinkai_network/shinkai-node-state/lib/mutations/addRowsSheet/useAddRowsSheet';
import { useRemoveRowsSheet } from '@shinkai_network/shinkai-node-state/lib/mutations/removeRowsSheet/useRemoveRowsSheet';
import { useSetColumnSheet } from '@shinkai_network/shinkai-node-state/lib/mutations/setColumnSheet/useSetColumnSheet';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/lib/queries/getLLMProviders/useGetLLMProviders';
import { useGetWorkflowList } from '@shinkai_network/shinkai-node-state/lib/queries/getWorkflowList/useGetWorkflowList';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/v2/queries/getLLMProviders/useGetLLMProviders';
import { useGetWorkflowList } from '@shinkai_network/shinkai-node-state/v2/queries/getWorkflowList/useGetWorkflowList';
import {
Button,
DropdownMenu,
Expand Down Expand Up @@ -137,25 +137,12 @@ export function AddColumnAction() {
const auth = useAuth((state) => state.auth);
const { llmProviders } = useGetLLMProviders({
nodeAddress: auth?.node_address ?? '',
sender: auth?.shinkai_identity ?? '',
senderSubidentity: `${auth?.profile}`,
shinkaiIdentity: auth?.shinkai_identity ?? '',
my_device_encryption_sk: auth?.profile_encryption_sk ?? '',
my_device_identity_sk: auth?.profile_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});

const { data: workflowList } = useGetWorkflowList({
nodeAddress: auth?.node_address ?? '',
shinkaiIdentity: auth?.shinkai_identity ?? '',
profile: auth?.profile ?? '',
my_device_encryption_sk: auth?.my_device_encryption_sk ?? '',
my_device_identity_sk: auth?.my_device_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});

const setColumnForm = useForm<SetColumnFormSchema>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '@shinkai_network/shinkai-message-ts/models/SchemaTypes';
import { useRemoveColumnSheet } from '@shinkai_network/shinkai-node-state/lib/mutations/removeColumnSheet/useRemoveColumnSheet';
import { useSetColumnSheet } from '@shinkai_network/shinkai-node-state/lib/mutations/setColumnSheet/useSetColumnSheet';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/lib/queries/getLLMProviders/useGetLLMProviders';
import { useGetWorkflowList } from '@shinkai_network/shinkai-node-state/lib/queries/getWorkflowList/useGetWorkflowList';
import { useGetLLMProviders } from '@shinkai_network/shinkai-node-state/v2/queries/getLLMProviders/useGetLLMProviders';
import { useGetWorkflowList } from '@shinkai_network/shinkai-node-state/v2/queries/getWorkflowList/useGetWorkflowList';
import {
Button,
DropdownMenu,
Expand Down Expand Up @@ -70,24 +70,11 @@ export function DataTableColumnHeader<TData, TValue>({

const { llmProviders } = useGetLLMProviders({
nodeAddress: auth?.node_address ?? '',
sender: auth?.shinkai_identity ?? '',
senderSubidentity: `${auth?.profile}`,
shinkaiIdentity: auth?.shinkai_identity ?? '',
my_device_encryption_sk: auth?.profile_encryption_sk ?? '',
my_device_identity_sk: auth?.profile_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});
const { data: workflowList } = useGetWorkflowList({
nodeAddress: auth?.node_address ?? '',
shinkaiIdentity: auth?.shinkai_identity ?? '',
profile: auth?.profile ?? '',
my_device_encryption_sk: auth?.my_device_encryption_sk ?? '',
my_device_identity_sk: auth?.my_device_identity_sk ?? '',
node_encryption_pk: auth?.node_encryption_pk ?? '',
profile_encryption_sk: auth?.profile_encryption_sk ?? '',
profile_identity_sk: auth?.profile_identity_sk ?? '',
token: auth?.api_v2_key ?? '',
});

const setColumnForm = useForm<SetColumnFormSchema>({
Expand All @@ -102,8 +89,6 @@ export function DataTableColumnHeader<TData, TValue>({
},
});

console.log(setColumnForm.formState.errors, 'errors');

const currentColumnType = useWatch({
control: setColumnForm.control,
name: 'columnType',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Table } from '@tanstack/react-table';

// import { SortAltIcon } from 'primereact/icons/sortalt';
import {
DataTableChatOptions,
DataTableHeightOptions,
DataTableViewOptions,
} from './data-table-view-options';
Expand Down Expand Up @@ -51,6 +52,7 @@ export function DataTableToolbar<TData>({
{/* </Button>*/}
{/*)}*/}
{/*</div>*/}
<DataTableChatOptions />
<DataTableHeightOptions columns={columns} table={table} />
<DataTableViewOptions columns={columns} table={table} />
</div>
Expand Down
Loading

0 comments on commit 47099ba

Please sign in to comment.