Skip to content

Commit b77ae1f

Browse files
authored
Merge pull request #1410 from Portkey-AI/fix/build-errors-07-nov
fix: build errors
2 parents 59622b7 + 0e66619 commit b77ae1f

File tree

12 files changed

+51
-20
lines changed

12 files changed

+51
-20
lines changed

src/apm/loki/envConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Environment } from '../../utils/env';
33
const requiredEnvVars = ['NODE_ENV', 'SERVICE_NAME', 'LOKI_AUTH', 'LOKI_HOST'];
44

55
export const loadAndValidateEnv = () => {
6-
const env = Environment({}) as Record<string, string>;
6+
const env = Environment() as Record<string, string>;
77
requiredEnvVars.forEach((varName) => {
88
if (!env[varName]) {
99
console.error(`Missing required environment variable: ${varName}`);

src/apm/loki/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let LokiLogger: any;
44

55
try {
66
const { createLogger, transports, format } = await import('winston');
7-
const LokiTransport = await import('winston-loki');
7+
const LokiTransport = (await import('winston-loki')).default;
88

99
const envVars = loadAndValidateEnv();
1010

src/apm/prometheus/envConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const requiredEnvVars = [
88
];
99

1010
export const loadAndValidateEnv = (): { [key: string]: string } => {
11-
const env = Environment({}) as Record<string, string>;
11+
const env = Environment() as Record<string, string>;
1212
requiredEnvVars.forEach((varName) => {
1313
if (!env[varName]) {
1414
console.error(`Missing required environment variable: ${varName}`);

src/apm/prometheus/prometheusClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ client.collectDefaultMetrics({
2323

2424
const loadMetadataKeys = () => {
2525
return (
26-
Environment({})
26+
Environment()
2727
.PROMETHEUS_LABELS_METADATA_ALLOWED_KEYS?.replaceAll(' ', '')
2828
.split(',') ?? []
2929
).map((key: string) => `metadata_${key}`);
@@ -305,7 +305,7 @@ export const llmCacheProcessingDurationMilliseconds = new client.Histogram({
305305
export const getCustomLabels = (metadata: string | undefined) => {
306306
let customLabels: Record<string, any> = {};
307307
const allowedKeys =
308-
Environment({}).PROMETHEUS_LABELS_METADATA_ALLOWED_KEYS?.split(',') ?? [];
308+
Environment().PROMETHEUS_LABELS_METADATA_ALLOWED_KEYS?.split(',') ?? [];
309309
if (typeof metadata === 'string') {
310310
try {
311311
const parsedMetadata = JSON.parse(metadata);

src/globals.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,19 @@ export const AtomicOperations = {
279279
export enum RateLimiterKeyTypes {
280280
VIRTUAL_KEY = 'VIRTUAL_KEY',
281281
API_KEY = 'API_KEY',
282+
WORKSPACE = 'WORKSPACE',
282283
INTEGRATION_WORKSPACE = 'INTEGRATION_WORKSPACE',
283284
}
285+
286+
export const METRICS_KEYS = {
287+
AUTH_N_MIDDLEWARE_START: 'authNMiddlewareStart',
288+
AUTH_N_MIDDLEWARE_END: 'authNMiddlewareEnd',
289+
API_KEY_RATE_LIMIT_CHECK_START: 'apiKeyRateLimitCheckStart',
290+
API_KEY_RATE_LIMIT_CHECK_END: 'apiKeyRateLimitCheckEnd',
291+
PORTKEY_MIDDLEWARE_PRE_REQUEST_START: 'portkeyMiddlewarePreRequestStart',
292+
PORTKEY_MIDDLEWARE_PRE_REQUEST_END: 'portkeyMiddlewarePreRequestEnd',
293+
PORTKEY_MIDDLEWARE_POST_REQUEST_START: 'portkeyMiddlewarePostRequestStart',
294+
PORTKEY_MIDDLEWARE_POST_REQUEST_END: 'portkeyMiddlewarePostRequestEnd',
295+
LLM_CACHE_GET_START: 'llmCacheGetStart',
296+
LLM_CACHE_GET_END: 'llmCacheGetEnd',
297+
};

src/middlewares/requestValidator/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const BLOCKED_TLDS = [
4747

4848
// Parse allowed custom hosts from environment variable
4949
// Format: comma-separated list of domains/IPs (e.g., "localhost,127.0.0.1,example.com")
50-
const TRUSTED_CUSTOM_HOSTS = (c: Context) => {
50+
const TRUSTED_CUSTOM_HOSTS = (c?: Context) => {
5151
const envVar = Environment(c)?.TRUSTED_CUSTOM_HOSTS;
5252
if (!envVar) {
5353
// Default allowed hosts for local development

src/providers/anthropic-base/messages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ProviderConfig } from '../types';
1+
import { ParameterConfig, ProviderConfig } from '../types';
22

33
export const messagesBaseConfig: ProviderConfig = {
44
model: {
@@ -82,7 +82,7 @@ export const getMessagesConfig = ({
8282
if (defaultValues) {
8383
Object.keys(defaultValues).forEach((key) => {
8484
if (!Array.isArray(baseParams[key])) {
85-
baseParams[key].default = defaultValues[key];
85+
(baseParams[key] as ParameterConfig).default = defaultValues[key];
8686
}
8787
});
8888
}

src/providers/cohere/chatComplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ export const CohereChatCompleteStreamChunkTransform: (
291291
index: streamState.lastIndex,
292292
delta: {
293293
role: 'assistant',
294-
content: parsedChunk.delta?.message?.content?.text ?? '',
295-
tool_calls: parsedChunk.delta?.message?.tool_calls,
294+
content: (parsedChunk as any).delta?.message?.content?.text ?? '',
295+
tool_calls: (parsedChunk as any).delta?.message?.tool_calls,
296296
},
297297
logprobs: null,
298298
finish_reason: null,

src/providers/google-vertex-ai/chatComplete.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../anthropic/types';
2222
import {
2323
GoogleMessage,
24+
GoogleMessagePart,
2425
GoogleMessageRole,
2526
GoogleToolConfig,
2627
SYSTEM_INSTRUCTION_DISABLED_MODELS,
@@ -82,7 +83,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
8283
return;
8384

8485
const role = transformOpenAIRoleToGoogleRole(message.role);
85-
let parts = [];
86+
let parts: GoogleMessagePart[] = [];
8687

8788
if (message.role === 'assistant' && message.tool_calls) {
8889
message.tool_calls.forEach((tool_call: ToolCall) => {
@@ -98,15 +99,15 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
9899
functionResponse: {
99100
name: message.name ?? 'gateway-tool-filler-name',
100101
response: {
101-
output: message.content,
102+
output: message.content ?? '',
102103
},
103104
},
104105
});
105106
} else if (message.content && typeof message.content === 'object') {
106107
message.content.forEach((c: ContentType) => {
107108
if (c.type === 'text') {
108109
parts.push({
109-
text: c.text,
110+
text: c.text ?? '',
110111
});
111112
} else if (c.type === 'input_audio') {
112113
parts.push(transformInputAudioPart(c));
@@ -149,7 +150,7 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
149150
parts.push({
150151
inlineData: {
151152
mimeType: 'image/jpeg',
152-
data: c.image_url?.url,
153+
data: c.image_url?.url ?? '',
153154
},
154155
});
155156
}

src/providers/google-vertex-ai/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ErrorResponse, FinetuneRequest, Logprobs } from '../types';
1515
import { Context } from 'hono';
1616
import { env } from 'hono/adapter';
1717
import { ContentType, JsonSchema, Tool } from '../../types/requestBody';
18+
import { GoogleMessagePart } from '../google/chatComplete';
1819

1920
/**
2021
* Encodes an object as a Base64 URL-encoded string.
@@ -717,15 +718,15 @@ export const OPENAI_AUDIO_FORMAT_TO_VERTEX_MIME_TYPE_MAPPING = {
717718
wav: 'audio/wav',
718719
};
719720

720-
export const transformInputAudioPart = (c: ContentType) => {
721+
export const transformInputAudioPart = (c: ContentType): GoogleMessagePart => {
721722
const data = c.input_audio?.data;
722723
const mimeType =
723724
OPENAI_AUDIO_FORMAT_TO_VERTEX_MIME_TYPE_MAPPING[
724725
c.input_audio?.format as 'mp3' | 'wav'
725726
];
726727
return {
727728
inlineData: {
728-
data,
729+
data: data ?? '',
729730
mimeType,
730731
},
731732
};

0 commit comments

Comments
 (0)