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

feat: add chat/agent related sdk and react-queries #1635

Merged
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
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instill-sdk",
"version": "0.12.0",
"version": "0.13.0-rc.0",
"description": "Instill AI's Typescript SDK",
"repository": "https://github.com/instill-ai/typescript-sdk.git",
"bugs": "https://github.com/instill-ai/community/issues",
Expand Down
164 changes: 164 additions & 0 deletions packages/sdk/src/application/ApplicationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import {
Conversation,
CreateApplicationRequest,
CreateApplicationResponse,
CreateChatResponse,
CreateConversationRequest,
CreateConversationResponse,
CreateMessageRequest,
CreateMessageResponse,
CreateNamespaceAgentRequest,
CreateNamespaceAgentResponse,
CreateNamespaceChatRequest,
DeleteApplicationRequest,
DeleteConversationRequest,
DeleteMessageRequest,
DeleteNamespaceAgentRequest,
DeleteNamespaceChatRequest,
GetApplicationRequest,
GetApplicationResponse,
GetPlaygroundConversationRequest,
Expand All @@ -25,6 +31,10 @@ import {
ListConversationsResponse,
ListMessagesRequest,
ListMessagesResponse,
ListNamespaceAgentsRequest,
ListNamespaceAgentsResponse,
ListNamespaceChatsRequest,
ListNamespaceChatsResponse,
Message,
RestartPlaygroundConversationRequest,
RestartPlaygroundConversationResponse,
Expand All @@ -34,6 +44,10 @@ import {
UpdateConversationResponse,
UpdateMessageRequest,
UpdateMessageResponse,
UpdateNamespaceAgentRequest,
UpdateNamespaceAgentResponse,
UpdateNamespaceChatRequest,
UpdateNamespaceChatResponse,
} from "./types";

export class ApplicationClient extends APIResource {
Expand Down Expand Up @@ -499,4 +513,154 @@ export class ApplicationClient extends APIResource {
throw error;
}
}

/* ----------------------------------------------------------------------------
* Agent
* ---------------------------------------------------------------------------*/

async createNamespaceAgent(props: CreateNamespaceAgentRequest) {
const { namespaceId, ...payload } = props;

const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/agents`,
});

try {
const response = await this._client.post<CreateNamespaceAgentResponse>(
queryString,
{
body: JSON.stringify(payload),
},
);
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
}

async listNamespaceAgents(props: ListNamespaceAgentsRequest) {
const { namespaceId } = props;

const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/agents`,
});

try {
const response =
await this._client.get<ListNamespaceAgentsResponse>(queryString);
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
}

async updateNamespaceAgent(props: UpdateNamespaceAgentRequest) {
const { namespaceId, agentUid, ...payload } = props;

const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/agents/${agentUid}`,
});

try {
const response = await this._client.put<UpdateNamespaceAgentResponse>(
queryString,
{
body: JSON.stringify(payload),
},
);
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
}

async deleteNamespaceAgent(props: DeleteNamespaceAgentRequest) {
const { namespaceId, agentUid } = props;

const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/agents/${agentUid}`,
});

try {
await this._client.delete(queryString);
return Promise.resolve();
} catch (error) {
return Promise.reject(error);
}
}

/* ----------------------------------------------------------------------------
* Chat
* ---------------------------------------------------------------------------*/

async createNamespaceChat(props: CreateNamespaceChatRequest) {
const { namespaceId, ...payload } = props;

const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/chats`,
});

try {
const response = await this._client.post<CreateChatResponse>(
queryString,
{
body: JSON.stringify(payload),
},
);
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
}

async listNamespaceChats(props: ListNamespaceChatsRequest) {
const { namespaceId } = props;

const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/chats`,
});

try {
const response =
await this._client.get<ListNamespaceChatsResponse>(queryString);
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
}

