Skip to content

Commit 10ac049

Browse files
authored
Merge pull request #137 from VishalPawar1010/#136-Add-config-to-Change-baseURL
config: added config to set baseURL automatically
2 parents 973e649 + 098dfaa commit 10ac049

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

src/app/App.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CopilotStreamController from "./controllers/copilotStreamController";
1111
import "./global.css";
1212
import WorkflowActivityList from "./components/WorkflowActivity";
1313
import { OSApi } from "@pieces.app/pieces-os-client";
14-
14+
import { config } from "../platform.config";
1515
const osApi = new OSApi(); // Create an instance of the OSApi
1616

1717
// types
@@ -104,7 +104,7 @@ export function App(): React.JSX.Element {
104104
};
105105
async function refreshSnippetList() {
106106
try {
107-
const assets = await new Pieces.AssetsApi().assetsSnapshot({});
107+
const assets = await new Pieces.AssetsApi(config).assetsSnapshot({});
108108
clearArray();
109109

110110
for (let i = 0; i < assets.iterable.length; i++) {
@@ -124,9 +124,9 @@ export function App(): React.JSX.Element {
124124

125125
async function searchSnippetList(snippetName: string) {
126126
try {
127-
const searchedAssets = await new Pieces.SearchApi().fullTextSearch({ query: snippetName });
128-
129-
// Check if there are no matching snippets
127+
const searchedAssets = await new Pieces.SearchApi(config).fullTextSearch({ query: snippetName });
128+
129+
// Check if there are no matching snippets
130130
if (searchedAssets.iterable.length === 0) {
131131
return 'No matching snippets found';
132132
}
@@ -137,8 +137,8 @@ export function App(): React.JSX.Element {
137137
let matchName: String;
138138

139139
// take that identifier to get your assets name using the Pieces.AssetApi()
140-
const asset = await new Pieces.AssetApi().assetSnapshot({asset: firstSearchMatchAssetIdentifier});
141-
140+
const asset = await new Pieces.AssetApi(config).assetSnapshot({asset: firstSearchMatchAssetIdentifier});
141+
142142
// assign that name to the matchName variable:
143143
matchName = asset.name;
144144
console.log("the matchName is" + matchName);

src/app/components/Asset/Asset.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Pieces from "@pieces.app/pieces-os-client";
22
import { SeededAsset, SeedTypeEnum } from "@pieces.app/pieces-os-client";
33
import { Application } from "@pieces.app/pieces-os-client";
4+
import { config } from "../../../platform.config";
45

56
type LocalAsset = {
67
name: string,
@@ -32,7 +33,7 @@ export async function createAsset(applicationData: Application, data: string, na
3233

3334
// make your api call.
3435
try {
35-
const _a = await new Pieces.AssetsApi().assetsCreateNewAsset({ seed: _seed });
36+
const _a = await new Pieces.AssetsApi(config).assetsCreateNewAsset({ seed: _seed });
3637
console.log("well howdy", _a);
3738
} catch (error) {
3839
console.error("Error creating asset:", error);
@@ -43,11 +44,11 @@ export async function createAsset(applicationData: Application, data: string, na
4344
export async function deleteAsset(_id: String, setArray: Function) {
4445
const newAssetsList: Array<LocalAsset> = [];
4546
try {
46-
const _assetList = await new Pieces.AssetsApi().assetsSnapshot({});
47+
const _assetList = await new Pieces.AssetsApi(config).assetsSnapshot({});
4748
for (let i = 0; i < _assetList.iterable.length; i++) {
4849
if (_assetList.iterable[i].id == _id) {
4950
try {
50-
await new Pieces.AssetsApi().assetsDeleteAsset({ asset: _assetList.iterable[i].id });
51+
await new Pieces.AssetsApi(config).assetsDeleteAsset({ asset: _assetList.iterable[i].id });
5152
console.log(_id);
5253
} catch (error) {
5354
console.error("Error deleting asset:", error);
@@ -74,13 +75,13 @@ export async function deleteAsset(_id: String, setArray: Function) {
7475
// then use the _id to select the snippet from the list of all snippets.
7576
export async function renameAsset(_name: string, _id: String) {
7677
try {
77-
const _assetList = await new Pieces.AssetsApi().assetsSnapshot({});
78+
const _assetList = await new Pieces.AssetsApi(config).assetsSnapshot({});
7879
for (let i = 0; i < _assetList.iterable.length; i++) {
7980
if (_assetList.iterable[i].id == _id) {
8081
let _asset = _assetList.iterable[i];
8182
_asset.name = _name;
8283
try {
83-
const _updated = await new Pieces.AssetApi().assetUpdate({ asset: _asset });
84+
const _updated = await new Pieces.AssetApi(config).assetUpdate({ asset: _asset });
8485
console.log("updated:", _updated);
8586
} catch (error) {
8687
console.error("Error updating asset:", error);

src/app/components/Copilot/Copilot.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import "./Copilot.css";
88
import { applicationData } from "../../App";
99
import CopilotStreamController from '../../controllers/copilotStreamController';
1010
import Markdown from '../ResponseFormat/Markdown';
11+
import { config } from '../../../platform.config';
1112

1213

1314
let GlobalConversationID: string;
@@ -30,7 +31,7 @@ export function createNewConversation() {
3031
// creates new conversation, .then is for confirmation on creation.
3132
// note the usage of transfereables here to expose the full conversation data and give access to the id and other
3233
// conversation values.
33-
new Pieces.ConversationsApi().conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => {
34+
new Pieces.ConversationsApi(config).conversationsCreateSpecificConversationRaw({transferables: true, seededConversation}).then((_c) => {
3435
console.log('Conversation created! : Here is the response:');
3536
console.log(_c);
3637

@@ -106,7 +107,7 @@ export function CopilotChat(): React.JSX.Element {
106107
const getInitialChat = async () => {
107108
let _name: string;
108109

109-
await new Pieces.ConversationsApi()
110+
await new Pieces.ConversationsApi(config)
110111
.conversationsSnapshot({})
111112
.then((output) => {
112113
if (

src/app/components/WorkflowActivity.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import * as Pieces from "@pieces.app/pieces-os-client";
33
import ActivityCard from './ActivityCard';
4+
import { config } from '../../platform.config';
45

56
interface WorkflowActivity {
67
id: string;
@@ -20,7 +21,7 @@ const WorkflowActivityList: React.FC = () => {
2021
}
2122

2223
React.useEffect(() => {
23-
new Pieces.ActivitiesApi().activitiesSnapshot({}).then((activities) => {
24+
new Pieces.ActivitiesApi(config).activitiesSnapshot({}).then((activities) => {
2425
console.log(activities);
2526
clearActivities();
2627
for(let i = 0; i < activities.iterable.length; i++){

src/app/controllers/copilotStreamController.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import * as Pieces from "@pieces.app/pieces-os-client";
3+
import { BASE_URL, WS_URL } from "../../platform.config";
34

45
export type MessageOutput = {
56
answer: string;
@@ -51,7 +52,7 @@ export default class CopilotStreamController {
5152
if (!this.ws) {
5253
this.connect();
5354
} // need to connect the socket if it's not established.
54-
await fetch(`http://localhost:1000/.well-known/health`).catch(() => {
55+
await fetch(`${BASE_URL}/.well-known/health`).catch(() => {
5556
// @TODO add error handling here
5657
});
5758

@@ -70,7 +71,7 @@ export default class CopilotStreamController {
7071
* Connects the websocket, handles all message callbacks, error handling, and rendering.
7172
*/
7273
private connect() {
73-
this.ws = new WebSocket(`ws://localhost:1000/qgpt/stream`);
74+
this.ws = new WebSocket(`${WS_URL}/qgpt/stream`);
7475

7576
let totalMessage = '';
7677
let relevantSnippets: Pieces.RelevantQGPTSeed[] = [];

src/app/utils/Connect.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Pieces from "@pieces.app/pieces-os-client";
2+
import { config } from "../../platform.config";
23

34
// ============================ [/connect]=============================//
45
const tracked_application = {
@@ -8,7 +9,7 @@ const tracked_application = {
89
}
910
// TODO: this will need to be updated once we are further along with the connector work.
1011
export async function connect(): Promise<JSON> {
11-
const connectorApi = new Pieces.ConnectorApi();
12+
const connectorApi = new Pieces.ConnectorApi(config);
1213
const response = await connectorApi.connect({
1314
seededConnectorConnection: { application: tracked_application },
1415
});

src/platform.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as Pieces from "@pieces.app/pieces-os-client";
2+
3+
let BASE_URL: string;
4+
let WS_URL: string;
5+
6+
if (Pieces.PlatformEnum.Linux) {
7+
BASE_URL = 'http://localhost:5323';
8+
WS_URL = 'ws://localhost:5323';
9+
} else {
10+
BASE_URL = 'http://localhost:1000';
11+
WS_URL = 'ws://localhost:1000';
12+
}
13+
14+
const config = new Pieces.Configuration({
15+
basePath: BASE_URL,
16+
});
17+
export { BASE_URL, WS_URL, config };

0 commit comments

Comments
 (0)