Skip to content
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
10 changes: 10 additions & 0 deletions config.template.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@
"apiKey": "",
"apiBaseUrl": "https://llm.onerouter.pro/v1"
},
// BytePlus ModelArk. One key powers chat (Seed/GLM/DeepSeek), image
// generation (Seedream) and video generation (Seedance); `apiBaseUrl`
// selects the region; see
// https://docs.byteplus.com/en/docs/ModelArk/1330310 for options.
"byteplus": {
"apiKey": "",
"apiBaseUrl": "https://ark.ap-southeast.bytepluses.com/api/v3"
},
"zai": { "apiKey": "" },
"alibaba": { "apiKey": "" },
"together-ai": { "apiKey": "" },
// Local Ollama. `enabled: false` skips the auto-probe at startup
// (otherwise Puter logs ECONNREFUSED on every boot when no Ollama
Expand Down
9 changes: 4 additions & 5 deletions src/backend/clients/event/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,10 @@ export type EventKey = keyof EventMap & string;
// Generates a wildcard for every non-final dot-separated prefix of K.
export type WildcardPrefixes<K extends string> =
K extends `${infer Head}.${infer Tail}`
?
| `${Head}.*`
| (Tail extends `${string}.${string}`
? `${Head}.${WildcardPrefixes<Tail>}`
: never)
? | `${Head}.*`
| (Tail extends `${string}.${string}`
? `${Head}.${WildcardPrefixes<Tail>}`
: never)
: never;

export type ListenKey = EventKey | WildcardPrefixes<EventKey>;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/controllers/auth/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,7 @@ export class AuthController extends PuterController {
is_temp: user!.password === null && user!.email === null,
ip:
(req?.headers?.['x-forwarded-for'] as
| string
| undefined) ||
string | undefined) ||
(
req as unknown as {
connection?: { remoteAddress?: string };
Expand Down
3 changes: 1 addition & 2 deletions src/backend/controllers/drivers/DriverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ export class DriverController extends PuterController {

if (req.actor) {
const permService = this.services.permission as unknown as
| PermissionService
| undefined;
PermissionService | undefined;
if (permService) {
// Build via PermissionUtil.join so any `:` in a driver or
// interface name is escaped — raw interpolation would let a
Expand Down
3 changes: 1 addition & 2 deletions src/backend/controllers/puterai/PuterAIController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@ export class PuterAIController extends PuterController {
text: extractTextContent(
(
messageResult.message as
| Record<string, unknown>
| undefined
Record<string, unknown> | undefined
)?.content,
),
index: 0,
Expand Down
3 changes: 1 addition & 2 deletions src/backend/core/http/middleware/gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ export const assertVerifiedAccount = (
*/
export const assertPhoneVerified = (
user:
| { phone?: unknown; requires_phone_verification?: unknown }
| undefined,
{ phone?: unknown; requires_phone_verification?: unknown } | undefined,
): void => {
if (user?.phone && !user?.requires_phone_verification) return;
throw new HttpError(403, 'Please verify your phone number to continue', {
Expand Down
11 changes: 2 additions & 9 deletions src/backend/core/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import type { Actor } from '../actor';
* it instead of accepting any token that authenticates.
*/
export type TokenSource =
| 'body'
| 'header'
| 'x-api-key'
| 'cookie'
| 'query'
| 'handshake';
'body' | 'header' | 'x-api-key' | 'cookie' | 'query' | 'handshake';

/**
* Every route method PuterRouter exposes. Mirrors the express router surface
Expand Down Expand Up @@ -441,9 +436,7 @@ export type AuthRequired<O extends RouteOptions> = O extends {
? true
: O extends {
requireSubscription:
| true
| readonly string[]
| string[];
true | readonly string[] | string[];
}
? true
: false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const FULL_PROVIDER_CONFIG = {
'together-ai': { apiKey: 'k' },
openrouter: { apiKey: 'k', apiBaseUrl: 'https://openrouter.test' },
infron: { apiKey: 'k' },
byteplus: { apiKey: 'k' },
neuralwatt: { apiKey: 'k' },
// Suppress auto-discovery of a developer's local Ollama.
ollama: { enabled: false },
Expand Down Expand Up @@ -184,6 +185,7 @@ describe('ChatCompletionDriver provider registration', () => {
'together-ai',
'openrouter',
'infron',
'byteplus',
'neuralwatt',
'fake-chat',
]) {
Expand Down
13 changes: 13 additions & 0 deletions src/backend/drivers/ai-chat/ChatCompletionDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { AI_CONCURRENT, AI_RATE_LIMIT } from '../util/aiLimits.js';
import { AlibabaProvider } from './providers/alibaba/AlibabaProvider.js';
import { AzureChatProvider } from './providers/azure/AzureChatProvider.js';
import { AzureResponsesProvider } from './providers/azure/AzureResponsesProvider.js';
import { BytePlusProvider } from './providers/byteplus/BytePlusProvider.js';
import { ClaudeProvider } from './providers/claude/ClaudeProvider.js';
import { DeepSeekProvider } from './providers/deepseek/DeepSeekProvider.js';
import { FakeChatProvider } from './providers/FakeChatProvider.js';
Expand Down Expand Up @@ -1251,6 +1252,18 @@ export class ChatCompletionDriver extends PuterDriver {
);
}

const byteplus = providers['byteplus'];
const byteplusKey = readKey(byteplus);
if (byteplusKey) {
this.#providers['byteplus'] = new BytePlusProvider(
{
apiKey: byteplusKey,
apiBaseUrl: byteplus?.apiBaseUrl as string | undefined,
},
metering,
);
}

const neuralwatt = providers['neuralwatt'];
const neuralwattKey = readKey(neuralwatt);
if (neuralwattKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2024-present Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* Integration test for the BytePlus ModelArk provider.
*
* Uses `seed-1-6-flash-250715` with `thinking: disabled` passed through
* `custom`. Ark's seed models default to deep reasoning and route those
* tokens to a `reasoning_content` field, leaving `content` empty under
* tight budgets. Disabling thinking forces a plain text response so the
* usual `message.content` assertion works. Skipped when
* `PUTER_TEST_AI_BYTEPLUS_API_KEY` is unset.
*/

import { describe, expect, it } from 'vitest';
import {
INTEGRATION_TEST_TIMEOUT_MS,
makeMeteringStub,
optionalEnv,
skipUnlessEnv,
withTestActor,
} from '../../../integrationTestUtil.js';
import { BytePlusProvider } from './BytePlusProvider.js';

const ENV_VAR = 'PUTER_TEST_AI_BYTEPLUS_API_KEY';

describe.skipIf(skipUnlessEnv(ENV_VAR))('BytePlusProvider (integration)', () => {
it('returns a non-empty completion from seed-1-6-flash-250715', { timeout: INTEGRATION_TEST_TIMEOUT_MS }, async () => {
const provider = new BytePlusProvider(
{ apiKey: optionalEnv(ENV_VAR)! },
makeMeteringStub(),
);

const result = await withTestActor(() =>
provider.complete({
model: 'seed-1-6-flash-250715',
messages: [{ role: 'user', content: 'Say hi in one word.' }],
max_tokens: 16,
custom: { thinking: { type: 'disabled' } },
}),
);

const text = (result as { message?: { content?: string } }).message
?.content;
expect(typeof text === 'string' && text.length > 0).toBe(true);
});
});
Loading
Loading