@effect/ai 0.26.0 → 0.27.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.
- package/Chat/package.json +6 -0
- package/EmbeddingModel/package.json +6 -0
- package/IdGenerator/package.json +6 -0
- package/LanguageModel/package.json +6 -0
- package/Model/package.json +6 -0
- package/Prompt/package.json +6 -0
- package/Response/package.json +6 -0
- package/Telemetry/package.json +6 -0
- package/Tool/package.json +6 -0
- package/Toolkit/package.json +6 -0
- package/dist/cjs/AiError.js +575 -11
- package/dist/cjs/AiError.js.map +1 -1
- package/dist/cjs/Chat.js +302 -0
- package/dist/cjs/Chat.js.map +1 -0
- package/dist/cjs/EmbeddingModel.js +184 -0
- package/dist/cjs/EmbeddingModel.js.map +1 -0
- package/dist/cjs/IdGenerator.js +255 -0
- package/dist/cjs/IdGenerator.js.map +1 -0
- package/dist/cjs/LanguageModel.js +584 -0
- package/dist/cjs/LanguageModel.js.map +1 -0
- package/dist/cjs/McpServer.js +12 -4
- package/dist/cjs/McpServer.js.map +1 -1
- package/dist/cjs/Model.js +118 -0
- package/dist/cjs/Model.js.map +1 -0
- package/dist/cjs/Prompt.js +649 -0
- package/dist/cjs/Prompt.js.map +1 -0
- package/dist/cjs/Response.js +635 -0
- package/dist/cjs/Response.js.map +1 -0
- package/dist/cjs/Telemetry.js +176 -0
- package/dist/cjs/Telemetry.js.map +1 -0
- package/dist/cjs/Tokenizer.js +87 -8
- package/dist/cjs/Tokenizer.js.map +1 -1
- package/dist/cjs/Tool.js +556 -0
- package/dist/cjs/Tool.js.map +1 -0
- package/dist/cjs/Toolkit.js +279 -0
- package/dist/cjs/Toolkit.js.map +1 -0
- package/dist/cjs/index.js +21 -19
- package/dist/dts/AiError.d.ts +577 -9
- package/dist/dts/AiError.d.ts.map +1 -1
- package/dist/dts/Chat.d.ts +356 -0
- package/dist/dts/Chat.d.ts.map +1 -0
- package/dist/dts/EmbeddingModel.d.ts +153 -0
- package/dist/dts/EmbeddingModel.d.ts.map +1 -0
- package/dist/dts/IdGenerator.d.ts +272 -0
- package/dist/dts/IdGenerator.d.ts.map +1 -0
- package/dist/dts/LanguageModel.d.ts +458 -0
- package/dist/dts/LanguageModel.d.ts.map +1 -0
- package/dist/dts/McpSchema.d.ts +25 -25
- package/dist/dts/McpServer.d.ts +6 -4
- package/dist/dts/McpServer.d.ts.map +1 -1
- package/dist/dts/Model.d.ts +124 -0
- package/dist/dts/Model.d.ts.map +1 -0
- package/dist/dts/Prompt.d.ts +1119 -0
- package/dist/dts/Prompt.d.ts.map +1 -0
- package/dist/dts/Response.d.ts +1519 -0
- package/dist/dts/Response.d.ts.map +1 -0
- package/dist/dts/Telemetry.d.ts +520 -0
- package/dist/dts/Telemetry.d.ts.map +1 -0
- package/dist/dts/Tokenizer.d.ts +131 -13
- package/dist/dts/Tokenizer.d.ts.map +1 -1
- package/dist/dts/Tool.d.ts +876 -0
- package/dist/dts/Tool.d.ts.map +1 -0
- package/dist/dts/Toolkit.d.ts +310 -0
- package/dist/dts/Toolkit.d.ts.map +1 -0
- package/dist/dts/index.d.ts +498 -13
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/AiError.js +570 -10
- package/dist/esm/AiError.js.map +1 -1
- package/dist/esm/Chat.js +291 -0
- package/dist/esm/Chat.js.map +1 -0
- package/dist/esm/EmbeddingModel.js +173 -0
- package/dist/esm/EmbeddingModel.js.map +1 -0
- package/dist/esm/IdGenerator.js +245 -0
- package/dist/esm/IdGenerator.js.map +1 -0
- package/dist/esm/LanguageModel.js +572 -0
- package/dist/esm/LanguageModel.js.map +1 -0
- package/dist/esm/McpServer.js +12 -4
- package/dist/esm/McpServer.js.map +1 -1
- package/dist/esm/Model.js +108 -0
- package/dist/esm/Model.js.map +1 -0
- package/dist/esm/Prompt.js +633 -0
- package/dist/esm/Prompt.js.map +1 -0
- package/dist/esm/Response.js +619 -0
- package/dist/esm/Response.js.map +1 -0
- package/dist/esm/Telemetry.js +166 -0
- package/dist/esm/Telemetry.js.map +1 -0
- package/dist/esm/Tokenizer.js +87 -8
- package/dist/esm/Tokenizer.js.map +1 -1
- package/dist/esm/Tool.js +534 -0
- package/dist/esm/Tool.js.map +1 -0
- package/dist/esm/Toolkit.js +269 -0
- package/dist/esm/Toolkit.js.map +1 -0
- package/dist/esm/index.js +498 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +76 -68
- package/src/AiError.ts +739 -9
- package/src/Chat.ts +546 -0
- package/src/EmbeddingModel.ts +311 -0
- package/src/IdGenerator.ts +320 -0
- package/src/LanguageModel.ts +1074 -0
- package/src/McpServer.ts +337 -194
- package/src/Model.ts +155 -0
- package/src/Prompt.ts +1616 -0
- package/src/Response.ts +2131 -0
- package/src/Telemetry.ts +655 -0
- package/src/Tokenizer.ts +145 -24
- package/src/Tool.ts +1267 -0
- package/src/Toolkit.ts +516 -0
- package/src/index.ts +499 -13
- package/AiChat/package.json +0 -6
- package/AiEmbeddingModel/package.json +0 -6
- package/AiInput/package.json +0 -6
- package/AiLanguageModel/package.json +0 -6
- package/AiModel/package.json +0 -6
- package/AiResponse/package.json +0 -6
- package/AiTelemetry/package.json +0 -6
- package/AiTool/package.json +0 -6
- package/AiToolkit/package.json +0 -6
- package/dist/cjs/AiChat.js +0 -122
- package/dist/cjs/AiChat.js.map +0 -1
- package/dist/cjs/AiEmbeddingModel.js +0 -109
- package/dist/cjs/AiEmbeddingModel.js.map +0 -1
- package/dist/cjs/AiInput.js +0 -458
- package/dist/cjs/AiInput.js.map +0 -1
- package/dist/cjs/AiLanguageModel.js +0 -351
- package/dist/cjs/AiLanguageModel.js.map +0 -1
- package/dist/cjs/AiModel.js +0 -37
- package/dist/cjs/AiModel.js.map +0 -1
- package/dist/cjs/AiResponse.js +0 -681
- package/dist/cjs/AiResponse.js.map +0 -1
- package/dist/cjs/AiTelemetry.js +0 -58
- package/dist/cjs/AiTelemetry.js.map +0 -1
- package/dist/cjs/AiTool.js +0 -150
- package/dist/cjs/AiTool.js.map +0 -1
- package/dist/cjs/AiToolkit.js +0 -157
- package/dist/cjs/AiToolkit.js.map +0 -1
- package/dist/cjs/internal/common.js +0 -21
- package/dist/cjs/internal/common.js.map +0 -1
- package/dist/dts/AiChat.d.ts +0 -101
- package/dist/dts/AiChat.d.ts.map +0 -1
- package/dist/dts/AiEmbeddingModel.d.ts +0 -65
- package/dist/dts/AiEmbeddingModel.d.ts.map +0 -1
- package/dist/dts/AiInput.d.ts +0 -590
- package/dist/dts/AiInput.d.ts.map +0 -1
- package/dist/dts/AiLanguageModel.d.ts +0 -302
- package/dist/dts/AiLanguageModel.d.ts.map +0 -1
- package/dist/dts/AiModel.d.ts +0 -25
- package/dist/dts/AiModel.d.ts.map +0 -1
- package/dist/dts/AiResponse.d.ts +0 -863
- package/dist/dts/AiResponse.d.ts.map +0 -1
- package/dist/dts/AiTelemetry.d.ts +0 -242
- package/dist/dts/AiTelemetry.d.ts.map +0 -1
- package/dist/dts/AiTool.d.ts +0 -334
- package/dist/dts/AiTool.d.ts.map +0 -1
- package/dist/dts/AiToolkit.d.ts +0 -96
- package/dist/dts/AiToolkit.d.ts.map +0 -1
- package/dist/dts/internal/common.d.ts +0 -2
- package/dist/dts/internal/common.d.ts.map +0 -1
- package/dist/esm/AiChat.js +0 -111
- package/dist/esm/AiChat.js.map +0 -1
- package/dist/esm/AiEmbeddingModel.js +0 -98
- package/dist/esm/AiEmbeddingModel.js.map +0 -1
- package/dist/esm/AiInput.js +0 -433
- package/dist/esm/AiInput.js.map +0 -1
- package/dist/esm/AiLanguageModel.js +0 -340
- package/dist/esm/AiLanguageModel.js.map +0 -1
- package/dist/esm/AiModel.js +0 -29
- package/dist/esm/AiModel.js.map +0 -1
- package/dist/esm/AiResponse.js +0 -657
- package/dist/esm/AiResponse.js.map +0 -1
- package/dist/esm/AiTelemetry.js +0 -48
- package/dist/esm/AiTelemetry.js.map +0 -1
- package/dist/esm/AiTool.js +0 -134
- package/dist/esm/AiTool.js.map +0 -1
- package/dist/esm/AiToolkit.js +0 -147
- package/dist/esm/AiToolkit.js.map +0 -1
- package/dist/esm/internal/common.js +0 -14
- package/dist/esm/internal/common.js.map +0 -1
- package/src/AiChat.ts +0 -251
- package/src/AiEmbeddingModel.ts +0 -169
- package/src/AiInput.ts +0 -602
- package/src/AiLanguageModel.ts +0 -685
- package/src/AiModel.ts +0 -53
- package/src/AiResponse.ts +0 -986
- package/src/AiTelemetry.ts +0 -333
- package/src/AiTool.ts +0 -579
- package/src/AiToolkit.ts +0 -265
- package/src/internal/common.ts +0 -12
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
import type { Span } from "effect/Tracer";
|
|
6
|
+
import type { Concurrency, NoExcessProperties } from "effect/Types";
|
|
7
|
+
import * as AiError from "./AiError.js";
|
|
8
|
+
import { IdGenerator } from "./IdGenerator.js";
|
|
9
|
+
import * as Prompt from "./Prompt.js";
|
|
10
|
+
import * as Response from "./Response.js";
|
|
11
|
+
import type * as Tool from "./Tool.js";
|
|
12
|
+
import * as Toolkit from "./Toolkit.js";
|
|
13
|
+
declare const LanguageModel_base: Context.TagClass<LanguageModel, "@effect/ai/LanguageModel", Service>;
|
|
14
|
+
/**
|
|
15
|
+
* The `LanguageModel` service tag for dependency injection.
|
|
16
|
+
*
|
|
17
|
+
* This tag provides access to language model functionality throughout your
|
|
18
|
+
* application, enabling text generation, streaming, and structured output
|
|
19
|
+
* capabilities.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { LanguageModel } from "@effect/ai"
|
|
24
|
+
* import { Effect } from "effect"
|
|
25
|
+
*
|
|
26
|
+
* const useLanguageModel = Effect.gen(function* () {
|
|
27
|
+
* const model = yield* LanguageModel
|
|
28
|
+
* const response = yield* model.generateText({
|
|
29
|
+
* prompt: "What is machine learning?"
|
|
30
|
+
* })
|
|
31
|
+
* return response.text
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
* @category Context
|
|
37
|
+
*/
|
|
38
|
+
export declare class LanguageModel extends LanguageModel_base {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The service interface for language model operations.
|
|
42
|
+
*
|
|
43
|
+
* Defines the contract that all language model implementations must fulfill,
|
|
44
|
+
* providing text generation, structured output, and streaming capabilities.
|
|
45
|
+
*
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
* @category Models
|
|
48
|
+
*/
|
|
49
|
+
export interface Service {
|
|
50
|
+
/**
|
|
51
|
+
* Generate text using the language model.
|
|
52
|
+
*/
|
|
53
|
+
readonly generateText: <Options extends NoExcessProperties<GenerateTextOptions<any>, Options>, Tools extends Record<string, Tool.Any> = {}>(options: Options & GenerateTextOptions<Tools>) => Effect.Effect<GenerateTextResponse<Tools>, ExtractError<Options>, ExtractContext<Options>>;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a structured object from a schema using the language model.
|
|
56
|
+
*/
|
|
57
|
+
readonly generateObject: <A, I extends Record<string, unknown>, R, Options extends NoExcessProperties<GenerateObjectOptions<any, A, I, R>, Options>, Tools extends Record<string, Tool.Any> = {}>(options: Options & GenerateObjectOptions<Tools, A, I, R>) => Effect.Effect<GenerateObjectResponse<Tools, A>, ExtractError<Options>, R | ExtractContext<Options>>;
|
|
58
|
+
/**
|
|
59
|
+
* Generate text using the language model with streaming output.
|
|
60
|
+
*/
|
|
61
|
+
readonly streamText: <Options extends NoExcessProperties<GenerateTextOptions<any>, Options>, Tools extends Record<string, Tool.Any> = {}>(options: Options & GenerateTextOptions<Tools>) => Stream.Stream<Response.StreamPart<Tools>, ExtractError<Options>, ExtractContext<Options>>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Configuration options for text generation.
|
|
65
|
+
*
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
* @category Models
|
|
68
|
+
*/
|
|
69
|
+
export interface GenerateTextOptions<Tools extends Record<string, Tool.Any>> {
|
|
70
|
+
/**
|
|
71
|
+
* The prompt input to use to generate text.
|
|
72
|
+
*/
|
|
73
|
+
readonly prompt: Prompt.RawInput;
|
|
74
|
+
/**
|
|
75
|
+
* A toolkit containing both the tools and the tool call handler to use to
|
|
76
|
+
* augment text generation.
|
|
77
|
+
*/
|
|
78
|
+
readonly toolkit?: Toolkit.WithHandler<Tools> | Effect.Effect<Toolkit.WithHandler<Tools>, any, any> | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The tool choice mode for the language model.
|
|
81
|
+
* - `auto` (default): The model can decide whether or not to call tools, as
|
|
82
|
+
* well as which tools to call.
|
|
83
|
+
* - `required`: The model **must** call a tool but can decide which tool will
|
|
84
|
+
* be called.
|
|
85
|
+
* - `none`: The model **must not** call a tool.
|
|
86
|
+
* - `{ tool: <tool_name> }`: The model must call the specified tool.
|
|
87
|
+
* - `{ mode?: "auto" (default) | "required", "oneOf": [<tool-names>] }`: The
|
|
88
|
+
* model is restricted to the subset of tools specified by `oneOf`. When
|
|
89
|
+
* `mode` is `"auto"` or omitted, the model can decide whether or not a tool
|
|
90
|
+
* from the allowed subset of tools can be called. When `mode` is
|
|
91
|
+
* `"required"`, the model **must** call one tool from the allowed subset of
|
|
92
|
+
* tools.
|
|
93
|
+
*/
|
|
94
|
+
readonly toolChoice?: ToolChoice<{
|
|
95
|
+
[Name in keyof Tools]: Tools[Name]["name"];
|
|
96
|
+
}[keyof Tools]> | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The concurrency level for resolving tool calls.
|
|
99
|
+
*/
|
|
100
|
+
readonly concurrency?: Concurrency | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* When set to `true`, tool calls requested by the large language model
|
|
103
|
+
* will not be auto-resolved by the framework.
|
|
104
|
+
*
|
|
105
|
+
* This option is useful when:
|
|
106
|
+
* 1. The user wants to include tool call definitions from an `AiToolkit`
|
|
107
|
+
* in requests to the large language model so that the model has the
|
|
108
|
+
* capability to call tools
|
|
109
|
+
* 2. The user wants to control the execution of tool call resolvers
|
|
110
|
+
* instead of having the framework handle tool call resolution
|
|
111
|
+
*/
|
|
112
|
+
readonly disableToolCallResolution?: boolean | undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Configuration options for structured object generation.
|
|
116
|
+
*
|
|
117
|
+
* @since 1.0.0
|
|
118
|
+
* @category Models
|
|
119
|
+
*/
|
|
120
|
+
export interface GenerateObjectOptions<Tools extends Record<string, Tool.Any>, A, I extends Record<string, unknown>, R> extends GenerateTextOptions<Tools> {
|
|
121
|
+
/**
|
|
122
|
+
* The name of the structured output that should be generated. Used by some
|
|
123
|
+
* large language model providers to provide additional guidance to the model.
|
|
124
|
+
*/
|
|
125
|
+
readonly objectName?: string | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* The schema to be used to specify the structure of the object to generate.
|
|
128
|
+
*/
|
|
129
|
+
readonly schema: Schema.Schema<A, I, R>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The tool choice mode for the language model.
|
|
133
|
+
* - `auto` (default): The model can decide whether or not to call tools, as
|
|
134
|
+
* well as which tools to call.
|
|
135
|
+
* - `required`: The model **must** call a tool but can decide which tool will
|
|
136
|
+
* be called.
|
|
137
|
+
* - `none`: The model **must not** call a tool.
|
|
138
|
+
* - `{ tool: <tool_name> }`: The model must call the specified tool.
|
|
139
|
+
* - `{ mode?: "auto" (default) | "required", "oneOf": [<tool-names>] }`: The
|
|
140
|
+
* model is restricted to the subset of tools specified by `oneOf`. When
|
|
141
|
+
* `mode` is `"auto"` or omitted, the model can decide whether or not a tool
|
|
142
|
+
* from the allowed subset of tools can be called. When `mode` is
|
|
143
|
+
* `"required"`, the model **must** call one tool from the allowed subset of
|
|
144
|
+
* tools.
|
|
145
|
+
*
|
|
146
|
+
* @since 1.0.0
|
|
147
|
+
* @category Models
|
|
148
|
+
*/
|
|
149
|
+
export type ToolChoice<Tools extends string> = "auto" | "none" | "required" | {
|
|
150
|
+
readonly tool: Tools;
|
|
151
|
+
} | {
|
|
152
|
+
readonly mode?: "auto" | "required";
|
|
153
|
+
readonly oneOf: ReadonlyArray<Tools>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Response class for text generation operations.
|
|
157
|
+
*
|
|
158
|
+
* Contains the generated content and provides convenient accessors for
|
|
159
|
+
* extracting different types of response parts like text, tool calls, and usage
|
|
160
|
+
* information.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { LanguageModel } from "@effect/ai"
|
|
165
|
+
* import { Effect } from "effect"
|
|
166
|
+
*
|
|
167
|
+
* const program = Effect.gen(function* () {
|
|
168
|
+
* const response = yield* LanguageModel.generateText({
|
|
169
|
+
* prompt: "Explain photosynthesis"
|
|
170
|
+
* })
|
|
171
|
+
*
|
|
172
|
+
* console.log(response.text) // Generated text content
|
|
173
|
+
* console.log(response.finishReason) // "stop", "length", etc.
|
|
174
|
+
* console.log(response.usage) // Usage information
|
|
175
|
+
*
|
|
176
|
+
* return response
|
|
177
|
+
* })
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @since 1.0.0
|
|
181
|
+
* @category Models
|
|
182
|
+
*/
|
|
183
|
+
export declare class GenerateTextResponse<Tools extends Record<string, Tool.Any>> {
|
|
184
|
+
readonly content: Array<Response.Part<Tools>>;
|
|
185
|
+
constructor(content: Array<Response.Part<Tools>>);
|
|
186
|
+
/**
|
|
187
|
+
* Extracts and concatenates all text parts from the response.
|
|
188
|
+
*/
|
|
189
|
+
get text(): string;
|
|
190
|
+
/**
|
|
191
|
+
* Returns all reasoning parts from the response.
|
|
192
|
+
*/
|
|
193
|
+
get reasoning(): Array<Response.ReasoningPart>;
|
|
194
|
+
/**
|
|
195
|
+
* Extracts and concatenates all reasoning text, or undefined if none exists.
|
|
196
|
+
*/
|
|
197
|
+
get reasoningText(): string | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Returns all tool call parts from the response.
|
|
200
|
+
*/
|
|
201
|
+
get toolCalls(): Array<Response.ToolCallParts<Tools>>;
|
|
202
|
+
/**
|
|
203
|
+
* Returns all tool result parts from the response.
|
|
204
|
+
*/
|
|
205
|
+
get toolResults(): Array<Response.ToolResultParts<Tools>>;
|
|
206
|
+
/**
|
|
207
|
+
* The reason why text generation finished.
|
|
208
|
+
*/
|
|
209
|
+
get finishReason(): Response.FinishReason;
|
|
210
|
+
/**
|
|
211
|
+
* Token usage statistics for the generation request.
|
|
212
|
+
*/
|
|
213
|
+
get usage(): Response.Usage;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Response class for structured object generation operations.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* import { LanguageModel } from "@effect/ai"
|
|
221
|
+
* import { Effect, Schema } from "effect"
|
|
222
|
+
*
|
|
223
|
+
* const UserSchema = Schema.Struct({
|
|
224
|
+
* name: Schema.String,
|
|
225
|
+
* email: Schema.String
|
|
226
|
+
* })
|
|
227
|
+
*
|
|
228
|
+
* const program = Effect.gen(function* () {
|
|
229
|
+
* const response = yield* LanguageModel.generateObject({
|
|
230
|
+
* prompt: "Create user: John Doe, john@example.com",
|
|
231
|
+
* schema: UserSchema
|
|
232
|
+
* })
|
|
233
|
+
*
|
|
234
|
+
* console.log(response.value) // { name: "John Doe", email: "john@example.com" }
|
|
235
|
+
* console.log(response.text) // Raw generated text
|
|
236
|
+
*
|
|
237
|
+
* return response.value
|
|
238
|
+
* })
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @since 1.0.0
|
|
242
|
+
* @category Models
|
|
243
|
+
*/
|
|
244
|
+
export declare class GenerateObjectResponse<Tools extends Record<string, Tool.Any>, A> extends GenerateTextResponse<Tools> {
|
|
245
|
+
/**
|
|
246
|
+
* The parsed structured object that conforms to the provided schema.
|
|
247
|
+
*/
|
|
248
|
+
readonly value: A;
|
|
249
|
+
constructor(value: A, content: Array<Response.Part<Tools>>);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Utility type that extracts the error type from LanguageModel options.
|
|
253
|
+
*
|
|
254
|
+
* Automatically infers the possible error types based on toolkit configuration
|
|
255
|
+
* and tool call resolution settings.
|
|
256
|
+
*
|
|
257
|
+
* @since 1.0.0
|
|
258
|
+
* @category Utility Types
|
|
259
|
+
*/
|
|
260
|
+
export type ExtractError<Options> = Options extends {
|
|
261
|
+
readonly disableToolCallResolution: true;
|
|
262
|
+
} ? Options extends {
|
|
263
|
+
readonly toolkit: Effect.Effect<Toolkit.WithHandler<infer _Tools>, infer _E, infer _R>;
|
|
264
|
+
} ? AiError.AiError | _E : AiError.AiError : Options extends {
|
|
265
|
+
readonly toolkit: Toolkit.WithHandler<infer _Tools>;
|
|
266
|
+
} ? AiError.AiError | Tool.Failure<_Tools[keyof _Tools]> : Options extends {
|
|
267
|
+
readonly toolkit: Effect.Effect<Toolkit.WithHandler<infer _Tools>, infer _E, infer _R>;
|
|
268
|
+
} ? AiError.AiError | Tool.Failure<_Tools[keyof _Tools]> | _E : AiError.AiError;
|
|
269
|
+
/**
|
|
270
|
+
* Utility type that extracts the context requirements from LanguageModel options.
|
|
271
|
+
*
|
|
272
|
+
* Automatically infers the required services based on the toolkit configuration.
|
|
273
|
+
*
|
|
274
|
+
* @since 1.0.0
|
|
275
|
+
* @category Utility Types
|
|
276
|
+
*/
|
|
277
|
+
export type ExtractContext<Options> = Options extends {
|
|
278
|
+
readonly toolkit: Toolkit.WithHandler<infer _Tools>;
|
|
279
|
+
} ? Tool.Requirements<_Tools[keyof _Tools]> : Options extends {
|
|
280
|
+
readonly toolkit: Effect.Effect<Toolkit.WithHandler<infer _Tools>, infer _E, infer _R>;
|
|
281
|
+
} ? Tool.Requirements<_Tools[keyof _Tools]> | _R : never;
|
|
282
|
+
/**
|
|
283
|
+
* Configuration options passed along to language model provider
|
|
284
|
+
* implementations.
|
|
285
|
+
*
|
|
286
|
+
* This interface defines the normalized options that are passed to the
|
|
287
|
+
* underlying provider implementation, regardless of the specific provider being
|
|
288
|
+
* used.
|
|
289
|
+
*
|
|
290
|
+
* @since 1.0.0
|
|
291
|
+
* @category Models
|
|
292
|
+
*/
|
|
293
|
+
export interface ProviderOptions {
|
|
294
|
+
/**
|
|
295
|
+
* The prompt messages to use to generate text.
|
|
296
|
+
*/
|
|
297
|
+
readonly prompt: Prompt.Prompt;
|
|
298
|
+
/**
|
|
299
|
+
* The tools that the large language model will have available to provide
|
|
300
|
+
* additional information which can be incorporated into its text generation.
|
|
301
|
+
*/
|
|
302
|
+
readonly tools: ReadonlyArray<Tool.Any>;
|
|
303
|
+
/**
|
|
304
|
+
* The format which the response should be provided in.
|
|
305
|
+
*
|
|
306
|
+
* If `"text"` is specified, the large language model response will be
|
|
307
|
+
* returned as text.
|
|
308
|
+
*
|
|
309
|
+
* If `"json"` is specified, the large language model respose will be provided
|
|
310
|
+
* as an JSON object that conforms to the shape of the specified schema.
|
|
311
|
+
*
|
|
312
|
+
* Defaults to `{ type: "text" }`.
|
|
313
|
+
*/
|
|
314
|
+
readonly responseFormat: {
|
|
315
|
+
readonly type: "text";
|
|
316
|
+
} | {
|
|
317
|
+
readonly type: "json";
|
|
318
|
+
readonly objectName: string;
|
|
319
|
+
readonly schema: Schema.Schema.Any;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* The tool choice mode for the language model.
|
|
323
|
+
* - `auto` (default): The model can decide whether or not to call tools, as
|
|
324
|
+
* well as which tools to call.
|
|
325
|
+
* - `required`: The model **must** call a tool but can decide which tool will
|
|
326
|
+
* be called.
|
|
327
|
+
* - `none`: The model **must not** call a tool.
|
|
328
|
+
* - `{ tool: <tool_name> }`: The model must call the specified tool.
|
|
329
|
+
* - `{ mode?: "auto" (default) | "required", "oneOf": [<tool-names>] }`: The
|
|
330
|
+
* model is restricted to the subset of tools specified by `oneOf`. When
|
|
331
|
+
* `mode` is `"auto"` or omitted, the model can decide whether or not a tool
|
|
332
|
+
* from the allowed subset of tools can be called. When `mode` is
|
|
333
|
+
* `"required"`, the model **must** call one tool from the allowed subset of
|
|
334
|
+
* tools.
|
|
335
|
+
*/
|
|
336
|
+
readonly toolChoice: ToolChoice<any>;
|
|
337
|
+
/**
|
|
338
|
+
* The span to use to trace interactions with the large language model.
|
|
339
|
+
*/
|
|
340
|
+
readonly span: Span;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Parameters required to construct a LanguageModel service.
|
|
344
|
+
*
|
|
345
|
+
* @since 1.0.0
|
|
346
|
+
* @category Models
|
|
347
|
+
*/
|
|
348
|
+
export interface ConstructorParams {
|
|
349
|
+
/**
|
|
350
|
+
* A method which requests text generation from the large language model
|
|
351
|
+
* provider.
|
|
352
|
+
*
|
|
353
|
+
* The final result is returned when the large language model provider
|
|
354
|
+
* finishes text generation.
|
|
355
|
+
*/
|
|
356
|
+
readonly generateText: (options: ProviderOptions) => Effect.Effect<Array<Response.PartEncoded>, AiError.AiError, IdGenerator>;
|
|
357
|
+
/**
|
|
358
|
+
* A method which requests text generation from the large language model
|
|
359
|
+
* provider.
|
|
360
|
+
*
|
|
361
|
+
* Intermediate results are streamed from the large language model provider.
|
|
362
|
+
*/
|
|
363
|
+
readonly streamText: (options: ProviderOptions) => Stream.Stream<Response.StreamPartEncoded, AiError.AiError, IdGenerator>;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Creates a LanguageModel service from provider-specific implementations.
|
|
367
|
+
*
|
|
368
|
+
* This constructor takes provider-specific implementations for text generation
|
|
369
|
+
* and streaming text generation and returns a LanguageModel service.
|
|
370
|
+
*
|
|
371
|
+
* @since 1.0.0
|
|
372
|
+
* @category Constructors
|
|
373
|
+
*/
|
|
374
|
+
export declare const make: (params: ConstructorParams) => Effect.Effect<Service>;
|
|
375
|
+
/**
|
|
376
|
+
* Generate text using a language model.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { LanguageModel } from "@effect/ai"
|
|
381
|
+
* import { Effect } from "effect"
|
|
382
|
+
*
|
|
383
|
+
* const program = Effect.gen(function* () {
|
|
384
|
+
* const response = yield* LanguageModel.generateText({
|
|
385
|
+
* prompt: "Write a haiku about programming",
|
|
386
|
+
* toolChoice: "none"
|
|
387
|
+
* })
|
|
388
|
+
*
|
|
389
|
+
* console.log(response.text)
|
|
390
|
+
* console.log(response.usage.totalTokens)
|
|
391
|
+
*
|
|
392
|
+
* return response
|
|
393
|
+
* })
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* @since 1.0.0
|
|
397
|
+
* @category Functions
|
|
398
|
+
*/
|
|
399
|
+
export declare const generateText: <Options extends NoExcessProperties<GenerateTextOptions<any>, Options>, Tools extends Record<string, Tool.Any> = {}>(options: Options & GenerateTextOptions<Tools>) => Effect.Effect<GenerateTextResponse<Tools>, ExtractError<Options>, LanguageModel | ExtractContext<Options>>;
|
|
400
|
+
/**
|
|
401
|
+
* Generate a structured object from a schema using a language model.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* import { LanguageModel } from "@effect/ai"
|
|
406
|
+
* import { Effect, Schema } from "effect"
|
|
407
|
+
*
|
|
408
|
+
* const EventSchema = Schema.Struct({
|
|
409
|
+
* title: Schema.String,
|
|
410
|
+
* date: Schema.String,
|
|
411
|
+
* location: Schema.String
|
|
412
|
+
* })
|
|
413
|
+
*
|
|
414
|
+
* const program = Effect.gen(function* () {
|
|
415
|
+
* const response = yield* LanguageModel.generateObject({
|
|
416
|
+
* prompt: "Extract event info: Tech Conference on March 15th in San Francisco",
|
|
417
|
+
* schema: EventSchema,
|
|
418
|
+
* objectName: "event"
|
|
419
|
+
* })
|
|
420
|
+
*
|
|
421
|
+
* console.log(response.value)
|
|
422
|
+
* // { title: "Tech Conference", date: "March 15th", location: "San Francisco" }
|
|
423
|
+
*
|
|
424
|
+
* return response.value
|
|
425
|
+
* })
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @since 1.0.0
|
|
429
|
+
* @category Functions
|
|
430
|
+
*/
|
|
431
|
+
export declare const generateObject: <A, I extends Record<string, unknown>, R, Options extends NoExcessProperties<GenerateObjectOptions<any, A, I, R>, Options>, Tools extends Record<string, Tool.Any> = {}>(options: Options & GenerateObjectOptions<Tools, A, I, R>) => Effect.Effect<GenerateObjectResponse<Tools, A>, ExtractError<Options>, LanguageModel | R | ExtractContext<Options>>;
|
|
432
|
+
/**
|
|
433
|
+
* Generate text using a language model with streaming output.
|
|
434
|
+
*
|
|
435
|
+
* Returns a stream of response parts that are emitted as soon as they are
|
|
436
|
+
* available from the model, enabling real-time text generation experiences.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* import { LanguageModel } from "@effect/ai"
|
|
441
|
+
* import { Effect, Stream, Console } from "effect"
|
|
442
|
+
*
|
|
443
|
+
* const program = LanguageModel.streamText({
|
|
444
|
+
* prompt: "Write a story about a space explorer"
|
|
445
|
+
* }).pipe(Stream.runForEach((part) => {
|
|
446
|
+
* if (part.type === "text-delta") {
|
|
447
|
+
* return Console.log(part.delta)
|
|
448
|
+
* }
|
|
449
|
+
* return Effect.void
|
|
450
|
+
* }))
|
|
451
|
+
* ```
|
|
452
|
+
*
|
|
453
|
+
* @since 1.0.0
|
|
454
|
+
* @category Functions
|
|
455
|
+
*/
|
|
456
|
+
export declare const streamText: <Options extends NoExcessProperties<GenerateTextOptions<any>, Options>, Tools extends Record<string, Tool.Any> = {}>(options: Options & GenerateTextOptions<Tools>) => Stream.Stream<Response.StreamPart<Tools>, ExtractError<Options>, LanguageModel | ExtractContext<Options>>;
|
|
457
|
+
export {};
|
|
458
|
+
//# sourceMappingURL=LanguageModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LanguageModel.d.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,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,CAC+C,CAAA"}
|
package/dist/dts/McpSchema.d.ts
CHANGED
|
@@ -702,12 +702,14 @@ declare const Resource_base: Schema.Class<Resource, {
|
|
|
702
702
|
*/
|
|
703
703
|
size: Schema.optional<typeof Schema.Number>;
|
|
704
704
|
}>, never, {
|
|
705
|
-
readonly description?: string | undefined;
|
|
706
|
-
} & {
|
|
707
705
|
readonly annotations?: {
|
|
708
706
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
709
707
|
readonly priority?: number | undefined;
|
|
710
708
|
} | undefined;
|
|
709
|
+
} & {
|
|
710
|
+
readonly description?: string | undefined;
|
|
711
|
+
} & {
|
|
712
|
+
readonly size?: number | undefined;
|
|
711
713
|
} & {
|
|
712
714
|
readonly name: string;
|
|
713
715
|
} & {
|
|
@@ -716,8 +718,6 @@ declare const Resource_base: Schema.Class<Resource, {
|
|
|
716
718
|
readonly uri: string;
|
|
717
719
|
} & {
|
|
718
720
|
readonly mimeType?: string | undefined;
|
|
719
|
-
} & {
|
|
720
|
-
readonly size?: number | undefined;
|
|
721
721
|
}, {}, {}>;
|
|
722
722
|
/**
|
|
723
723
|
* A known resource that the server is capable of reading.
|
|
@@ -786,12 +786,12 @@ declare const ResourceTemplate_base: Schema.Class<ResourceTemplate, {
|
|
|
786
786
|
*/
|
|
787
787
|
annotations: Schema.optional<typeof Annotations>;
|
|
788
788
|
}>, never, {
|
|
789
|
-
readonly description?: string | undefined;
|
|
790
|
-
} & {
|
|
791
789
|
readonly annotations?: {
|
|
792
790
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
793
791
|
readonly priority?: number | undefined;
|
|
794
792
|
} | undefined;
|
|
793
|
+
} & {
|
|
794
|
+
readonly description?: string | undefined;
|
|
795
795
|
} & {
|
|
796
796
|
readonly name: string;
|
|
797
797
|
} & {
|
|
@@ -1103,8 +1103,8 @@ declare const Prompt_base: Schema.Class<Prompt, {
|
|
|
1103
1103
|
readonly arguments?: readonly {
|
|
1104
1104
|
readonly description?: string | undefined;
|
|
1105
1105
|
readonly name: string;
|
|
1106
|
-
readonly title?: string | undefined;
|
|
1107
1106
|
readonly required?: boolean | undefined;
|
|
1107
|
+
readonly title?: string | undefined;
|
|
1108
1108
|
}[] | undefined;
|
|
1109
1109
|
}, {}, {}>;
|
|
1110
1110
|
/**
|
|
@@ -1294,6 +1294,10 @@ declare const GetPromptResult_base: Schema.Class<GetPromptResult, {
|
|
|
1294
1294
|
_meta: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
1295
1295
|
}>, never, {
|
|
1296
1296
|
readonly description?: string | undefined;
|
|
1297
|
+
} & {
|
|
1298
|
+
readonly _meta?: {
|
|
1299
|
+
readonly [x: string]: unknown;
|
|
1300
|
+
} | undefined;
|
|
1297
1301
|
} & {
|
|
1298
1302
|
readonly messages: readonly {
|
|
1299
1303
|
readonly role: "user" | "assistant";
|
|
@@ -1302,8 +1306,8 @@ declare const GetPromptResult_base: Schema.Class<GetPromptResult, {
|
|
|
1302
1306
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
1303
1307
|
readonly priority?: number | undefined;
|
|
1304
1308
|
} | undefined;
|
|
1305
|
-
readonly text: string;
|
|
1306
1309
|
readonly type: "text";
|
|
1310
|
+
readonly text: string;
|
|
1307
1311
|
} | {
|
|
1308
1312
|
readonly annotations?: {
|
|
1309
1313
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
@@ -1336,23 +1340,19 @@ declare const GetPromptResult_base: Schema.Class<GetPromptResult, {
|
|
|
1336
1340
|
readonly blob: Uint8Array<ArrayBufferLike>;
|
|
1337
1341
|
};
|
|
1338
1342
|
} | {
|
|
1339
|
-
readonly description?: string | undefined;
|
|
1340
1343
|
readonly annotations?: {
|
|
1341
1344
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
1342
1345
|
readonly priority?: number | undefined;
|
|
1343
1346
|
} | undefined;
|
|
1347
|
+
readonly description?: string | undefined;
|
|
1348
|
+
readonly size?: number | undefined;
|
|
1344
1349
|
readonly name: string;
|
|
1345
1350
|
readonly type: "resource_link";
|
|
1346
1351
|
readonly title?: string | undefined;
|
|
1347
1352
|
readonly uri: string;
|
|
1348
1353
|
readonly mimeType?: string | undefined;
|
|
1349
|
-
readonly size?: number | undefined;
|
|
1350
1354
|
};
|
|
1351
1355
|
}[];
|
|
1352
|
-
} & {
|
|
1353
|
-
readonly _meta?: {
|
|
1354
|
-
readonly [x: string]: unknown;
|
|
1355
|
-
} | undefined;
|
|
1356
1356
|
}, {}, {}>;
|
|
1357
1357
|
/**
|
|
1358
1358
|
* The server's response to a prompts/get request from the client.
|
|
@@ -1561,9 +1561,9 @@ declare const Tool_base: Schema.Class<Tool, {
|
|
|
1561
1561
|
*/
|
|
1562
1562
|
annotations: Schema.optional<typeof ToolAnnotations>;
|
|
1563
1563
|
}>, never, {
|
|
1564
|
-
readonly description?: string | undefined;
|
|
1565
|
-
} & {
|
|
1566
1564
|
readonly annotations?: ToolAnnotations | undefined;
|
|
1565
|
+
} & {
|
|
1566
|
+
readonly description?: string | undefined;
|
|
1567
1567
|
} & {
|
|
1568
1568
|
readonly name: string;
|
|
1569
1569
|
} & {
|
|
@@ -1634,17 +1634,13 @@ declare const CallToolResult_base: Schema.Class<CallToolResult, {
|
|
|
1634
1634
|
isError: Schema.optional<typeof Schema.Boolean>;
|
|
1635
1635
|
_meta: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
1636
1636
|
}>, never, {
|
|
1637
|
-
readonly _meta?: {
|
|
1638
|
-
readonly [x: string]: unknown;
|
|
1639
|
-
} | undefined;
|
|
1640
|
-
} & {
|
|
1641
1637
|
readonly content: readonly ({
|
|
1642
1638
|
readonly annotations?: {
|
|
1643
1639
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
1644
1640
|
readonly priority?: number | undefined;
|
|
1645
1641
|
} | undefined;
|
|
1646
|
-
readonly text: string;
|
|
1647
1642
|
readonly type: "text";
|
|
1643
|
+
readonly text: string;
|
|
1648
1644
|
} | {
|
|
1649
1645
|
readonly annotations?: {
|
|
1650
1646
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
@@ -1677,18 +1673,22 @@ declare const CallToolResult_base: Schema.Class<CallToolResult, {
|
|
|
1677
1673
|
readonly blob: Uint8Array<ArrayBufferLike>;
|
|
1678
1674
|
};
|
|
1679
1675
|
} | {
|
|
1680
|
-
readonly description?: string | undefined;
|
|
1681
1676
|
readonly annotations?: {
|
|
1682
1677
|
readonly audience?: readonly ("user" | "assistant")[] | undefined;
|
|
1683
1678
|
readonly priority?: number | undefined;
|
|
1684
1679
|
} | undefined;
|
|
1680
|
+
readonly description?: string | undefined;
|
|
1681
|
+
readonly size?: number | undefined;
|
|
1685
1682
|
readonly name: string;
|
|
1686
1683
|
readonly type: "resource_link";
|
|
1687
1684
|
readonly title?: string | undefined;
|
|
1688
1685
|
readonly uri: string;
|
|
1689
1686
|
readonly mimeType?: string | undefined;
|
|
1690
|
-
readonly size?: number | undefined;
|
|
1691
1687
|
})[];
|
|
1688
|
+
} & {
|
|
1689
|
+
readonly _meta?: {
|
|
1690
|
+
readonly [x: string]: unknown;
|
|
1691
|
+
} | undefined;
|
|
1692
1692
|
} & {
|
|
1693
1693
|
readonly structuredContent?: unknown;
|
|
1694
1694
|
} & {
|
|
@@ -2258,11 +2258,11 @@ declare const ElicitAcceptResult_base: Schema.Class<ElicitAcceptResult, {
|
|
|
2258
2258
|
content: typeof Schema.Unknown;
|
|
2259
2259
|
_meta: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
2260
2260
|
}>, never, {
|
|
2261
|
+
readonly content: unknown;
|
|
2262
|
+
} & {
|
|
2261
2263
|
readonly _meta?: {
|
|
2262
2264
|
readonly [x: string]: unknown;
|
|
2263
2265
|
} | undefined;
|
|
2264
|
-
} & {
|
|
2265
|
-
readonly content: unknown;
|
|
2266
2266
|
} & {
|
|
2267
2267
|
readonly action: "accept";
|
|
2268
2268
|
}, {}, {}>;
|
package/dist/dts/McpServer.d.ts
CHANGED
|
@@ -11,13 +11,14 @@ import * as Mailbox from "effect/Mailbox";
|
|
|
11
11
|
import * as Schema from "effect/Schema";
|
|
12
12
|
import type { Sink } from "effect/Sink";
|
|
13
13
|
import type { Stream } from "effect/Stream";
|
|
14
|
-
import * as AiTool from "./AiTool.js";
|
|
15
|
-
import type * as AiToolkit from "./AiToolkit.js";
|
|
16
14
|
import type { CallTool, Complete, GetPrompt, Param, PromptMessage, ReadResourceResult } from "./McpSchema.js";
|
|
17
15
|
import { CallToolResult, CompleteResult, ElicitationDeclined, GetPromptResult, InternalError, InvalidParams, McpServerClient, Prompt, Resource, ResourceTemplate, ServerNotificationRpcs, Tool } from "./McpSchema.js";
|
|
16
|
+
import * as AiTool from "./Tool.js";
|
|
17
|
+
import type * as Toolkit from "./Toolkit.js";
|
|
18
18
|
declare const McpServer_base: Context.TagClass<McpServer, "@effect/ai/McpServer", {
|
|
19
19
|
readonly notifications: RpcClient.RpcClient<RpcGroup.Rpcs<typeof ServerNotificationRpcs>>;
|
|
20
20
|
readonly notificationsMailbox: Mailbox.ReadonlyMailbox<RpcMessage.Request<any>>;
|
|
21
|
+
readonly initializedClients: Set<number>;
|
|
21
22
|
readonly tools: ReadonlyArray<Tool>;
|
|
22
23
|
readonly addTool: (options: {
|
|
23
24
|
readonly tool: Tool;
|
|
@@ -54,6 +55,7 @@ export declare class McpServer extends McpServer_base {
|
|
|
54
55
|
static readonly make: Effect.Effect<{
|
|
55
56
|
readonly notifications: RpcClient.RpcClient<RpcGroup.Rpcs<typeof ServerNotificationRpcs>>;
|
|
56
57
|
readonly notificationsMailbox: Mailbox.ReadonlyMailbox<RpcMessage.Request<any>>;
|
|
58
|
+
readonly initializedClients: Set<number>;
|
|
57
59
|
readonly tools: ReadonlyArray<Tool>;
|
|
58
60
|
readonly addTool: (options: {
|
|
59
61
|
readonly tool: Tool;
|
|
@@ -246,14 +248,14 @@ export declare const layerHttpRouter: (options: {
|
|
|
246
248
|
* @since 1.0.0
|
|
247
249
|
* @category Tools
|
|
248
250
|
*/
|
|
249
|
-
export declare const registerToolkit: <Tools extends AiTool.Any
|
|
251
|
+
export declare const registerToolkit: <Tools extends Record<string, AiTool.Any>>(toolkit: Toolkit.Toolkit<Tools>) => Effect.Effect<void, never, McpServer | AiTool.HandlersFor<Tools> | Exclude<AiTool.Requirements<Tools>, McpServerClient>>;
|
|
250
252
|
/**
|
|
251
253
|
* Register an AiToolkit with the McpServer.
|
|
252
254
|
*
|
|
253
255
|
* @since 1.0.0
|
|
254
256
|
* @category Tools
|
|
255
257
|
*/
|
|
256
|
-
export declare const toolkit: <Tools extends AiTool.Any
|
|
258
|
+
export declare const toolkit: <Tools extends Record<string, AiTool.Any>>(toolkit: Toolkit.Toolkit<Tools>) => Layer.Layer<never, never, AiTool.HandlersFor<Tools> | Exclude<AiTool.Requirements<Tools>, McpServerClient>>;
|
|
257
259
|
/**
|
|
258
260
|
* @since 1.0.0
|
|
259
261
|
*/
|