Skip to content

config: added config to set baseURL automatically #137

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

Merged
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
14 changes: 7 additions & 7 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++) {
Expand All @@ -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';
}
Expand All @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/app/components/Asset/Asset.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -43,11 +44,11 @@ export async function createAsset(applicationData: Application, data: string, na
export async function deleteAsset(_id: String, setArray: Function) {
const newAssetsList: Array<LocalAsset> = [];
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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/WorkflowActivity.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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++){
Expand Down
5 changes: 3 additions & 2 deletions src/app/controllers/copilotStreamController.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
});

Expand All @@ -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[] = [];
Expand Down
3 changes: 2 additions & 1 deletion src/app/utils/Connect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Pieces from "@pieces.app/pieces-os-client";
import { config } from "../../platform.config";

// ============================ [/connect]=============================//
const tracked_application = {
Expand All @@ -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<JSON> {
const connectorApi = new Pieces.ConnectorApi();
const connectorApi = new Pieces.ConnectorApi(config);
const response = await connectorApi.connect({
seededConnectorConnection: { application: tracked_application },
});
Expand Down
17 changes: 17 additions & 0 deletions src/platform.config.ts
Original file line number Diff line number Diff line change
@@ -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 };
Loading