@xandreed/plugin-models 0.13.0 → 0.15.0

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.
Files changed (151) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/anthropicOAuth.d.ts +45 -11
  3. package/dist/auth/anthropicOAuth.js +23 -23
  4. package/dist/auth/auth-store.conformance.d.ts +63 -0
  5. package/dist/auth/auth-store.conformance.js +152 -0
  6. package/dist/auth/credential-input.entity.d.ts +52 -0
  7. package/dist/auth/credential-input.entity.functions.d.ts +18 -0
  8. package/dist/auth/credential-input.entity.functions.js +12 -0
  9. package/dist/auth/credential-input.entity.js +22 -0
  10. package/dist/auth/credential-refresh.entity.d.ts +17 -0
  11. package/dist/auth/credential-refresh.entity.functions.d.ts +57 -0
  12. package/dist/auth/credential-refresh.entity.functions.js +21 -0
  13. package/dist/auth/credential-refresh.entity.js +2 -0
  14. package/dist/auth/localAuth.d.ts +12 -2
  15. package/dist/auth/localAuth.js +58 -86
  16. package/dist/auth/memory-auth.adapter.d.ts +35 -0
  17. package/dist/auth/memory-auth.adapter.js +35 -0
  18. package/dist/auth/openAiCodexOAuth.d.ts +28 -6
  19. package/dist/auth/openAiCodexOAuth.js +22 -32
  20. package/dist/auth/token-response.entity.d.ts +21 -0
  21. package/dist/auth/token-response.entity.functions.d.ts +20 -0
  22. package/dist/auth/token-response.entity.functions.js +10 -0
  23. package/dist/auth/token-response.entity.js +10 -0
  24. package/dist/compat/index.d.ts +2 -0
  25. package/dist/compat/index.js +1 -0
  26. package/dist/conformance/index.d.ts +6 -0
  27. package/dist/conformance/index.js +3 -0
  28. package/dist/index.d.ts +30 -13
  29. package/dist/index.js +25 -50
  30. package/dist/llm/chat-wire.entity.d.ts +123 -0
  31. package/dist/llm/chat-wire.entity.functions.d.ts +28 -0
  32. package/dist/llm/chat-wire.entity.functions.js +10 -0
  33. package/dist/llm/chat-wire.entity.js +37 -0
  34. package/dist/llm/compat-telemetry.adapter.d.ts +6 -0
  35. package/dist/llm/compat-telemetry.adapter.js +21 -0
  36. package/dist/llm/compat.d.ts +84 -33
  37. package/dist/llm/compat.js +188 -121
  38. package/dist/llm/model-completion.adapter.d.ts +49 -0
  39. package/dist/llm/model-completion.adapter.js +77 -0
  40. package/dist/llm/model-completion.entity.d.ts +4 -0
  41. package/dist/llm/model-completion.entity.functions.d.ts +3 -0
  42. package/dist/llm/model-completion.entity.functions.js +7 -0
  43. package/dist/llm/model-completion.entity.js +7 -0
  44. package/dist/llm/model-retry-policy.entity.d.ts +37 -0
  45. package/dist/llm/model-retry-policy.entity.functions.d.ts +16 -0
  46. package/dist/llm/model-retry-policy.entity.functions.js +33 -0
  47. package/dist/llm/model-retry-policy.entity.js +23 -0
  48. package/dist/llm/model-settings.entity.d.ts +85 -0
  49. package/dist/llm/model-settings.entity.functions.d.ts +11 -0
  50. package/dist/llm/model-settings.entity.functions.js +49 -0
  51. package/dist/llm/model-settings.entity.js +28 -0
  52. package/dist/llm/model-usage.entity.d.ts +61 -0
  53. package/dist/llm/model-usage.entity.functions.d.ts +11 -0
  54. package/dist/llm/model-usage.entity.functions.js +24 -0
  55. package/dist/llm/model-usage.entity.js +19 -0
  56. package/dist/llm/modelCatalog.d.ts +47 -7
  57. package/dist/llm/modelCatalog.js +31 -57
  58. package/dist/llm/openAiCodex.d.ts +18 -7
  59. package/dist/llm/openAiCodex.js +57 -45
  60. package/dist/llm/openAiCodexWebSocket.d.ts +60 -7
  61. package/dist/llm/openAiCodexWebSocket.js +113 -105
  62. package/dist/llm/prompt-cache-frame.entity.d.ts +18 -0
  63. package/dist/llm/prompt-cache-frame.entity.js +10 -0
  64. package/dist/llm/prompt-cache.entity.d.ts +57 -0
  65. package/dist/llm/prompt-cache.entity.functions.d.ts +8 -0
  66. package/dist/llm/prompt-cache.entity.functions.js +73 -0
  67. package/dist/llm/prompt-cache.entity.js +27 -0
  68. package/dist/llm/provider-client.adapter.d.ts +9 -0
  69. package/dist/llm/provider-client.adapter.js +60 -0
  70. package/dist/llm/provider-failure.entity.d.ts +42 -0
  71. package/dist/llm/provider-failure.entity.functions.d.ts +8 -0
  72. package/dist/llm/provider-failure.entity.functions.js +67 -0
  73. package/dist/llm/provider-failure.entity.js +20 -0
  74. package/dist/llm/provider-profile.entity.d.ts +79 -0
  75. package/dist/llm/provider-profile.entity.functions.d.ts +23 -0
  76. package/dist/llm/provider-profile.entity.functions.js +83 -0
  77. package/dist/llm/provider-profile.entity.js +10 -0
  78. package/dist/llm/providers.d.ts +125 -29
  79. package/dist/llm/providers.js +311 -117
  80. package/dist/llm/retry.d.ts +11 -47
  81. package/dist/llm/retry.js +33 -52
  82. package/dist/llm/router.d.ts +56 -28
  83. package/dist/llm/router.js +125 -88
  84. package/dist/llm/sse.d.ts +58 -29
  85. package/dist/llm/sse.js +47 -39
  86. package/dist/llm/thinking-binding.entity.d.ts +49 -0
  87. package/dist/llm/thinking-binding.entity.functions.d.ts +21 -0
  88. package/dist/llm/thinking-binding.entity.functions.js +16 -0
  89. package/dist/llm/thinking-binding.entity.js +11 -0
  90. package/dist/llm/utilityLlm.d.ts +14 -5
  91. package/dist/llm/utilityLlm.js +18 -13
  92. package/dist/plugin.adapter.d.ts +154 -6
  93. package/dist/plugin.adapter.js +53 -10
  94. package/dist/ports/auth-store.port.d.ts +73 -0
  95. package/dist/ports/auth-store.port.js +24 -0
  96. package/dist/ports/host-credentials.port.d.ts +22 -0
  97. package/dist/ports/host-credentials.port.js +4 -0
  98. package/dist/ports/model-call-completion.port.d.ts +9 -0
  99. package/dist/ports/model-call-completion.port.js +2 -0
  100. package/dist/ports/model-endpoints.port.d.ts +66 -19
  101. package/dist/ports/model-endpoints.port.js +22 -4
  102. package/dist/ports/model-retry-policy.port.d.ts +17 -0
  103. package/dist/ports/model-retry-policy.port.js +3 -0
  104. package/dist/ports/model-settings.port.d.ts +32 -0
  105. package/dist/ports/model-settings.port.js +4 -0
  106. package/dist/ports/models-transport.port.d.ts +53 -0
  107. package/dist/ports/models-transport.port.js +7 -0
  108. package/dist/ports/prompt-cache-frame.port.d.ts +21 -0
  109. package/dist/ports/prompt-cache-frame.port.js +4 -0
  110. package/dist/ports/settings-store.port.d.ts +70 -0
  111. package/dist/ports/settings-store.port.js +33 -0
  112. package/dist/ports/thinking-binding.port.d.ts +7 -0
  113. package/dist/ports/thinking-binding.port.js +4 -0
  114. package/dist/settings/localSettings.d.ts +2 -1
  115. package/dist/settings/localSettings.js +18 -61
  116. package/dist/settings/memory-settings.adapter.d.ts +12 -0
  117. package/dist/settings/memory-settings.adapter.js +11 -0
  118. package/dist/settings/roleView.d.ts +3 -1
  119. package/dist/settings/roleView.js +1 -1
  120. package/dist/settings/settings-store.conformance.d.ts +47 -0
  121. package/dist/settings/settings-store.conformance.js +100 -0
  122. package/dist/settings/settings-value.entity.d.ts +15 -0
  123. package/dist/settings/settings-value.entity.functions.d.ts +51 -0
  124. package/dist/settings/settings-value.entity.functions.js +42 -0
  125. package/dist/settings/settings-value.entity.js +2 -0
  126. package/dist/storage/json-file.d.ts +18 -0
  127. package/dist/storage/json-file.js +26 -0
  128. package/dist/transport/http-proxy.entity.d.ts +104 -0
  129. package/dist/transport/http-proxy.entity.functions.d.ts +51 -0
  130. package/dist/transport/http-proxy.entity.functions.js +112 -0
  131. package/dist/transport/http-proxy.entity.js +42 -0
  132. package/dist/transport/model-request.conformance.d.ts +13 -0
  133. package/dist/transport/model-request.conformance.js +36 -0
  134. package/dist/transport/models-transport.adapter.d.ts +49 -0
  135. package/dist/transport/models-transport.adapter.js +99 -0
  136. package/dist/transport/resilient-http-client.adapter.d.ts +73 -0
  137. package/dist/transport/resilient-http-client.adapter.js +177 -0
  138. package/dist/transport/undici-fetch.adapter.d.ts +13 -0
  139. package/dist/transport/undici-fetch.adapter.js +1 -0
  140. package/package.json +13 -6
  141. package/dist/auth/anthropicOAuth.test.d.ts +0 -1
  142. package/dist/auth/localAuth.test.d.ts +0 -1
  143. package/dist/llm/compat.test.d.ts +0 -1
  144. package/dist/llm/modelCatalog.test.d.ts +0 -1
  145. package/dist/llm/providers.test.d.ts +0 -1
  146. package/dist/llm/retry.test.d.ts +0 -1
  147. package/dist/llm/router.test.d.ts +0 -1
  148. package/dist/llm/sse.test.d.ts +0 -1
  149. package/dist/plugin.adapter.test.d.ts +0 -1
  150. package/dist/settings/localSettings.test.d.ts +0 -1
  151. package/dist/settings/roleView.test.d.ts +0 -1
