@standardagents/novita 0.0.0-dev.fffff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @standardagents/novita
|
|
2
|
+
|
|
3
|
+
Novita AI provider for Standard Agents.
|
|
4
|
+
|
|
5
|
+
This package wraps Novita's OpenAI-compatible Chat Completions API behind the
|
|
6
|
+
Standard Agents provider interface. It supports:
|
|
7
|
+
|
|
8
|
+
- streaming and non-streaming text generation
|
|
9
|
+
- local function tool calling on supported models
|
|
10
|
+
- JSON and structured output modes
|
|
11
|
+
- live model discovery from Novita's `/openai/v1/models` endpoint
|
|
12
|
+
- usage normalization and live provider pricing from Novita's model catalog,
|
|
13
|
+
including cache-read token prices when Novita reports them
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @standardagents/novita @standardagents/spec
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { novita } from '@standardagents/novita';
|
|
25
|
+
|
|
26
|
+
const provider = novita({
|
|
27
|
+
apiKey: process.env.NOVITA_API_KEY!,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const result = await provider.generate({
|
|
31
|
+
model: 'deepseek/deepseek-v3.2',
|
|
32
|
+
messages: [{ role: 'user', content: 'Give me three concise launch names.' }],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(result.content);
|
|
36
|
+
console.log(result.usage?.cost);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Factory
|
|
40
|
+
|
|
41
|
+
The package exports:
|
|
42
|
+
|
|
43
|
+
- `novita(config)` - provider factory
|
|
44
|
+
- `NovitaProvider` - provider class
|
|
45
|
+
- `novitaProviderOptions` - Zod schema for provider-specific options
|
|
46
|
+
|
|
47
|
+
## Model Discovery And Pricing
|
|
48
|
+
|
|
49
|
+
Novita model metadata is read from `https://api.novita.ai/openai/v1/models`.
|
|
50
|
+
The response includes model IDs, context size, and token prices. Novita reports
|
|
51
|
+
prices as scaled integers, so this provider converts values like `14000` to
|
|
52
|
+
`$1.40` per million tokens before exposing `inputPrice`, `outputPrice`,
|
|
53
|
+
`cachedPrice`, and `usage.pricing`.
|
|
54
|
+
|
|
55
|
+
When Novita includes `pricing.input_cache_read.price_per_m`, the provider maps
|
|
56
|
+
that value to `cachedInputPerMillion` and uses it for cached prompt tokens.
|
|
57
|
+
Cache write tokens remain part of uncached prompt input usage and are priced at
|
|
58
|
+
the normal input rate.
|
|
59
|
+
|
|
60
|
+
When response usage includes token counts, generated and streamed responses also
|
|
61
|
+
attach `usage.cost`. If the live catalog cannot be reached, the provider falls
|
|
62
|
+
back to a small static set of currently recommended Novita models.
|
|
63
|
+
|
|
64
|
+
For custom or private Novita models, set explicit model pricing in AgentBuilder
|
|
65
|
+
if the model does not appear in Novita's catalog.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LLMProviderInterface, ProviderFactoryConfig, ModelCapabilities, ProviderModelInfo, ProviderRequest, ProviderResponse, ProviderStreamChunk, InspectedRequest, ProviderUsagePricing, ProviderUsage, ProviderFactoryWithOptions } from '@standardagents/spec';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Novita provider options schema.
|
|
6
|
+
*
|
|
7
|
+
* Novita exposes an OpenAI-compatible Chat Completions API. These options cover
|
|
8
|
+
* documented Novita-specific and OpenAI-compatible parameters, while
|
|
9
|
+
* passthrough keeps the provider forward-compatible with new API fields.
|
|
10
|
+
*/
|
|
11
|
+
declare const novitaProviderOptions: z.ZodObject<{
|
|
12
|
+
n: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
frequency_penalty: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
presence_penalty: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
repetition_penalty: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
top_k: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
min_p: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
logit_bias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
20
|
+
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
top_logprobs: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
separate_reasoning: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
enable_thinking: z.ZodOptional<z.ZodBoolean>;
|
|
24
|
+
modalities: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
}, z.core.$loose>;
|
|
26
|
+
type NovitaProviderOptions = z.infer<typeof novitaProviderOptions>;
|
|
27
|
+
|
|
28
|
+
interface NovitaModelInfo {
|
|
29
|
+
id: string;
|
|
30
|
+
object?: string;
|
|
31
|
+
created?: number;
|
|
32
|
+
title?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
context_size?: number;
|
|
35
|
+
input_token_price_per_m?: number;
|
|
36
|
+
output_token_price_per_m?: number;
|
|
37
|
+
pricing?: {
|
|
38
|
+
prompt?: NovitaPriceInfo;
|
|
39
|
+
completion?: NovitaPriceInfo;
|
|
40
|
+
input_cache_read?: NovitaPriceInfo;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
interface NovitaPriceInfo {
|
|
44
|
+
origin_price_per_m?: number;
|
|
45
|
+
price_per_m?: number;
|
|
46
|
+
}
|
|
47
|
+
declare function normalizeNovitaPricePerMillion(value: unknown): number | undefined;
|
|
48
|
+
declare function novitaUsagePricingFromModel(model: NovitaModelInfo | undefined): ProviderUsagePricing | undefined;
|
|
49
|
+
declare function calculateNovitaUsageCost(usage: ProviderUsage, pricing?: ProviderUsagePricing): number | undefined;
|
|
50
|
+
declare class NovitaProvider implements LLMProviderInterface {
|
|
51
|
+
readonly name = "novita";
|
|
52
|
+
readonly specificationVersion: "1";
|
|
53
|
+
private config;
|
|
54
|
+
private static modelsCache;
|
|
55
|
+
private static modelsCacheTime;
|
|
56
|
+
private static readonly CACHE_TTL;
|
|
57
|
+
private static readonly USAGE_PRICING_FINISH_WAIT_MS;
|
|
58
|
+
constructor(config: ProviderFactoryConfig);
|
|
59
|
+
supportsModel(_modelId: string): boolean;
|
|
60
|
+
getIcon(modelId?: string): string;
|
|
61
|
+
private baseUrl;
|
|
62
|
+
private headers;
|
|
63
|
+
private fetchModelsWithCache;
|
|
64
|
+
private mapModelCapabilities;
|
|
65
|
+
getModelCapabilities(modelId: string): Promise<ModelCapabilities | null>;
|
|
66
|
+
private mapToProviderModelInfo;
|
|
67
|
+
getModels(filter?: string): Promise<ProviderModelInfo[]>;
|
|
68
|
+
private static settleUsagePricing;
|
|
69
|
+
private getUsagePricing;
|
|
70
|
+
generate(request: ProviderRequest): Promise<ProviderResponse>;
|
|
71
|
+
stream(request: ProviderRequest): Promise<AsyncIterable<ProviderStreamChunk>>;
|
|
72
|
+
private toHttpProviderErrorFromResponse;
|
|
73
|
+
private toProviderError;
|
|
74
|
+
private toHttpProviderError;
|
|
75
|
+
inspectRequest(request: ProviderRequest): Promise<InspectedRequest>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Novita AI provider factory for Standard Agents.
|
|
80
|
+
*
|
|
81
|
+
* Uses Novita's OpenAI-compatible Chat Completions API and live model catalog.
|
|
82
|
+
*/
|
|
83
|
+
declare const novita: ProviderFactoryWithOptions<typeof novitaProviderOptions>;
|
|
84
|
+
|
|
85
|
+
export { type NovitaModelInfo, NovitaProvider, type NovitaProviderOptions, calculateNovitaUsageCost, normalizeNovitaPricePerMillion, novita, novitaProviderOptions, novitaUsagePricingFromModel };
|