@revojs/ai 0.2.57 → 0.2.59
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/dist/index.d.ts +5 -2
- package/dist/index.js +2 -2
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +3 -2
- package/dist/providers/deepseek.d.ts +1 -1
- package/dist/providers/deepseek.js +3 -2
- package/dist/providers/google.d.ts +1 -1
- package/dist/providers/google.js +3 -2
- package/dist/providers/moonshotai.d.ts +1 -1
- package/dist/providers/moonshotai.js +3 -2
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +3 -2
- package/dist/providers/opencode-go.d.ts +1 -1
- package/dist/providers/opencode-go.js +5 -4
- package/dist/providers/opencode.d.ts +1 -1
- package/dist/providers/opencode.js +3 -2
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +3 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -815,8 +815,11 @@ export interface SkillsUploadSkillResult {
|
|
|
815
815
|
providerMetadata?: Record<string, JSONObject>;
|
|
816
816
|
warnings: Array<SharedWarning>;
|
|
817
817
|
}
|
|
818
|
+
export interface ProviderOptions {
|
|
819
|
+
apiKey?: string;
|
|
820
|
+
}
|
|
818
821
|
export interface Provider {
|
|
819
|
-
setup: (scope: Scope) => Awaitable<ProviderConnection>;
|
|
822
|
+
setup: (scope: Scope, options?: ProviderOptions) => Awaitable<ProviderConnection>;
|
|
820
823
|
}
|
|
821
824
|
export declare class ModelContextProtocolError extends Error {
|
|
822
825
|
readonly code: number;
|
|
@@ -862,7 +865,7 @@ export declare function useTools(scope: Scope): {
|
|
|
862
865
|
export declare function handleModelContextProtocol(scope: Scope, options?: ModelContextProtocolServerOptions): Promise<Response>;
|
|
863
866
|
export declare function useModelContextProtocol(options: ModelContextProtocolConnectOptions): Promise<ModelContextProtocolConnection>;
|
|
864
867
|
export declare function defineProvider<TProvider extends Provider>(provider: TProvider): TProvider;
|
|
865
|
-
export declare function useAi<TSource extends Source<Provider> = typeof import("#providers").default>(scope: Scope): AiConnections<TSource>;
|
|
868
|
+
export declare function useAi<TSource extends Source<Provider> = typeof import("#providers").default>(scope: Scope, options?: Partial<Record<string, ProviderOptions>>): AiConnections<TSource>;
|
|
866
869
|
export declare function useModelsDev(id: string, resolve: (model: ModelsDevModel, provider: ModelsDevProvider) => TextProtocols | undefined): Promise<{
|
|
867
870
|
models: () => Promise<Description[]>;
|
|
868
871
|
textGenerate: Record<string, Protocol<LanguageModelCallOptions<string>, LanguageModelGenerateResult>>;
|
package/dist/index.js
CHANGED
|
@@ -541,12 +541,12 @@ async function useModelContextProtocol(options) {
|
|
|
541
541
|
function defineProvider(provider) {
|
|
542
542
|
return provider;
|
|
543
543
|
}
|
|
544
|
-
function useAi(scope) {
|
|
544
|
+
function useAi(scope, options = {}) {
|
|
545
545
|
const names = [...new Set(Object.values(providers).flatMap((entries) => Object.keys(entries)))].sort();
|
|
546
546
|
const connect = async (name) => {
|
|
547
547
|
const resolves = Object.values(providers).map((entries) => entries[name]).filter((resolve) => resolve !== void 0);
|
|
548
548
|
if (resolves.length === 0) throw new Error(`Unknown AI provider "${name}". Built-in providers: ${names.join(", ")}. Add ./providers/${name}.ts for custom ones.`);
|
|
549
|
-
return resolves[0]().then((provider) => provider.setup(scope));
|
|
549
|
+
return resolves[0]().then((provider) => provider.setup(scope, options[name]));
|
|
550
550
|
};
|
|
551
551
|
const invoke = async (name, capability, options) => {
|
|
552
552
|
const models = (await connect(name))[capability];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
|
@@ -2,10 +2,11 @@ import { defineProvider, useModelsDev } from "../index.js";
|
|
|
2
2
|
import { messagesGenerateProtocol, messagesStreamProtocol } from "../protocols/anthropic-messages.js";
|
|
3
3
|
import { useVariables } from "revojs";
|
|
4
4
|
//#region src/providers/anthropic.ts
|
|
5
|
-
var anthropic_default = defineProvider({ setup: (scope) => {
|
|
5
|
+
var anthropic_default = defineProvider({ setup: (scope, options) => {
|
|
6
|
+
const variables = useVariables(scope);
|
|
6
7
|
const config = {
|
|
7
8
|
baseURL: "https://api.anthropic.com/v1",
|
|
8
|
-
apiKey:
|
|
9
|
+
apiKey: options?.apiKey ?? variables.anthropicApiKey
|
|
9
10
|
};
|
|
10
11
|
const protocols = {
|
|
11
12
|
textGenerate: messagesGenerateProtocol(config),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
|
@@ -2,10 +2,11 @@ import { defineProvider, useModelsDev } from "../index.js";
|
|
|
2
2
|
import { chatCompletionsGenerateProtocol, chatCompletionsStreamProtocol } from "../protocols/openai-chat-completions.js";
|
|
3
3
|
import { useVariables } from "revojs";
|
|
4
4
|
//#region src/providers/deepseek.ts
|
|
5
|
-
var deepseek_default = defineProvider({ setup: (scope) => {
|
|
5
|
+
var deepseek_default = defineProvider({ setup: (scope, options) => {
|
|
6
|
+
const variables = useVariables(scope);
|
|
6
7
|
const config = {
|
|
7
8
|
baseURL: "https://api.deepseek.com/v1",
|
|
8
|
-
apiKey:
|
|
9
|
+
apiKey: options?.apiKey ?? variables.deepseekApiKey
|
|
9
10
|
};
|
|
10
11
|
const protocols = {
|
|
11
12
|
textGenerate: chatCompletionsGenerateProtocol(config),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
package/dist/providers/google.js
CHANGED
|
@@ -2,10 +2,11 @@ import { defineProvider, useModelsDev } from "../index.js";
|
|
|
2
2
|
import { chatCompletionsGenerateProtocol, chatCompletionsStreamProtocol } from "../protocols/openai-chat-completions.js";
|
|
3
3
|
import { useVariables } from "revojs";
|
|
4
4
|
//#region src/providers/google.ts
|
|
5
|
-
var google_default = defineProvider({ setup: (scope) => {
|
|
5
|
+
var google_default = defineProvider({ setup: (scope, options) => {
|
|
6
|
+
const variables = useVariables(scope);
|
|
6
7
|
const config = {
|
|
7
8
|
baseURL: "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
8
|
-
apiKey:
|
|
9
|
+
apiKey: options?.apiKey ?? variables.googleApiKey
|
|
9
10
|
};
|
|
10
11
|
const protocols = {
|
|
11
12
|
textGenerate: chatCompletionsGenerateProtocol(config),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
|
@@ -2,10 +2,11 @@ import { defineProvider, useModelsDev } from "../index.js";
|
|
|
2
2
|
import { chatCompletionsGenerateProtocol, chatCompletionsStreamProtocol } from "../protocols/openai-chat-completions.js";
|
|
3
3
|
import { useVariables } from "revojs";
|
|
4
4
|
//#region src/providers/moonshotai.ts
|
|
5
|
-
var moonshotai_default = defineProvider({ setup: (scope) => {
|
|
5
|
+
var moonshotai_default = defineProvider({ setup: (scope, options) => {
|
|
6
|
+
const variables = useVariables(scope);
|
|
6
7
|
const config = {
|
|
7
8
|
baseURL: "https://api.moonshot.ai/v1",
|
|
8
|
-
apiKey:
|
|
9
|
+
apiKey: options?.apiKey ?? variables.moonshotaiApiKey
|
|
9
10
|
};
|
|
10
11
|
const protocols = {
|
|
11
12
|
textGenerate: chatCompletionsGenerateProtocol(config),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
package/dist/providers/openai.js
CHANGED
|
@@ -2,10 +2,11 @@ import { defineProvider, useModelsDev } from "../index.js";
|
|
|
2
2
|
import { responsesGenerateProtocol, responsesStreamProtocol } from "../protocols/openai-responses.js";
|
|
3
3
|
import { useVariables } from "revojs";
|
|
4
4
|
//#region src/providers/openai.ts
|
|
5
|
-
var openai_default = defineProvider({ setup: (scope) => {
|
|
5
|
+
var openai_default = defineProvider({ setup: (scope, options) => {
|
|
6
|
+
const variables = useVariables(scope);
|
|
6
7
|
const config = {
|
|
7
8
|
baseURL: "https://api.openai.com/v1",
|
|
8
|
-
apiKey:
|
|
9
|
+
apiKey: options?.apiKey ?? variables.openaiApiKey
|
|
9
10
|
};
|
|
10
11
|
const protocols = {
|
|
11
12
|
textGenerate: responsesGenerateProtocol(config),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LanguageModelCallOptions, type Protocol } from "../index";
|
|
2
2
|
declare const _default: {
|
|
3
|
-
setup(scope: import("revojs").Scope): Promise<{
|
|
3
|
+
setup(scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined): Promise<{
|
|
4
4
|
models: () => Promise<import("../index").Description[]>;
|
|
5
5
|
textGenerate: Record<string, Protocol<LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
6
6
|
textStream: Record<string, Protocol<LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
|
@@ -5,10 +5,10 @@ import { responsesGenerateProtocol, responsesStreamProtocol } from "../protocols
|
|
|
5
5
|
import { geminiGenerateProtocol, geminiStreamProtocol } from "../protocols/google-models.js";
|
|
6
6
|
import { useVariables } from "revojs";
|
|
7
7
|
//#region src/providers/opencode-go.ts
|
|
8
|
-
var opencode_go_default = defineProvider({ setup(scope) {
|
|
8
|
+
var opencode_go_default = defineProvider({ setup(scope, options) {
|
|
9
9
|
function withSession(protocol) {
|
|
10
10
|
return (options) => {
|
|
11
|
-
if (!
|
|
11
|
+
if (!apiKey) throw new Error("OpenCode Go requires an API key.");
|
|
12
12
|
const headers = new Headers();
|
|
13
13
|
for (const [name, value] of Object.entries(options.headers ?? {})) if (value !== void 0) headers.set(name, value);
|
|
14
14
|
if (!headers.get("x-opencode-session")?.trim()) throw new Error("OpenCode Go requires a stable x-opencode-session header.");
|
|
@@ -28,9 +28,10 @@ var opencode_go_default = defineProvider({ setup(scope) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
const variables = useVariables(scope);
|
|
31
|
+
const apiKey = options?.apiKey ?? variables.opencodeApiKey;
|
|
31
32
|
const config = {
|
|
32
33
|
baseURL: "https://opencode.ai/zen/go/v1",
|
|
33
|
-
apiKey
|
|
34
|
+
apiKey
|
|
34
35
|
};
|
|
35
36
|
const protocols = {
|
|
36
37
|
"chat-completions": {
|
|
@@ -51,7 +52,7 @@ var opencode_go_default = defineProvider({ setup(scope) {
|
|
|
51
52
|
if (protocol === "google-models") {
|
|
52
53
|
const google = {
|
|
53
54
|
baseURL: model.provider?.api ?? "https://opencode.ai/inference/go/google/v1beta",
|
|
54
|
-
apiKey
|
|
55
|
+
apiKey
|
|
55
56
|
};
|
|
56
57
|
return {
|
|
57
58
|
textGenerate: withSession(geminiGenerateProtocol(google)),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
|
@@ -5,10 +5,11 @@ import { responsesGenerateProtocol, responsesStreamProtocol } from "../protocols
|
|
|
5
5
|
import { geminiGenerateProtocol, geminiStreamProtocol } from "../protocols/google-models.js";
|
|
6
6
|
import { useVariables } from "revojs";
|
|
7
7
|
//#region src/providers/opencode.ts
|
|
8
|
-
var opencode_default = defineProvider({ setup: (scope) => {
|
|
8
|
+
var opencode_default = defineProvider({ setup: (scope, options) => {
|
|
9
|
+
const variables = useVariables(scope);
|
|
9
10
|
const config = {
|
|
10
11
|
baseURL: "https://opencode.ai/zen/v1",
|
|
11
|
-
apiKey:
|
|
12
|
+
apiKey: options?.apiKey ?? variables.opencodeApiKey
|
|
12
13
|
};
|
|
13
14
|
const protocols = {
|
|
14
15
|
"chat-completions": {
|
package/dist/providers/xai.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
setup: (scope: import("revojs").Scope) => Promise<{
|
|
2
|
+
setup: (scope: import("revojs").Scope, options: import("../index").ProviderOptions | undefined) => Promise<{
|
|
3
3
|
models: () => Promise<import("../index").Description[]>;
|
|
4
4
|
textGenerate: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelGenerateResult>>;
|
|
5
5
|
textStream: Record<string, import("../index").Protocol<import("../index").LanguageModelCallOptions<string>, import("../index").LanguageModelStreamResult>>;
|
package/dist/providers/xai.js
CHANGED
|
@@ -2,10 +2,11 @@ import { defineProvider, useModelsDev } from "../index.js";
|
|
|
2
2
|
import { chatCompletionsGenerateProtocol, chatCompletionsStreamProtocol } from "../protocols/openai-chat-completions.js";
|
|
3
3
|
import { useVariables } from "revojs";
|
|
4
4
|
//#region src/providers/xai.ts
|
|
5
|
-
var xai_default = defineProvider({ setup: (scope) => {
|
|
5
|
+
var xai_default = defineProvider({ setup: (scope, options) => {
|
|
6
|
+
const variables = useVariables(scope);
|
|
6
7
|
const config = {
|
|
7
8
|
baseURL: "https://api.x.ai/v1",
|
|
8
|
-
apiKey:
|
|
9
|
+
apiKey: options?.apiKey ?? variables.xaiApiKey
|
|
9
10
|
};
|
|
10
11
|
const protocols = {
|
|
11
12
|
textGenerate: chatCompletionsGenerateProtocol(config),
|