Skip to content

Commit

Permalink
Merge pull request #68 from indexnetwork/features
Browse files Browse the repository at this point in the history
Features
  • Loading branch information
serefyarar authored Mar 20, 2024
2 parents 8a658ec + 86c9b5b commit 52adecf
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
29 changes: 27 additions & 2 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,33 @@ paths:
responses:
"200":
description: Index deleted
/index/{indexId}/questions:
get:
summary: Get default questions of an Index
operationId: getDefaultQuestionsOfIndex
parameters:
- name: indexId
in: path
required: true
description: Unique identifier of the Index
schema:
type: string
responses:
"200":
description: Successfully retrieved default questions
content:
application/json:
schema:
type: object
properties:
questions:
type: array
items:
type: string
"404":
description: Index not found
"500":
description: Server error
/indexes:
post:
summary: Create index
Expand Down Expand Up @@ -551,8 +578,6 @@ paths:
/profile:
patch:
summary: Update profile information
security:
- BearerAuth: []
requestBody:
required: true
content:
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indexnetwork/sdk",
"version": "0.0.2",
"version": "0.0.3",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 10 additions & 2 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ export default class IndexClient {

constructor({
domain,
session,
privateKey,
network,
}: {
domain: string;
privateKey: string;
session?: string;
privateKey?: string;
network?: string;
}) {
this.baseUrl = IndexConfig.apiURL;
this.network = network || "ethereum";
this.domain = domain;
this.privateKey = privateKey;
if (session) {
this.session = session;
} else {
this.privateKey = privateKey;
}
}

private async request<T>(
Expand All @@ -61,6 +67,8 @@ export default class IndexClient {
}

public async authenticate(): Promise<void> {
if (this.session) return;

if (!this.privateKey || !this.domain) {
throw new Error("Private key and domain is required to authenticate");
}
Expand Down
16 changes: 7 additions & 9 deletions web-app/src/components/ai/empty-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ export function EmptyScreen({
</div>
<div className="example-messages-empty-screen">
{indexIds && indexIds.length > 0
? defaultQuestions
?.slice(0, 2)
.map((message, i) => (
<ExampleMessageBox
key={i}
message={message}
setInput={setInput}
/>
))
? defaultQuestions?.map((message, i) => (
<ExampleMessageBox
key={i}
message={message}
setInput={setInput}
/>
))
: defaultQuestions?.map((message, i) => (
<ExampleMessageBox
key={i}
Expand Down
18 changes: 15 additions & 3 deletions web-app/src/components/site/indexes/AskIndexes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { toast } from "react-hot-toast";
import { API_ENDPOINTS } from "utils/constants";
import { maskDID, shuffleArray } from "utils/helper";
import NoIndexes from "../NoIndexes";
import { useApi } from "@/context/APIContext";

// TODO: remove this
const exampleMessages = [
Expand Down Expand Up @@ -52,7 +53,8 @@ const AskIndexes: FC<AskIndexesProps> = ({ chatID, did, indexIds }) => {

const { session } = useAuth();
const { viewedIndex } = useApp();
const { isIndex } = useRouteParams();
const { isIndex, id } = useRouteParams();
const { ready: apiReady, api } = useApi();

const [editingMessage, setEditingMessage] = useState<Message | undefined>();
const [editingIndex, setEditingIndex] = useState<number | undefined>();
Expand All @@ -61,9 +63,19 @@ const AskIndexes: FC<AskIndexesProps> = ({ chatID, did, indexIds }) => {

const bottomRef = useRef<null | HTMLDivElement>(null);

const fetchDefaultQuestions = useCallback(async (): Promise<void> => {
if (!apiReady || !isIndex) return;
try {
const defaultQuestions = await api!.getDefaultQuestionsOfIndex(id);
setDefaultQuestions(defaultQuestions);
} catch (error) {
console.error("Error fetching default questions", error);
}
}, [apiReady]);

useEffect(() => {
setDefaultQuestions(shuffleArray(exampleMessages));
}, []);
fetchDefaultQuestions();
}, [fetchDefaultQuestions]);

const handleEditClick = (message: Message, indexOfMessage: number) => {
setEditingMessage(message);
Expand Down
11 changes: 11 additions & 0 deletions web-app/src/services/api-service-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import litService from "./lit-service";
const API_ENDPOINTS = {
CHAT_STREAM: "/chat_stream",
INDEXES: "/indexes/:id",
DEFAULT_QUESTIONS_OF_INDEX: "/indexes/:id/questions",
GET_ALL_INDEXES: "/dids/:did/indexes",
CREATE_INDEX: "/indexes",
UPDATE_INDEX: "/indexes/:id",
Expand Down Expand Up @@ -118,6 +119,16 @@ class ApiService {
return data as Indexes;
}

async getDefaultQuestionsOfIndex(indexId: string): Promise<string[]> {
const url = API_ENDPOINTS.DEFAULT_QUESTIONS_OF_INDEX.replace(
":id",
indexId,
);
const { data } = await this.apiAxios.get<{ questions: string[] }>(url);
console.log("in api", data.questions);
return data.questions;
}

async getIndexWithIsCreator(indexId: string): Promise<Indexes | undefined> {
const url = API_ENDPOINTS.INDEXES.replace(":id", indexId).concat(
"?roles=true",
Expand Down

0 comments on commit 52adecf

Please sign in to comment.