@mushinjs/plugin-providers 0.0.0-stage → 0.2.0-next.20261112165327

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Setobox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,188 @@
1
+ import { ChatRequest, ChatResponse, ContentPart, DecisionAnswer, DecisionAsset, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionText, EmbedRequest, EmbedResponse, FinishReason, LlmChatOptions, LlmDecideOptions, LlmDecideResult, LlmEmbedOptions, LlmEmbedResult, LlmMessage, LlmResult, ModelProfile, ProfileModel, ProviderCapability, ProviderClient, ProviderPreset, ProviderRecord, ProviderTest, ProviderType, RawTurn, StreamEvent, ToolCall, ToolDefinition, Usage } from "./types.js";
2
+ import { Context, Service, z } from "@mushinjs/core";
3
+ declare module '@mushinjs/core' {
4
+ interface Context {
5
+ llm: LlmService;
6
+ }
7
+ interface Events {
8
+ 'providers/changed'(): void;
9
+ 'llm/called'(call: LlmCall): void;
10
+ }
11
+ }
12
+ /** One finished model request, for usage statistics. */
13
+ export interface LlmCall {
14
+ provider: string;
15
+ providerName: string;
16
+ model: string;
17
+ ok: boolean;
18
+ inputTokens?: number;
19
+ outputTokens?: number;
20
+ latencyMs: number;
21
+ }
22
+ /** Most texts sent in one embedding request. */
23
+ export declare const EMBED_BATCH = 64;
24
+ declare const providerInput: z.ZodObject<{
25
+ name: z.ZodString;
26
+ type: z.ZodString;
27
+ config: z.ZodRecord<z.ZodString, z.ZodAny>;
28
+ models: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ defaultModel: z.ZodOptional<z.ZodString>;
30
+ isDefault: z.ZodOptional<z.ZodBoolean>;
31
+ }, z.core.$strip>;
32
+ declare const profileInput: z.ZodObject<{
33
+ name: z.ZodString;
34
+ models: z.ZodArray<z.ZodObject<{
35
+ provider: z.ZodString;
36
+ model: z.ZodString;
37
+ }, z.core.$strip>>;
38
+ }, z.core.$strip>;
39
+ /**
40
+ * Owns provider records and exposes one `chat` entry point.
41
+ * Provider types (OpenAI-compatible, Anthropic, ...) are registered by other plugins.
42
+ */
43
+ export declare class LlmService extends Service {
44
+ static inject: string[];
45
+ private home;
46
+ private typeStore;
47
+ private records;
48
+ private profileRecords;
49
+ private clients;
50
+ constructor(ctx: Context);
51
+ /** Provider lifecycle lines, tagged `provider` in the dashboard. Never includes config values. */
52
+ private get logger();
53
+ [Service.init](): AsyncGenerator<import("cordis").Disposable<Promise<void>>, void, unknown>;
54
+ /** Registers a provider type. It is removed when the calling plugin unloads. */
55
+ defineType<C>(type: ProviderType<C>): import("cordis").Disposable<Promise<void>>;
56
+ types(): {
57
+ id: string;
58
+ displayName: import("@mushinjs/core").LocalizedText;
59
+ configSchema: import("@mushinjs/core").JsonSchema;
60
+ secrets: string[];
61
+ presets: ProviderPreset[];
62
+ capabilities: ProviderCapability[];
63
+ }[];
64
+ list(): {
65
+ config: {
66
+ [x: string]: any;
67
+ };
68
+ typeAvailable: boolean;
69
+ capabilities: ProviderCapability[];
70
+ id: string;
71
+ name: string;
72
+ type: string;
73
+ models: string[];
74
+ defaultModel?: string;
75
+ isDefault?: boolean;
76
+ lastTest?: ProviderTest;
77
+ createdAt: number;
78
+ }[];
79
+ get(id: string): ProviderRecord;
80
+ /** What a saved provider can do. A record whose type is not loaded counts as a chat provider. */
81
+ capabilities(record: ProviderRecord): ProviderCapability[];
82
+ supports(record: ProviderRecord, capability: ProviderCapability): boolean;
83
+ /** The default provider that can do `capability`, or the first such one if none is marked default. */
84
+ defaultProvider(capability?: ProviderCapability): ProviderRecord;
85
+ /** True when at least one chat provider has passed its connection test. */
86
+ isReady(): boolean;
87
+ private redact;
88
+ private requireType;
89
+ private validateConfig;
90
+ private save;
91
+ create(input: z.infer<typeof providerInput>): Promise<{
92
+ config: {
93
+ [x: string]: any;
94
+ };
95
+ typeAvailable: boolean;
96
+ capabilities: ProviderCapability[];
97
+ id: string;
98
+ name: string;
99
+ type: string;
100
+ models: string[];
101
+ defaultModel?: string;
102
+ isDefault?: boolean;
103
+ lastTest?: ProviderTest;
104
+ createdAt: number;
105
+ }>;
106
+ update(id: string, patch: Partial<z.infer<typeof providerInput>>): Promise<{
107
+ config: {
108
+ [x: string]: any;
109
+ };
110
+ typeAvailable: boolean;
111
+ capabilities: ProviderCapability[];
112
+ id: string;
113
+ name: string;
114
+ type: string;
115
+ models: string[];
116
+ defaultModel?: string;
117
+ isDefault?: boolean;
118
+ lastTest?: ProviderTest;
119
+ createdAt: number;
120
+ }>;
121
+ delete(id: string): Promise<{
122
+ deleted: string;
123
+ }>;
124
+ private markDefault;
125
+ /** Log lines name a provider by its id; the dashboard links it to the provider. */
126
+ private label;
127
+ setDefault(id: string): Promise<{
128
+ config: {
129
+ [x: string]: any;
130
+ };
131
+ typeAvailable: boolean;
132
+ capabilities: ProviderCapability[];
133
+ id: string;
134
+ name: string;
135
+ type: string;
136
+ models: string[];
137
+ defaultModel?: string;
138
+ isDefault?: boolean;
139
+ lastTest?: ProviderTest;
140
+ createdAt: number;
141
+ }>;
142
+ profiles(): ModelProfile[];
143
+ getProfile(id: string): ModelProfile;
144
+ isProfile(id: string): boolean;
145
+ private checkProfileModels;
146
+ createProfile(input: z.infer<typeof profileInput>): Promise<ModelProfile>;
147
+ updateProfile(id: string, patch: Partial<z.infer<typeof profileInput>>): Promise<ModelProfile>;
148
+ deleteProfile(id: string): Promise<{
149
+ deleted: string;
150
+ }>;
151
+ /** Providers and profiles as `{ value, label }`, for fields that take either. */
152
+ choices(): {
153
+ value: string;
154
+ label: string;
155
+ group: string;
156
+ }[];
157
+ client(record: ProviderRecord): ProviderClient;
158
+ private resolve;
159
+ /** Where a request goes: one provider and model, or a profile's models in order. */
160
+ private targets;
161
+ /** Logs a failed model of a profile and says whether to try the next one. */
162
+ private fallBack;
163
+ /** Counts a request against the message being handled, if any; see `usage` in core. */
164
+ private report;
165
+ private result;
166
+ /** Runs one chat completion through the chosen (or default) provider. */
167
+ chat(options: LlmChatOptions): Promise<LlmResult>;
168
+ /** Streams text deltas, then yields the final result. Falls back to `chat` for clients without streaming. */
169
+ stream(options: LlmChatOptions): AsyncGenerator<StreamEvent | {
170
+ type: 'result';
171
+ result: LlmResult;
172
+ }>;
173
+ /** Whether a provider can embed text, for pickers. */
174
+ canEmbed(id: string): boolean;
175
+ /** Embeds texts through a provider, `EMBED_BATCH` at a time; each batch is retried once. */
176
+ embed(options: LlmEmbedOptions): Promise<LlmEmbedResult>;
177
+ /** Asks a decision provider structured questions about a state. */
178
+ decide(options: LlmDecideOptions): Promise<LlmDecideResult>;
179
+ private logRequestError;
180
+ test(id: string): Promise<ProviderTest>;
181
+ models(input: {
182
+ provider?: string;
183
+ type?: string;
184
+ config?: Record<string, any>;
185
+ }): Promise<string[]>;
186
+ private defineActions;
187
+ }
188
+ export { ChatRequest, ChatResponse, ContentPart, DecisionAnswer, DecisionAsset, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionText, EmbedRequest, EmbedResponse, FinishReason, LlmChatOptions, LlmDecideOptions, LlmDecideResult, LlmEmbedOptions, LlmEmbedResult, LlmMessage, LlmResult, LlmService as default, ModelProfile, ProfileModel, ProviderCapability, ProviderClient, ProviderPreset, ProviderRecord, ProviderTest, ProviderType, RawTurn, StreamEvent, ToolCall, ToolDefinition, Usage };