async updateNamespaceChat(props: UpdateNamespaceChatRequest) {
const { namespaceId, chatUid, ...payload } = props;

try {
const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/chats/${chatUid}`,
});

const response = await this._client.put<UpdateNamespaceChatResponse>(
queryString,
{
body: JSON.stringify(payload),
},
);
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
}

async deleteNamespaceChat(props: DeleteNamespaceChatRequest) {
const { namespaceId, chatUid } = props;

try {
const queryString = getQueryString({
baseURL: `/namespaces/${namespaceId}/chats/${chatUid}`,
});

await this._client.delete(queryString);
return Promise.resolve();
} catch (error) {
return Promise.reject(error);
}
}
}
119 changes: 118 additions & 1 deletion packages/sdk/src/application/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Chunk } from "../catalog";
import { Nullable, Permission } from "../types";
import { GeneralRecord, Nullable, Permission } from "../types";

export type Application = {
name: string;
Expand Down Expand Up @@ -300,3 +300,120 @@ export type DeleteConversationRequest = {
appId: string;
conversationId: string;
};

export type AiAgentTool = {
pipelineId: string;
name: string;
config: GeneralRecord;
};

export type AiAgentMetadata = {
instructions: string;
tools: AiAgentTool[];
catalogUids: string[];
chunkTopK: number;
};

export type CreateNamespaceAgentRequest = {
namespaceId: string;
displayName?: string;
description?: string;
tags?: string[];
aiAgentMetadata: AiAgentMetadata;
};

export type Agent = {
agentUid: string;
displayName: string;
description: string;
namespaceUid: string;
tags: string[];
aiAgentMetadata: AiAgentMetadata;
creatorUid: string;
createTime: string;
updateTime: string;
};

export type CreateNamespaceAgentResponse = {
agent: Agent;
};

export type ListNamespaceAgentsRequest = {
namespaceId: string;
};

export type ListNamespaceAgentsResponse = {
agents: Agent[];
};

export type DeleteNamespaceAgentRequest = {
namespaceId: string;
agentUid: string;
};

export type UpdateNamespaceAgentRequest = {
namespaceId: string;
agentUid: string;
displayName?: string;
description?: string;
tags?: string[];
aiAgentMetadata?: AiAgentMetadata;
};

export type UpdateNamespaceAgentResponse = {
agent: Agent;
};

export type Chat = {
uid: string;
namespaceid: string;
lastUsedCatalogUid: string;
lastUsedTopK: number;
createTime: string;
updateTime: string;
aiAgentMetadata: AiAgentMetadata;
chatDisplayName: string;
tempCatalogId: string;
};

export type CreateNamespaceChatRequest = {
namespaceId: string;
chatDisplayName?: string;
aiAgentApp: AiAgentMetadata;
};

export type CreateChatResponse = {
chat: Chat;
};

export type ListNamespaceChatsRequest = {
namespaceId: string;
};

export type ListNamespaceChatsResponse = {
chats: Chat[];
};

export type UpdateNamespaceChatRequest = {
namespaceId: string;
chatUid: string;
chatDisplayName?: string;
aiAgentMetadata: AiAgentMetadata;
};

export type UpdateNamespaceChatResponse = {
chat: Chat;
};

export type DeleteNamespaceChatRequest = {
namespaceId: string;
chatUid: string;
};

export type ListNamespaceChatMessagesRequest = {
namespaceId: string;
chatUid: string;
pageSize?: number;
pageToken?: string;
ifAll?: boolean;
};
2 changes: 1 addition & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@instill-ai/toolkit",
"version": "0.113.0-rc.5",
"version": "0.113.0-rc.6",
"description": "Instill AI's frontend toolkit",
"repository": "https://github.com/instill-ai/design-system.git",
"bugs": "https://github.com/instill-ai/design-system/issues",
Expand Down
21 changes: 21 additions & 0 deletions packages/toolkit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
import BulletList from "@tiptap/extension-bullet-list";
import Document from "@tiptap/extension-document";
import ListItem from "@tiptap/extension-list-item";
import Mention from "@tiptap/extension-mention";
import Paragraph from "@tiptap/extension-paragraph";
import Placeholder from "@tiptap/extension-placeholder";
import Text from "@tiptap/extension-text";
import { EditorContent, useEditor } from "@tiptap/react";

export * from "./components";
export * from "./constant";
export * from "./lib";
export * from "./view";

export const TipTap = {
BulletList,
Document,
ListItem,
Mention,
Paragraph,
Text,
Placeholder,
EditorContent,
useEditor,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from "./useCreateNamespaceAgent";
export * from "./useCreateNamespaceChat";
export * from "./useDeleteNamespaceAgent";
export * from "./useDeleteNamespaceChat";
export * from "./useListNamespaceAgents";
export * from "./useListNamespaceChats";
export * from "./useUpdateNamespaceAgent";
export * from "./useUpdateNamespaceChat";
Loading
Loading