@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.
Files changed (151) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/anthropicOAuth.d.ts +30 -10
  3. package/dist/auth/anthropicOAuth.js +15 -18
  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 +23 -5
  7. package/dist/auth/credential-input.entity.functions.d.ts +15 -5
  8. package/dist/auth/credential-input.entity.functions.js +12 -9
  9. package/dist/auth/credential-input.entity.js +5 -3
  10. package/dist/auth/credential-refresh.entity.d.ts +11 -3
  11. package/dist/auth/credential-refresh.entity.functions.d.ts +48 -6
  12. package/dist/auth/credential-refresh.entity.functions.js +12 -3
  13. package/dist/auth/localAuth.d.ts +10 -1
  14. package/dist/auth/localAuth.js +53 -79
  15. package/dist/auth/memory-auth.adapter.d.ts +12 -4
  16. package/dist/auth/memory-auth.adapter.js +13 -25
  17. package/dist/auth/openAiCodexOAuth.d.ts +26 -5
  18. package/dist/auth/openAiCodexOAuth.js +17 -28
  19. package/dist/auth/token-response.entity.d.ts +21 -0
  20. package/dist/auth/token-response.entity.functions.d.ts +20 -0
  21. package/dist/auth/token-response.entity.functions.js +10 -0
  22. package/dist/auth/token-response.entity.js +10 -0
  23. package/dist/compat/index.d.ts +2 -0
  24. package/dist/compat/index.js +1 -0
  25. package/dist/conformance/index.d.ts +6 -0
  26. package/dist/conformance/index.js +3 -0
  27. package/dist/index.d.ts +19 -19
  28. package/dist/index.js +17 -69
  29. package/dist/llm/chat-wire.entity.d.ts +123 -0
  30. package/dist/llm/chat-wire.entity.functions.d.ts +28 -0
  31. package/dist/llm/chat-wire.entity.functions.js +10 -0
  32. package/dist/llm/chat-wire.entity.js +37 -0
  33. package/dist/llm/compat-telemetry.adapter.d.ts +6 -0
  34. package/dist/llm/compat-telemetry.adapter.js +21 -0
  35. package/dist/llm/compat.d.ts +50 -30
  36. package/dist/llm/compat.js +149 -133
  37. package/dist/llm/model-completion.adapter.d.ts +49 -0
  38. package/dist/llm/model-completion.adapter.js +77 -0
  39. package/dist/llm/model-completion.entity.d.ts +4 -0
  40. package/dist/llm/model-completion.entity.functions.d.ts +3 -0
  41. package/dist/llm/model-completion.entity.functions.js +7 -0
  42. package/dist/llm/model-completion.entity.js +7 -0
  43. package/dist/llm/model-retry-policy.entity.d.ts +37 -0
  44. package/dist/llm/model-retry-policy.entity.functions.d.ts +16 -0
  45. package/dist/llm/model-retry-policy.entity.functions.js +33 -0
  46. package/dist/llm/model-retry-policy.entity.js +23 -0
  47. package/dist/llm/model-settings.entity.d.ts +85 -0
  48. package/dist/llm/model-settings.entity.functions.d.ts +11 -0
  49. package/dist/llm/model-settings.entity.functions.js +49 -0
  50. package/dist/llm/model-settings.entity.js +28 -0
  51. package/dist/llm/model-usage.entity.d.ts +61 -0
  52. package/dist/llm/model-usage.entity.functions.d.ts +11 -0
  53. package/dist/llm/model-usage.entity.functions.js +24 -0
  54. package/dist/llm/model-usage.entity.js +19 -0
  55. package/dist/llm/modelCatalog.d.ts +29 -8
  56. package/dist/llm/modelCatalog.js +28 -66
  57. package/dist/llm/openAiCodex.d.ts +15 -7
  58. package/dist/llm/openAiCodex.js +57 -45
  59. package/dist/llm/openAiCodexWebSocket.d.ts +48 -15
  60. package/dist/llm/openAiCodexWebSocket.js +101 -147
  61. package/dist/llm/prompt-cache-frame.entity.d.ts +18 -0
  62. package/dist/llm/prompt-cache-frame.entity.js +10 -0
  63. package/dist/llm/prompt-cache.entity.d.ts +57 -0
  64. package/dist/llm/prompt-cache.entity.functions.d.ts +8 -0
  65. package/dist/llm/prompt-cache.entity.functions.js +73 -0
  66. package/dist/llm/prompt-cache.entity.js +27 -0
  67. package/dist/llm/provider-client.adapter.d.ts +9 -0
  68. package/dist/llm/provider-client.adapter.js +60 -0
  69. package/dist/llm/provider-failure.entity.d.ts +42 -0
  70. package/dist/llm/provider-failure.entity.functions.d.ts +8 -0
  71. package/dist/llm/provider-failure.entity.functions.js +67 -0
  72. package/dist/llm/provider-failure.entity.js +20 -0
  73. package/dist/llm/provider-profile.entity.d.ts +79 -0
  74. package/dist/llm/provider-profile.entity.functions.d.ts +23 -0
  75. package/dist/llm/provider-profile.entity.functions.js +83 -0
  76. package/dist/llm/provider-profile.entity.js +10 -0
  77. package/dist/llm/providers.d.ts +116 -34
  78. package/dist/llm/providers.js +298 -129
  79. package/dist/llm/retry.d.ts +11 -47
  80. package/dist/llm/retry.js +33 -52
  81. package/dist/llm/router.d.ts +54 -36
  82. package/dist/llm/router.js +91 -78
  83. package/dist/llm/sse.d.ts +44 -37
  84. package/dist/llm/sse.js +43 -35
  85. package/dist/llm/thinking-binding.entity.d.ts +49 -0
  86. package/dist/llm/thinking-binding.entity.functions.d.ts +21 -0
  87. package/dist/llm/thinking-binding.entity.functions.js +16 -0
  88. package/dist/llm/thinking-binding.entity.js +11 -0
  89. package/dist/llm/utilityLlm.d.ts +14 -5
  90. package/dist/llm/utilityLlm.js +18 -13
  91. package/dist/plugin.adapter.d.ts +94 -6
  92. package/dist/plugin.adapter.js +18 -13
  93. package/dist/ports/auth-store.port.d.ts +73 -0
  94. package/dist/ports/auth-store.port.js +24 -0
  95. package/dist/ports/host-credentials.port.d.ts +2 -1
  96. package/dist/ports/model-call-completion.port.d.ts +9 -0
  97. package/dist/ports/model-call-completion.port.js +2 -0
  98. package/dist/ports/model-endpoints.port.d.ts +60 -26
  99. package/dist/ports/model-endpoints.port.js +17 -3
  100. package/dist/ports/model-retry-policy.port.d.ts +17 -0
  101. package/dist/ports/model-retry-policy.port.js +3 -0
  102. package/dist/ports/model-settings.port.d.ts +32 -0
  103. package/dist/ports/model-settings.port.js +4 -0
  104. package/dist/ports/models-transport.port.d.ts +9 -2
  105. package/dist/ports/models-transport.port.js +4 -1
  106. package/dist/ports/prompt-cache-frame.port.d.ts +21 -0
  107. package/dist/ports/prompt-cache-frame.port.js +4 -0
  108. package/dist/ports/settings-store.port.d.ts +70 -0
  109. package/dist/ports/settings-store.port.js +33 -0
  110. package/dist/ports/thinking-binding.port.d.ts +7 -0
  111. package/dist/ports/thinking-binding.port.js +4 -0
  112. package/dist/settings/localSettings.d.ts +2 -1
  113. package/dist/settings/localSettings.js +17 -20
  114. package/dist/settings/memory-settings.adapter.d.ts +3 -1
  115. package/dist/settings/memory-settings.adapter.js +1 -1
  116. package/dist/settings/roleView.d.ts +3 -1
  117. package/dist/settings/roleView.js +1 -1
  118. package/dist/settings/settings-store.conformance.d.ts +47 -0
  119. package/dist/settings/settings-store.conformance.js +100 -0
  120. package/dist/settings/settings-value.entity.d.ts +10 -2
  121. package/dist/settings/settings-value.entity.functions.d.ts +31 -9
  122. package/dist/settings/settings-value.entity.functions.js +5 -6
  123. package/dist/storage/json-file.d.ts +18 -0
  124. package/dist/storage/json-file.js +26 -0
  125. package/dist/transport/http-proxy.entity.d.ts +17 -3
  126. package/dist/transport/model-request.conformance.d.ts +13 -0
  127. package/dist/transport/model-request.conformance.js +36 -0
  128. package/dist/transport/models-transport.adapter.d.ts +18 -17
  129. package/dist/transport/models-transport.adapter.js +28 -31
  130. package/dist/transport/resilient-http-client.adapter.d.ts +73 -0
  131. package/dist/transport/resilient-http-client.adapter.js +177 -0
  132. package/package.json +11 -5
  133. package/dist/auth/anthropicOAuth.test.d.ts +0 -1
  134. package/dist/auth/credential-refresh.entity.functions.test.d.ts +0 -1
  135. package/dist/auth/localAuth.test.d.ts +0 -1
  136. package/dist/auth/memory-auth.adapter.test.d.ts +0 -1
  137. package/dist/llm/compat.test.d.ts +0 -1
  138. package/dist/llm/modelCatalog.test.d.ts +0 -1
  139. package/dist/llm/openAiCodexWebSocket.test.d.ts +0 -1
  140. package/dist/llm/providers.test.d.ts +0 -1
  141. package/dist/llm/retry.test.d.ts +0 -1
  142. package/dist/llm/router.test.d.ts +0 -1
  143. package/dist/llm/sse.test.d.ts +0 -1
  144. package/dist/plugin.adapter.test.d.ts +0 -1
  145. package/dist/settings/localSettings.test.d.ts +0 -1
  146. package/dist/settings/memory-settings.adapter.test.d.ts +0 -1
  147. package/dist/settings/roleView.test.d.ts +0 -1
  148. package/dist/settings/settings-value.entity.functions.test.d.ts +0 -1
  149. package/dist/transport/http-proxy.entity.functions.test.d.ts +0 -1
  150. package/dist/transport/models-transport.adapter.test.d.ts +0 -1
  151. package/dist/transport/recording-proxy.testing.d.ts +0 -33
@@ -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 "@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";
7
8
  import { usesOpenCodeResponses } from "./modelCatalog.js";
8
- import type { ModelEndpoint } from "../ports/model-endpoints.port.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";
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
- * v1 providers: opencode (OpenAI-compatible gateway — the default), google
15
- * (Gemini's OpenAI-compatible endpoint), anthropic (api key or subscription
16
- * OAuth), openai (api key), openai-codex (subscription OAuth). A configured
17
- * endpoint, or a `local` credential with a `baseUrl`, sends its provider's
18
- * 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.
19
28
  */
20
- export declare const OPENCODE_CHAT_URL = "https://opencode.ai/zen/go/v1/chat/completions";
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: unknown) => unknown;
35
- /**
36
- * Anthropic prompt caching is OPT-IN per request: stamp ephemeral
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 environment variable `apiKeyEnv`
48
- * names when it is set. An empty one is still the endpoint's own: it sends
49
- * no key, and the AuthStore's is not used.
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 endpointOwnKey: (endpoint: ModelEndpoint) => Option.Option<Redacted.Redacted<string>>;
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 (`imageInputFor`, a
55
- * configured endpoint's `images`), every request is sent with its images as
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>;