@xandreed/plugin-models 0.14.0 → 0.15.1
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 +1 -1
- package/dist/auth/anthropicOAuth.d.ts +30 -10
- package/dist/auth/anthropicOAuth.js +15 -18
- package/dist/auth/auth-store.conformance.d.ts +63 -0
- package/dist/auth/auth-store.conformance.js +152 -0
- package/dist/auth/credential-input.entity.d.ts +23 -5
- package/dist/auth/credential-input.entity.functions.d.ts +15 -5
- package/dist/auth/credential-input.entity.functions.js +12 -9
- package/dist/auth/credential-input.entity.js +5 -3
- package/dist/auth/credential-refresh.entity.d.ts +11 -3
- package/dist/auth/credential-refresh.entity.functions.d.ts +48 -6
- package/dist/auth/credential-refresh.entity.functions.js +12 -3
- package/dist/auth/localAuth.d.ts +10 -1
- package/dist/auth/localAuth.js +53 -79
- package/dist/auth/memory-auth.adapter.d.ts +12 -4
- package/dist/auth/memory-auth.adapter.js +13 -25
- package/dist/auth/openAiCodexOAuth.d.ts +26 -5
- package/dist/auth/openAiCodexOAuth.js +17 -28
- package/dist/auth/token-response.entity.d.ts +21 -0
- package/dist/auth/token-response.entity.functions.d.ts +20 -0
- package/dist/auth/token-response.entity.functions.js +10 -0
- package/dist/auth/token-response.entity.js +10 -0
- package/dist/compat/index.d.ts +2 -0
- package/dist/compat/index.js +1 -0
- package/dist/conformance/index.d.ts +6 -0
- package/dist/conformance/index.js +3 -0
- package/dist/index.d.ts +19 -19
- package/dist/index.js +17 -69
- package/dist/llm/chat-wire.entity.d.ts +123 -0
- package/dist/llm/chat-wire.entity.functions.d.ts +28 -0
- package/dist/llm/chat-wire.entity.functions.js +10 -0
- package/dist/llm/chat-wire.entity.js +37 -0
- package/dist/llm/compat-telemetry.adapter.d.ts +6 -0
- package/dist/llm/compat-telemetry.adapter.js +21 -0
- package/dist/llm/compat.d.ts +50 -30
- package/dist/llm/compat.js +149 -133
- package/dist/llm/model-completion.adapter.d.ts +49 -0
- package/dist/llm/model-completion.adapter.js +77 -0
- package/dist/llm/model-completion.entity.d.ts +4 -0
- package/dist/llm/model-completion.entity.functions.d.ts +3 -0
- package/dist/llm/model-completion.entity.functions.js +7 -0
- package/dist/llm/model-completion.entity.js +7 -0
- package/dist/llm/model-retry-policy.entity.d.ts +37 -0
- package/dist/llm/model-retry-policy.entity.functions.d.ts +16 -0
- package/dist/llm/model-retry-policy.entity.functions.js +33 -0
- package/dist/llm/model-retry-policy.entity.js +23 -0
- package/dist/llm/model-settings.entity.d.ts +85 -0
- package/dist/llm/model-settings.entity.functions.d.ts +11 -0
- package/dist/llm/model-settings.entity.functions.js +49 -0
- package/dist/llm/model-settings.entity.js +28 -0
- package/dist/llm/model-usage.entity.d.ts +61 -0
- package/dist/llm/model-usage.entity.functions.d.ts +11 -0
- package/dist/llm/model-usage.entity.functions.js +24 -0
- package/dist/llm/model-usage.entity.js +19 -0
- package/dist/llm/modelCatalog.d.ts +29 -8
- package/dist/llm/modelCatalog.js +28 -66
- package/dist/llm/openAiCodex.d.ts +15 -7
- package/dist/llm/openAiCodex.js +57 -45
- package/dist/llm/openAiCodexWebSocket.d.ts +48 -15
- package/dist/llm/openAiCodexWebSocket.js +101 -147
- package/dist/llm/prompt-cache-frame.entity.d.ts +18 -0
- package/dist/llm/prompt-cache-frame.entity.js +10 -0
- package/dist/llm/prompt-cache.entity.d.ts +57 -0
- package/dist/llm/prompt-cache.entity.functions.d.ts +8 -0
- package/dist/llm/prompt-cache.entity.functions.js +73 -0
- package/dist/llm/prompt-cache.entity.js +27 -0
- package/dist/llm/provider-client.adapter.d.ts +9 -0
- package/dist/llm/provider-client.adapter.js +60 -0
- package/dist/llm/provider-failure.entity.d.ts +42 -0
- package/dist/llm/provider-failure.entity.functions.d.ts +8 -0
- package/dist/llm/provider-failure.entity.functions.js +67 -0
- package/dist/llm/provider-failure.entity.js +20 -0
- package/dist/llm/provider-profile.entity.d.ts +79 -0
- package/dist/llm/provider-profile.entity.functions.d.ts +23 -0
- package/dist/llm/provider-profile.entity.functions.js +83 -0
- package/dist/llm/provider-profile.entity.js +10 -0
- package/dist/llm/providers.d.ts +116 -34
- package/dist/llm/providers.js +298 -129
- package/dist/llm/retry.d.ts +11 -47
- package/dist/llm/retry.js +33 -52
- package/dist/llm/router.d.ts +54 -36
- package/dist/llm/router.js +91 -78
- package/dist/llm/sse.d.ts +44 -37
- package/dist/llm/sse.js +43 -35
- package/dist/llm/thinking-binding.entity.d.ts +49 -0
- package/dist/llm/thinking-binding.entity.functions.d.ts +21 -0
- package/dist/llm/thinking-binding.entity.functions.js +16 -0
- package/dist/llm/thinking-binding.entity.js +11 -0
- package/dist/llm/utilityLlm.d.ts +14 -5
- package/dist/llm/utilityLlm.js +18 -13
- package/dist/plugin.adapter.d.ts +94 -6
- package/dist/plugin.adapter.js +18 -13
- package/dist/ports/auth-store.port.d.ts +73 -0
- package/dist/ports/auth-store.port.js +24 -0
- package/dist/ports/host-credentials.port.d.ts +2 -1
- package/dist/ports/model-call-completion.port.d.ts +9 -0
- package/dist/ports/model-call-completion.port.js +2 -0
- package/dist/ports/model-endpoints.port.d.ts +60 -26
- package/dist/ports/model-endpoints.port.js +17 -3
- package/dist/ports/model-retry-policy.port.d.ts +17 -0
- package/dist/ports/model-retry-policy.port.js +3 -0
- package/dist/ports/model-settings.port.d.ts +32 -0
- package/dist/ports/model-settings.port.js +4 -0
- package/dist/ports/models-transport.port.d.ts +9 -2
- package/dist/ports/models-transport.port.js +4 -1
- package/dist/ports/prompt-cache-frame.port.d.ts +21 -0
- package/dist/ports/prompt-cache-frame.port.js +4 -0
- package/dist/ports/settings-store.port.d.ts +70 -0
- package/dist/ports/settings-store.port.js +33 -0
- package/dist/ports/thinking-binding.port.d.ts +7 -0
- package/dist/ports/thinking-binding.port.js +4 -0
- package/dist/settings/localSettings.d.ts +2 -1
- package/dist/settings/localSettings.js +17 -20
- package/dist/settings/memory-settings.adapter.d.ts +3 -1
- package/dist/settings/memory-settings.adapter.js +1 -1
- package/dist/settings/roleView.d.ts +3 -1
- package/dist/settings/roleView.js +1 -1
- package/dist/settings/settings-store.conformance.d.ts +47 -0
- package/dist/settings/settings-store.conformance.js +100 -0
- package/dist/settings/settings-value.entity.d.ts +10 -2
- package/dist/settings/settings-value.entity.functions.d.ts +31 -9
- package/dist/settings/settings-value.entity.functions.js +5 -6
- package/dist/storage/json-file.d.ts +18 -0
- package/dist/storage/json-file.js +26 -0
- package/dist/transport/http-proxy.entity.d.ts +17 -3
- package/dist/transport/model-request.conformance.d.ts +13 -0
- package/dist/transport/model-request.conformance.js +36 -0
- package/dist/transport/models-transport.adapter.d.ts +18 -17
- package/dist/transport/models-transport.adapter.js +28 -31
- package/dist/transport/resilient-http-client.adapter.d.ts +73 -0
- package/dist/transport/resilient-http-client.adapter.js +177 -0
- package/package.json +11 -5
- package/dist/auth/anthropicOAuth.test.d.ts +0 -1
- package/dist/auth/credential-refresh.entity.functions.test.d.ts +0 -1
- package/dist/auth/localAuth.test.d.ts +0 -1
- package/dist/auth/memory-auth.adapter.test.d.ts +0 -1
- package/dist/llm/compat.test.d.ts +0 -1
- package/dist/llm/modelCatalog.test.d.ts +0 -1
- package/dist/llm/openAiCodexWebSocket.test.d.ts +0 -1
- package/dist/llm/providers.test.d.ts +0 -1
- package/dist/llm/retry.test.d.ts +0 -1
- package/dist/llm/router.test.d.ts +0 -1
- package/dist/llm/sse.test.d.ts +0 -1
- package/dist/plugin.adapter.test.d.ts +0 -1
- package/dist/settings/localSettings.test.d.ts +0 -1
- package/dist/settings/memory-settings.adapter.test.d.ts +0 -1
- package/dist/settings/roleView.test.d.ts +0 -1
- package/dist/settings/settings-value.entity.functions.test.d.ts +0 -1
- package/dist/transport/http-proxy.entity.functions.test.d.ts +0 -1
- package/dist/transport/models-transport.adapter.test.d.ts +0 -1
- package/dist/transport/recording-proxy.testing.d.ts +0 -33
package/dist/llm/providers.d.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import { LanguageModel } from "effect/ai";
|
|
1
|
+
import { AiError, LanguageModel, Prompt } from "effect/ai";
|
|
2
2
|
import { HttpClient } from "effect/http";
|
|
3
|
-
import { Effect, Option, Redacted } from "effect";
|
|
4
|
-
import type { Scope } from "effect";
|
|
5
|
-
import { AuthError } from "
|
|
6
|
-
import type {
|
|
3
|
+
import { Config, Effect, Option, Redacted, Result } from "effect";
|
|
4
|
+
import type { Context, Schema, Scope } from "effect";
|
|
5
|
+
import { AuthError } from "../ports/auth-store.port.js";
|
|
6
|
+
import type { ModelCallPolicy, ModelSelection } from "@xandreed/core";
|
|
7
|
+
import type { Credential } from "../ports/auth-store.port.js";
|
|
7
8
|
import { usesOpenCodeResponses } from "./modelCatalog.js";
|
|
8
|
-
import type {
|
|
9
|
+
import type { OpenAiCodexSessions } from "./openAiCodexWebSocket.js";
|
|
10
|
+
import type { Route } from "./provider-profile.entity.js";
|
|
11
|
+
import type { ModelEndpoint, ModelEndpoints } from "../ports/model-endpoints.port.js";
|
|
12
|
+
import { ModelsTransport } from "../ports/models-transport.port.js";
|
|
13
|
+
import { ModelSettingsError } from "./model-settings.entity.js";
|
|
14
|
+
import type { ModelSettingsMap } from "./model-settings.entity.js";
|
|
15
|
+
import type { ThinkingPrefixMismatch } from "./thinking-binding.entity.js";
|
|
9
16
|
/**
|
|
10
17
|
* Per-provider `LanguageModel` construction. Built PER REQUEST from a
|
|
11
18
|
* freshly-resolved key (never captured at layer build), so a credential or
|
|
12
19
|
* model switch applies on the next call.
|
|
13
20
|
*
|
|
14
|
-
*
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
21
|
+
* The built-in providers are their profiles (`PROVIDER_PROFILES`): opencode
|
|
22
|
+
* (OpenAI-compatible gateway — the default), google (Gemini's
|
|
23
|
+
* OpenAI-compatible endpoint), anthropic (api key or subscription OAuth),
|
|
24
|
+
* openai (api key), openai-codex (subscription OAuth). A model is built by
|
|
25
|
+
* its route, one builder each. A configured endpoint, or a `local`
|
|
26
|
+
* credential with a `baseUrl`, sends its provider's models to that
|
|
27
|
+
* OpenAI-compatible URL, with or without a key.
|
|
19
28
|
*/
|
|
20
|
-
export
|
|
21
|
-
/** OpenCode serves GPT models through the OpenAI Responses protocol. */
|
|
22
|
-
export declare const OPENCODE_RESPONSES_API_URL = "https://opencode.ai/zen/v1";
|
|
23
|
-
/** Gemini through its OpenAI-compatible chat completions (Bearer API key). */
|
|
24
|
-
export declare const GOOGLE_CHAT_URL = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions";
|
|
29
|
+
export { GOOGLE_CHAT_URL, OPENCODE_CHAT_URL, OPENCODE_RESPONSES_API_URL } from "./provider-profile.entity.functions.js";
|
|
25
30
|
export { usesOpenCodeResponses };
|
|
26
31
|
export interface BuiltProvider {
|
|
27
32
|
readonly svc: LanguageModel.LanguageModel;
|
|
@@ -29,30 +34,107 @@ export interface BuiltProvider {
|
|
|
29
34
|
readonly prependClaudeCode: boolean;
|
|
30
35
|
/** The route sends images; when it does not, `buildProvider` has the model send them as label lines. */
|
|
31
36
|
readonly images: boolean;
|
|
37
|
+
/** The route the model is sent over: a configured endpoint's and a `local` credential's URL are `compat`. */
|
|
38
|
+
readonly route: Route["_tag"];
|
|
32
39
|
}
|
|
40
|
+
/** The options of a model call, as far as the plugin rewrites them: the prompt. */
|
|
41
|
+
export interface PromptOptions {
|
|
42
|
+
readonly prompt: Prompt.RawInput;
|
|
43
|
+
readonly toolChoice?: LanguageModel.ToolChoice<string> | undefined;
|
|
44
|
+
}
|
|
45
|
+
/** A call's options with the prompt `f` made of it; every other option is kept. */
|
|
46
|
+
export declare const withPrompt: <O extends PromptOptions>(options: O, f: (prompt: Prompt.Prompt) => Prompt.Prompt) => Omit<O, "prompt"> & {
|
|
47
|
+
readonly prompt: Prompt.Prompt;
|
|
48
|
+
};
|
|
33
49
|
/** Prepend the Claude Code system block (subscription-auth requirement). */
|
|
34
|
-
export declare const prependClaudeCode: (options:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* `cache_control` breakpoints on the last system message + the last two
|
|
38
|
-
* non-system messages. Marker placement is not part of Anthropic's content
|
|
39
|
-
* hash, so the markers moving forward each turn never invalidates earlier
|
|
40
|
-
* prefixes. Messages already carrying an explicit `cacheControl` are left
|
|
41
|
-
* alone.
|
|
42
|
-
*/
|
|
43
|
-
export declare const withAnthropicCacheBreakpoints: (options: unknown) => unknown;
|
|
50
|
+
export declare const prependClaudeCode: <O extends PromptOptions>(options: O) => Omit<O, "prompt"> & {
|
|
51
|
+
readonly prompt: Prompt.Prompt;
|
|
52
|
+
};
|
|
44
53
|
/** `<url>/chat/completions` of an OpenAI-compatible base URL. */
|
|
45
54
|
export declare const chatCompletionsUrl: (baseUrl: string) => string;
|
|
46
55
|
/**
|
|
47
|
-
* An endpoint's own key: `apiKey`, then the
|
|
48
|
-
*
|
|
49
|
-
*
|
|
56
|
+
* An endpoint's own key: `apiKey`, then the variable `apiKeyEnv` names, read
|
|
57
|
+
* with `Config` from the current ConfigProvider (the process environment
|
|
58
|
+
* unless the host provides another; the environment's reads an empty
|
|
59
|
+
* variable as unset). An empty `apiKey` is still the endpoint's own: it
|
|
60
|
+
* sends no key, and the AuthStore's is not used. Fails with the
|
|
61
|
+
* ConfigError when the provider cannot be read.
|
|
62
|
+
*/
|
|
63
|
+
export declare const endpointOwnKey: (endpoint: ModelEndpoint) => Effect.Effect<Option.Option<Redacted.Redacted<string>>, Config.ConfigError>;
|
|
64
|
+
/** The transport the plugin was built over, if any: the compat client's fetch goes through it. */
|
|
65
|
+
type Transport = Option.Option<Context.Service.Shape<typeof ModelsTransport>>;
|
|
66
|
+
/**
|
|
67
|
+
* What a provider is built over besides its selection and credential: the
|
|
68
|
+
* configured endpoints, the transport, and the OpenAI subscription's
|
|
69
|
+
* session cache (`None` keeps one per built model). The routed models read
|
|
70
|
+
* them once, where their layer is built, and build every call's provider
|
|
71
|
+
* over them ({@link buildProviderOver}).
|
|
72
|
+
*/
|
|
73
|
+
export interface ProviderServices {
|
|
74
|
+
readonly endpoints: ModelEndpoints;
|
|
75
|
+
readonly modelSettings: ModelSettingsMap;
|
|
76
|
+
readonly transport: Transport;
|
|
77
|
+
readonly managedTransport: Transport;
|
|
78
|
+
readonly sessions: Option.Option<OpenAiCodexSessions>;
|
|
79
|
+
/** What a request to a model that binds thinking says about a changed prefix (`thinkingPrefixMismatch`). */
|
|
80
|
+
readonly thinkingPrefixMismatch: ThinkingPrefixMismatch;
|
|
81
|
+
}
|
|
82
|
+
/** The provider services where this runs: `CurrentModelEndpoints`, `CurrentModelSettings`, `ModelsTransport` if provided, `CurrentOpenAiCodexSessions`, `CurrentThinkingPrefixMismatch`. */
|
|
83
|
+
export declare const providerServices: Effect.Effect<ProviderServices>;
|
|
84
|
+
type MessagesEndpoint = Extract<ModelEndpoint, {
|
|
85
|
+
readonly api: "anthropic-messages";
|
|
86
|
+
}>;
|
|
87
|
+
/** Accept a root, a proxy prefix or a base ending in /v1, without doubling the Messages path. */
|
|
88
|
+
export declare const anthropicBaseUrl: (base: string) => string;
|
|
89
|
+
/** A model configuration failure is not an authentication failure or a retryable provider outage. */
|
|
90
|
+
export declare const modelSettingsFailure: (error: ModelSettingsError) => AiError.AiError;
|
|
91
|
+
/** Public Messages controls shared by provider construction and durable routing descriptions; no credentials or client IO. */
|
|
92
|
+
export declare const resolveMessagesConfiguration: (selection: ModelSelection, modelSettings: ModelSettingsMap, policy: Option.Option<ModelCallPolicy>, thinkingPrefixMismatch: ThinkingPrefixMismatch, endpoint: Option.Option<MessagesEndpoint>) => Result.Result<{
|
|
93
|
+
resolved: {
|
|
94
|
+
readonly selection: string;
|
|
95
|
+
readonly maxOutputTokens: number;
|
|
96
|
+
readonly effort: Option.Option<"low" | "medium" | "high" | "xhigh" | "max">;
|
|
97
|
+
readonly thinking: Option.Option<{
|
|
98
|
+
readonly _tag: "Off";
|
|
99
|
+
} | {
|
|
100
|
+
readonly _tag: "Adaptive";
|
|
101
|
+
readonly display?: "omitted" | "summarized";
|
|
102
|
+
} | {
|
|
103
|
+
readonly _tag: "Budget";
|
|
104
|
+
readonly budgetTokens: number;
|
|
105
|
+
readonly display?: "omitted" | "summarized";
|
|
106
|
+
} | {
|
|
107
|
+
readonly _tag: "BetweenTools";
|
|
108
|
+
}>;
|
|
109
|
+
readonly promptCache: {
|
|
110
|
+
readonly _tag: "Auto";
|
|
111
|
+
readonly ttl: "5m" | "1h";
|
|
112
|
+
} | {
|
|
113
|
+
readonly _tag: "TopLevel";
|
|
114
|
+
readonly ttl: "5m" | "1h";
|
|
115
|
+
} | {
|
|
116
|
+
readonly _tag: "Off";
|
|
117
|
+
};
|
|
118
|
+
readonly limits?: {
|
|
119
|
+
readonly maxOutputTokens?: number;
|
|
120
|
+
readonly contextWindow?: number;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
binding: Option.Option<"error" | "drop_block">;
|
|
124
|
+
wire: Schema.JsonObject;
|
|
125
|
+
settings: Schema.JsonObject;
|
|
126
|
+
}, ModelSettingsError>;
|
|
127
|
+
/**
|
|
128
|
+
* {@link buildProvider} over the given provider services, not those where
|
|
129
|
+
* it runs: a routed model builds each call's provider over the services its
|
|
130
|
+
* layer was built with.
|
|
50
131
|
*/
|
|
51
|
-
export declare const
|
|
132
|
+
export declare const buildProviderOver: (services: ProviderServices) => (selection: ModelSelection, credential: Credential | undefined, key: Redacted.Redacted<string> | undefined) => Effect.Effect<BuiltProvider, AuthError | ModelSettingsError, HttpClient.HttpClient | Scope.Scope>;
|
|
52
133
|
/**
|
|
53
134
|
* Preserve adapter descriptors and describe the public configuration of
|
|
54
|
-
* SDK-backed models. On a route that reads no images (
|
|
55
|
-
* configured endpoint's `images`), every request is sent with its images
|
|
56
|
-
* label lines (`promptWithImageLabels`) instead of a provider error.
|
|
135
|
+
* SDK-backed models. On a route that reads no images (the model's profile,
|
|
136
|
+
* a configured endpoint's `images`), every request is sent with its images
|
|
137
|
+
* as label lines (`promptWithImageLabels`) instead of a provider error.
|
|
138
|
+
* Built over the provider services where it runs (`providerServices`).
|
|
57
139
|
*/
|
|
58
|
-
export declare const buildProvider: (selection: ModelSelection, credential: Credential | undefined, key: Redacted.Redacted<string> | undefined) => Effect.Effect<BuiltProvider, AuthError, HttpClient.HttpClient | Scope.Scope>;
|
|
140
|
+
export declare const buildProvider: (selection: ModelSelection, credential: Credential | undefined, key: Redacted.Redacted<string> | undefined) => Effect.Effect<BuiltProvider, AuthError | ModelSettingsError, HttpClient.HttpClient | Scope.Scope>;
|