@@ -1,44 +1,140 @@
1
- import { LanguageModel } from "effect/ai";
1
+ import { AiError, LanguageModel, Prompt } from "effect/ai";
2
2
  import { HttpClient } from "effect/http";
3
- import { Effect, Redacted } from "effect";
4
- import type { Scope } from "effect";
5
- import { AuthError } from "@xandreed/core";
6
- import type { Credential, ModelSelection } from "@xandreed/core";
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";
8
+ import { usesOpenCodeResponses } from "./modelCatalog.js";
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";
7
16
  /**
8
17
  * Per-provider `LanguageModel` construction. Built PER REQUEST from a
9
18
  * freshly-resolved key (never captured at layer build), so a credential or
10
19
  * model switch applies on the next call.
11
20
  *
12
- * v1 providers: opencode (OpenAI-compatible gateway — the default), google
13
- * (Gemini's OpenAI-compatible endpoint), anthropic (api key or subscription
14
- * OAuth), openai (api key), openai-codex (subscription OAuth). A configured
15
- * endpoint, or a `local` credential with a `baseUrl`, sends its provider's
16
- * models to that OpenAI-compatible URL, with or without a key.
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.
17
28
  */
18
- export declare const OPENCODE_CHAT_URL = "https://opencode.ai/zen/go/v1/chat/completions";
19
- /** OpenCode serves GPT models through the OpenAI Responses protocol. */
20
- export declare const OPENCODE_RESPONSES_API_URL = "https://opencode.ai/zen/v1";
21
- /** Gemini through its OpenAI-compatible chat completions (Bearer API key). */
22
- export declare const GOOGLE_CHAT_URL = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions";
23
- /** Pure protocol routing decision; provider details stay inside this adapter. */
24
- export declare const usesOpenCodeResponses: (modelId: string) => boolean;
29
+ export { GOOGLE_CHAT_URL, OPENCODE_CHAT_URL, OPENCODE_RESPONSES_API_URL } from "./provider-profile.entity.functions.js";
30
+ export { usesOpenCodeResponses };
25
31
  export interface BuiltProvider {
26
32
  readonly svc: LanguageModel.LanguageModel;
27
33
  /** Anthropic subscription auth requires the Claude Code system block first. */
28
34
  readonly prependClaudeCode: boolean;
35
+ /** The route sends images; when it does not, `buildProvider` has the model send them as label lines. */
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"];
29
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
+ };
30
49
  /** Prepend the Claude Code system block (subscription-auth requirement). */
