Skip to content

Commit 2d391a1

Browse files
authored
Remove Tons of Dead Code (#19)
This is just the beginning of an attempt to streamline the project into something lean and maintainable. There were a bunch of types that are never used anywhere. There is also much more to be removed, but this is just a start (also removes three large/unused dependencies).
1 parent 5a9a339 commit 2d391a1

10 files changed

Lines changed: 24 additions & 1481 deletions

File tree

__tests__/integration/agents.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fetch from "node-fetch";
2-
31
export const BASE_URL = process.env.DEPLOYMENT_URL
42
? process.env.DEPLOYMENT_URL
53
: "http://localhost:3000";

__tests__/integration/tools.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { BASE_URL } from './agents.test';
32

43
beforeEach(async () => {

app/config.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import dotenv from 'dotenv';
2-
import ftsMetadata from '@/app/data/fts.json';
3-
import { isNearNetworkId, NearNetworkId } from '@/lib/types';
42

53
dotenv.config();
64

@@ -19,21 +17,4 @@ export const OPENAI_API_KEY = getMandatoryEnv('OPENAI_API_KEY');///
1917
export const ANTHROPIC_API_KEY = getMandatoryEnv('ANTHROPIC_API_KEY');///
2018
export const XAI_API_KEY = getMandatoryEnv('XAI_API_KEY');///
2119

22-
export const NEAR_RPC_URL = getMandatoryEnv('NEAR_RPC_URL');//?
23-
export const NEAR_NETWORK_ID = ((): NearNetworkId => {
24-
const id = getMandatoryEnv('NEAR_NETWORK_ID');//?
25-
if (!isNearNetworkId(id))
26-
throw new Error('NEAR_NETWORK_ID needs to be `testnet` or `mainnet`');
27-
return id;
28-
})();
29-
30-
export const PIMLICO_KEY = getMandatoryEnv('PIMLICO_KEY');
31-
3220
export const UNKEY_API_ID = getMandatoryEnv('UNKEY_API_ID');
33-
34-
export const IS_TESTNET = NEAR_NETWORK_ID === 'testnet';
35-
export const BITTE_WALLET = 'wallet.bitte.ai';
36-
export const BITTE_WALLET_URL = IS_TESTNET
37-
? `https://testnet.${BITTE_WALLET}`
38-
: `https://${BITTE_WALLET}`;
39-
export const FTS_METADATA = ftsMetadata;

app/data/fts.json

Lines changed: 0 additions & 476 deletions
This file was deleted.

jest.setup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { jest } from '@jest/globals';
2-
import fetch from 'node-fetch';
32

43
// Set default timeout for all tests (useful for integration tests that make real HTTP calls)
54
jest.setTimeout(30000);

lib/plugins.ts

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { OpenAI } from 'openai';
44
import { DEFAULT_MODEL } from '@/lib/constants';
55
import type {
66
BitteAssistantConfig,
7-
BitteMetadata,
87
BitteOpenAPISpec,
9-
BitteToolExecutor,
108
PluginToolSpec,
119
} from '@/lib/types';
1210
import { errorString } from './error';
@@ -175,79 +173,6 @@ export const generateAssistantFromOpenAPISpec = async ({
175173
return assistantObject;
176174
};
177175

178-
export const createExecutor = (
179-
tool: PluginToolSpec,
180-
metadata?: BitteMetadata
181-
): BitteToolExecutor => {
182-
return async (args) => {
183-
try {
184-
const { baseUrl, path, httpMethod } = tool.execution;
185-
const fullBaseUrl = baseUrl.startsWith('http')
186-
? baseUrl
187-
: `https://${baseUrl}`;
188-
189-
// Build URL with path parameters
190-
let url = `${fullBaseUrl}${path}`;
191-
const remainingArgs = { ...args };
192-
193-
url = url.replace(/\{(\w+)\}/g, (_, key) => {
194-
if (remainingArgs[key] === undefined) {
195-
throw new Error(`Missing required path parameter: ${key}`);
196-
}
197-
const value = remainingArgs[key];
198-
delete remainingArgs[key];
199-
return encodeURIComponent(String(value));
200-
});
201-
202-
// Setup request
203-
const headers: HeadersInit = {
204-
...(metadata && { 'mb-metadata': JSON.stringify(metadata) }),
205-
};
206-
207-
const method = httpMethod.toUpperCase();
208-
const fetchOptions: RequestInit = { method, headers };
209-
210-
// Handle query parameters
211-
const queryParams = new URLSearchParams();
212-
Object.entries(remainingArgs)
213-
.filter(([_key, value]) => value != null)
214-
.forEach(([key, value]) => queryParams.append(key, String(value)));
215-
216-
const queryString = queryParams.toString();
217-
if (queryString) {
218-
url += (url.includes('?') ? '&' : '?') + queryString;
219-
}
220-
221-
// Handle request body
222-
if (['POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'].includes(method)) {
223-
headers['Content-Type'] = 'application/json';
224-
fetchOptions.body = JSON.stringify(remainingArgs);
225-
}
226-
227-
// Execute request
228-
const response = await fetch(url, fetchOptions);
229-
230-
if (!response.ok) {
231-
throw new Error(
232-
`HTTP error during plugin tool execution: ${response.status} ${response.statusText}`
233-
);
234-
}
235-
// Parse response based on content type
236-
const contentType = response.headers.get('Content-Type') || '';
237-
const data = await (contentType.includes('application/json')
238-
? response.json()
239-
: contentType.includes('text')
240-
? response.text()
241-
: response.blob());
242-
243-
return { data };
244-
} catch (error) {
245-
return { error: errorString(error) };
246-
}
247-
};
248-
};
249-
250-
// converts pluginUrl to pluginId
251176
export const processPluginId = (
252177
urlParam: string | null
253178
): { pluginId?: string; error?: string } => {

lib/portfolio.ts

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)