diff --git a/src/app/App.tsx b/src/app/App.tsx index bc14f43..ca97baa 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -11,7 +11,7 @@ import CopilotStreamController from "./controllers/copilotStreamController"; import "./global.css"; import WorkflowActivityList from "./components/WorkflowActivity"; import { OSApi } from "@pieces.app/pieces-os-client"; - +import { config } from "../platform.config"; const osApi = new OSApi(); // Create an instance of the OSApi // types @@ -104,7 +104,7 @@ export function App(): React.JSX.Element { }; async function refreshSnippetList() { try { - const assets = await new Pieces.AssetsApi().assetsSnapshot({}); + const assets = await new Pieces.AssetsApi(config).assetsSnapshot({}); clearArray(); for (let i = 0; i < assets.iterable.length; i++) { @@ -124,9 +124,9 @@ export function App(): React.JSX.Element { async function searchSnippetList(snippetName: string) { try { - const searchedAssets = await new Pieces.SearchApi().fullTextSearch({ query: snippetName }); - - // Check if there are no matching snippets + const searchedAssets = await new Pieces.SearchApi(config).fullTextSearch({ query: snippetName }); + + // Check if there are no matching snippets if (searchedAssets.iterable.length === 0) { return 'No matching snippets found'; } @@ -137,8 +137,8 @@ export function App(): React.JSX.Element { let matchName: String; // take that identifier to get your assets name using the Pieces.AssetApi() - const asset = await new Pieces.AssetApi().assetSnapshot({asset: firstSearchMatchAssetIdentifier}); - + const asset = await new Pieces.AssetApi(config).assetSnapshot({asset: firstSearchMatchAssetIdentifier}); + // assign that name to the matchName variable: matchName = asset.name; console.log("the matchName is" + matchName); diff --git a/src/app/components/Asset/Asset.tsx b/src/app/components/Asset/Asset.tsx index 4d4e117..0106d77 100644 --- a/src/app/components/Asset/Asset.tsx +++ b/src/app/components/Asset/Asset.tsx @@ -1,6 +1,7 @@ import * as Pieces from "@pieces.app/pieces-os-client"; import { SeededAsset, SeedTypeEnum } from "@pieces.app/pieces-os-client"; import { Application } from "@pieces.app/pieces-os-client"; +import { config } from "../../../platform.config"; type LocalAsset = { name: string, @@ -32,7 +33,7 @@ export async function createAsset(applicationData: Application, data: string, na // make your api call. try { - const _a = await new Pieces.AssetsApi().assetsCreateNewAsset({ seed: _seed }); + const _a = await new Pieces.AssetsApi(config).assetsCreateNewAsset({ seed: _seed }); console.log("well howdy", _a); } catch (error) { console.error("Error creating asset:", error); @@ -43,11 +44,11 @@ export async function createAsset(applicationData: Application, data: string, na export async function deleteAsset(_id: String, setArray: Function) { const newAssetsList: Array = []; try { - const _assetList = await new Pieces.AssetsApi().assetsSnapshot({}); + const _assetList = await new Pieces.AssetsApi(config).assetsSnapshot({}); for (let i = 0; i < _assetList.iterable.length; i++) { if (_assetList.iterable[i].id == _id) { try { - await new Pieces.AssetsApi().assetsDeleteAsset({ asset: _assetList.iterable[i].id }); + await new Pieces.AssetsApi(config).assetsDeleteAsset({ asset: _assetList.iterable[i].id }); console.log(_id); } catch (error) { console.error("Error deleting asset:", error); @@ -74,13 +75,13 @@ export async function deleteAsset(_id: String, setArray: Function) { // then use the _id to select the snippet from the list of all snippets. export async function renameAsset(_name: string, _id: String) { try { - const _assetList = await new Pieces.AssetsApi().assetsSnapshot({}); + const _assetList = await new Pieces.AssetsApi(config).assetsSnapshot({}); for (let i = 0; i < _assetList.iterable.length; i++) { if (_assetList.iterable[i].id == _id) { let _asset = _assetList.iterable[i]; _asset.name = _name; try { - const _updated = await new Pieces.AssetApi().assetUpdate({ asset: _asset }); + const _updated = await new Pieces.AssetApi(config).assetUpdate({ asset: _asset }); console.log("updated:", _updated); } catch (error) { console.error("Error updating asset:", error); diff --git a/src/app/components/Copilot/Copilot.tsx b/src/app/components/Copilot/Copilot.tsx index afb506c..2fbac0b 100644 --- a/src/app/components/Copilot/Copilot.tsx +++ b/src/app/components/Copilot/Copilot.tsx @@ -8,6 +8,7 @@ import "./Copilot.css"; import { applicationData } from "../../App"; import CopilotStreamController from '../../controllers/copilotStreamController'; import Markdown from '../ResponseFormat/Markdown'; +import { config } from '../../../platform.config'; let GlobalConversationID: string; @@ -30,7 +31,7 @@ export function createNewConversation() { // creates new conversation, .then is for confirmation on creation. // note the usage of transfereables here to expose the full conversation data and give access to the id and other // conversation values. - new Pieces.ConversationsApi().conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => { + new Pieces.ConversationsApi(config).conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => { console.log('Conversation created! : Here is the response:'); console.log(_c); @@ -106,7 +107,7 @@ export function CopilotChat(): React.JSX.Element { const getInitialChat = async () => { let _name: string; - await new Pieces.ConversationsApi() + await new Pieces.ConversationsApi(config) .conversationsSnapshot({}) .then((output) => { if ( diff --git a/src/app/components/WorkflowActivity.tsx b/src/app/components/WorkflowActivity.tsx index 3b584e5..f1bd01b 100644 --- a/src/app/components/WorkflowActivity.tsx +++ b/src/app/components/WorkflowActivity.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import * as Pieces from "@pieces.app/pieces-os-client"; import ActivityCard from './ActivityCard'; +import { config } from '../../platform.config'; interface WorkflowActivity { id: string; @@ -20,7 +21,7 @@ const WorkflowActivityList: React.FC = () => { } React.useEffect(() => { - new Pieces.ActivitiesApi().activitiesSnapshot({}).then((activities) => { + new Pieces.ActivitiesApi(config).activitiesSnapshot({}).then((activities) => { console.log(activities); clearActivities(); for(let i = 0; i < activities.iterable.length; i++){ diff --git a/src/app/controllers/copilotStreamController.tsx b/src/app/controllers/copilotStreamController.tsx index c001dc0..5175ac6 100644 --- a/src/app/controllers/copilotStreamController.tsx +++ b/src/app/controllers/copilotStreamController.tsx @@ -1,5 +1,6 @@ import * as Pieces from "@pieces.app/pieces-os-client"; +import { BASE_URL, WS_URL } from "../../platform.config"; export type MessageOutput = { answer: string; @@ -51,7 +52,7 @@ export default class CopilotStreamController { if (!this.ws) { this.connect(); } // need to connect the socket if it's not established. - await fetch(`http://localhost:1000/.well-known/health`).catch(() => { + await fetch(`${BASE_URL}/.well-known/health`).catch(() => { // @TODO add error handling here }); @@ -70,7 +71,7 @@ export default class CopilotStreamController { * Connects the websocket, handles all message callbacks, error handling, and rendering. */ private connect() { - this.ws = new WebSocket(`ws://localhost:1000/qgpt/stream`); + this.ws = new WebSocket(`${WS_URL}/qgpt/stream`); let totalMessage = ''; let relevantSnippets: Pieces.RelevantQGPTSeed[] = []; diff --git a/src/app/utils/Connect.tsx b/src/app/utils/Connect.tsx index 1f73dad..98c44ec 100644 --- a/src/app/utils/Connect.tsx +++ b/src/app/utils/Connect.tsx @@ -1,4 +1,5 @@ import * as Pieces from "@pieces.app/pieces-os-client"; +import { config } from "../../platform.config"; // ============================ [/connect]=============================// const tracked_application = { @@ -8,7 +9,7 @@ const tracked_application = { } // TODO: this will need to be updated once we are further along with the connector work. export async function connect(): Promise { - const connectorApi = new Pieces.ConnectorApi(); + const connectorApi = new Pieces.ConnectorApi(config); const response = await connectorApi.connect({ seededConnectorConnection: { application: tracked_application }, }); diff --git a/src/platform.config.ts b/src/platform.config.ts new file mode 100644 index 0000000..ea7cc5a --- /dev/null +++ b/src/platform.config.ts @@ -0,0 +1,17 @@ +import * as Pieces from "@pieces.app/pieces-os-client"; + +let BASE_URL: string; +let WS_URL: string; + +if (Pieces.PlatformEnum.Linux) { + BASE_URL = 'http://localhost:5323'; + WS_URL = 'ws://localhost:5323'; +} else { + BASE_URL = 'http://localhost:1000'; + WS_URL = 'ws://localhost:1000'; +} + +const config = new Pieces.Configuration({ + basePath: BASE_URL, +}); +export { BASE_URL, WS_URL, config }; \ No newline at end of file