31
- export declare const prependClaudeCode: (options: unknown) => unknown;
32
- /**
33
- * Anthropic prompt caching is OPT-IN per request: stamp ephemeral
34
- * `cache_control` breakpoints on the last system message + the last two
35
- * non-system messages. Marker placement is not part of Anthropic's content
36
- * hash, so the markers moving forward each turn never invalidates earlier
37
- * prefixes. Messages already carrying an explicit `cacheControl` are left
38
- * alone.
39
- */
40
- 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
+ };
41
53
  /** `<url>/chat/completions` of an OpenAI-compatible base URL. */
42
54
  export declare const chatCompletionsUrl: (baseUrl: string) => string;
43
- /** Preserve adapter descriptors and describe the public configuration of SDK-backed models. */
44
- export declare const buildProvider: (selection: ModelSelection, credential: Credential | undefined, key: Redacted.Redacted<string> | undefined) => Effect.Effect<BuiltProvider, AuthError, HttpClient.HttpClient | Scope.Scope>;
55
+ /**
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.
131
+ */
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>;
133
+ /**
134
+ * Preserve adapter descriptors and describe the public configuration of
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`).
139
+ */
140
+ export declare const buildProvider: (selection: ModelSelection, credential: Credential | undefined, key: Redacted.Redacted<string> | undefined) => Effect.Effect<BuiltProvider, AuthError | ModelSettingsError, HttpClient.HttpClient | Scope.Scope>;