@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,584 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.streamText = exports.make = exports.generateText = exports.generateObject = exports.LanguageModel = exports.GenerateTextResponse = exports.GenerateObjectResponse = void 0;
|
|
7
|
+
var Chunk = _interopRequireWildcard(require("effect/Chunk"));
|
|
8
|
+
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
9
|
+
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
10
|
+
var Option = _interopRequireWildcard(require("effect/Option"));
|
|
11
|
+
var ParseResult = _interopRequireWildcard(require("effect/ParseResult"));
|
|
12
|
+
var Predicate = _interopRequireWildcard(require("effect/Predicate"));
|
|
13
|
+
var Schema = _interopRequireWildcard(require("effect/Schema"));
|
|
14
|
+
var Stream = _interopRequireWildcard(require("effect/Stream"));
|
|
15
|
+
var AiError = _interopRequireWildcard(require("./AiError.js"));
|
|
16
|
+
var _IdGenerator = require("./IdGenerator.js");
|
|
17
|
+
var Prompt = _interopRequireWildcard(require("./Prompt.js"));
|
|
18
|
+
var Response = _interopRequireWildcard(require("./Response.js"));
|
|
19
|
+
var _Telemetry = require("./Telemetry.js");
|
|
20
|
+
var Toolkit = _interopRequireWildcard(require("./Toolkit.js"));
|
|
21
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
22
|
+
/**
|
|
23
|
+
* The `LanguageModel` module provides AI text generation capabilities with tool
|
|
24
|
+
* calling support.
|
|
25
|
+
*
|
|
26
|
+
* This module offers a comprehensive interface for interacting with large
|
|
27
|
+
* language models, supporting both streaming and non-streaming text generation,
|
|
28
|
+
* structured output generation, and tool calling functionality. It provides a
|
|
29
|
+
* unified API that can be implemented by different AI providers while
|
|
30
|
+
* maintaining type safety and effect management.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { LanguageModel } from "@effect/ai"
|
|
35
|
+
* import { Effect } from "effect"
|
|
36
|
+
*
|
|
37
|
+
* // Basic text generation
|
|
38
|
+
* const program = Effect.gen(function* () {
|
|
39
|
+
* const response = yield* LanguageModel.generateText({
|
|
40
|
+
* prompt: "Explain quantum computing"
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* console.log(response.text)
|
|
44
|
+
*
|
|
45
|
+
* return response
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { LanguageModel } from "@effect/ai"
|
|
52
|
+
* import { Effect, Schema } from "effect"
|
|
53
|
+
*
|
|
54
|
+
* // Structured output generation
|
|
55
|
+
* const ContactSchema = Schema.Struct({
|
|
56
|
+
* name: Schema.String,
|
|
57
|
+
* email: Schema.String
|
|
58
|
+
* })
|
|
59
|
+
*
|
|
60
|
+
* const extractContact = Effect.gen(function* () {
|
|
61
|
+
* const response = yield* LanguageModel.generateObject({
|
|
62
|
+
* prompt: "Extract contact: John Doe, john@example.com",
|
|
63
|
+
* schema: ContactSchema
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* return response.value
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @since 1.0.0
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
// =============================================================================
|
|
74
|
+
// Service Definition
|
|
75
|
+
// =============================================================================
|
|
76
|
+
/**
|
|
77
|
+
* The `LanguageModel` service tag for dependency injection.
|
|
78
|
+
*
|
|
79
|
+
* This tag provides access to language model functionality throughout your
|
|
80
|
+
* application, enabling text generation, streaming, and structured output
|
|
81
|
+
* capabilities.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { LanguageModel } from "@effect/ai"
|
|
86
|
+
* import { Effect } from "effect"
|
|
87
|
+
*
|
|
88
|
+
* const useLanguageModel = Effect.gen(function* () {
|
|
89
|
+
* const model = yield* LanguageModel
|
|
90
|
+
* const response = yield* model.generateText({
|
|
91
|
+
* prompt: "What is machine learning?"
|
|
92
|
+
* })
|
|
93
|
+
* return response.text
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @since 1.0.0
|
|
98
|
+
* @category Context
|
|
99
|
+
*/
|
|
100
|
+
class LanguageModel extends /*#__PURE__*/Context.Tag("@effect/ai/LanguageModel")() {}
|
|
101
|
+
/**
|
|
102
|
+
* Response class for text generation operations.
|
|
103
|
+
*
|
|
104
|
+
* Contains the generated content and provides convenient accessors for
|
|
105
|
+
* extracting different types of response parts like text, tool calls, and usage
|
|
106
|
+
* information.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { LanguageModel } from "@effect/ai"
|
|
111
|
+
* import { Effect } from "effect"
|
|
112
|
+
*
|
|
113
|
+
* const program = Effect.gen(function* () {
|
|
114
|
+
* const response = yield* LanguageModel.generateText({
|
|
115
|
+
* prompt: "Explain photosynthesis"
|
|
116
|
+
* })
|
|
117
|
+
*
|
|
118
|
+
* console.log(response.text) // Generated text content
|
|
119
|
+
* console.log(response.finishReason) // "stop", "length", etc.
|
|
120
|
+
* console.log(response.usage) // Usage information
|
|
121
|
+
*
|
|
122
|
+
* return response
|
|
123
|
+
* })
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
* @category Models
|
|
128
|
+
*/
|
|
129
|
+
exports.LanguageModel = LanguageModel;
|
|
130
|
+
class GenerateTextResponse {
|
|
131
|
+
content;
|
|
132
|
+
constructor(content) {
|
|
133
|
+
this.content = content;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Extracts and concatenates all text parts from the response.
|
|
137
|
+
*/
|
|
138
|
+
get text() {
|
|
139
|
+
const text = [];
|
|
140
|
+
for (const part of this.content) {
|
|
141
|
+
if (part.type === "text") {
|
|
142
|
+
text.push(part.text);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return text.join("");
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns all reasoning parts from the response.
|
|
149
|
+
*/
|
|
150
|
+
get reasoning() {
|
|
151
|
+
return this.content.filter(part => part.type === "reasoning");
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Extracts and concatenates all reasoning text, or undefined if none exists.
|
|
155
|
+
*/
|
|
156
|
+
get reasoningText() {
|
|
157
|
+
const text = [];
|
|
158
|
+
for (const part of this.content) {
|
|
159
|
+
if (part.type === "reasoning") {
|
|
160
|
+
text.push(part.text);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return text.length === 0 ? undefined : text.join("");
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns all tool call parts from the response.
|
|
167
|
+
*/
|
|
168
|
+
get toolCalls() {
|
|
169
|
+
return this.content.filter(part => part.type === "tool-call");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns all tool result parts from the response.
|
|
173
|
+
*/
|
|
174
|
+
get toolResults() {
|
|
175
|
+
return this.content.filter(part => part.type === "tool-result");
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The reason why text generation finished.
|
|
179
|
+
*/
|
|
180
|
+
get finishReason() {
|
|
181
|
+
const finishPart = this.content.find(part => part.type === "finish");
|
|
182
|
+
return Predicate.isUndefined(finishPart) ? "unknown" : finishPart.reason;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Token usage statistics for the generation request.
|
|
186
|
+
*/
|
|
187
|
+
get usage() {
|
|
188
|
+
const finishPart = this.content.find(part => part.type === "finish");
|
|
189
|
+
if (Predicate.isUndefined(finishPart)) {
|
|
190
|
+
return new Response.Usage({
|
|
191
|
+
inputTokens: undefined,
|
|
192
|
+
outputTokens: undefined,
|
|
193
|
+
totalTokens: undefined,
|
|
194
|
+
reasoningTokens: undefined,
|
|
195
|
+
cachedInputTokens: undefined
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return finishPart.usage;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Response class for structured object generation operations.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* import { LanguageModel } from "@effect/ai"
|
|
207
|
+
* import { Effect, Schema } from "effect"
|
|
208
|
+
*
|
|
209
|
+
* const UserSchema = Schema.Struct({
|
|
210
|
+
* name: Schema.String,
|
|
211
|
+
* email: Schema.String
|
|
212
|
+
* })
|
|
213
|
+
*
|
|
214
|
+
* const program = Effect.gen(function* () {
|
|
215
|
+
* const response = yield* LanguageModel.generateObject({
|
|
216
|
+
* prompt: "Create user: John Doe, john@example.com",
|
|
217
|
+
* schema: UserSchema
|
|
218
|
+
* })
|
|
219
|
+
*
|
|
220
|
+
* console.log(response.value) // { name: "John Doe", email: "john@example.com" }
|
|
221
|
+
* console.log(response.text) // Raw generated text
|
|
222
|
+
*
|
|
223
|
+
* return response.value
|
|
224
|
+
* })
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @since 1.0.0
|
|
228
|
+
* @category Models
|
|
229
|
+
*/
|
|
230
|
+
exports.GenerateTextResponse = GenerateTextResponse;
|
|
231
|
+
class GenerateObjectResponse extends GenerateTextResponse {
|
|
232
|
+
/**
|
|
233
|
+
* The parsed structured object that conforms to the provided schema.
|
|
234
|
+
*/
|
|
235
|
+
value;
|
|
236
|
+
constructor(value, content) {
|
|
237
|
+
super(content);
|
|
238
|
+
this.value = value;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Creates a LanguageModel service from provider-specific implementations.
|
|
243
|
+
*
|
|
244
|
+
* This constructor takes provider-specific implementations for text generation
|
|
245
|
+
* and streaming text generation and returns a LanguageModel service.
|
|
246
|
+
*
|
|
247
|
+
* @since 1.0.0
|
|
248
|
+
* @category Constructors
|
|
249
|
+
*/
|
|
250
|
+
exports.GenerateObjectResponse = GenerateObjectResponse;
|
|
251
|
+
const make = exports.make = /*#__PURE__*/Effect.fnUntraced(function* (params) {
|
|
252
|
+
const parentSpanTransformer = yield* Effect.serviceOption(_Telemetry.CurrentSpanTransformer);
|
|
253
|
+
const getSpanTransformer = Effect.serviceOption(_Telemetry.CurrentSpanTransformer).pipe(Effect.map(Option.orElse(() => parentSpanTransformer)));
|
|
254
|
+
const idGenerator = yield* Effect.serviceOption(_IdGenerator.IdGenerator).pipe(Effect.map(Option.getOrElse(() => _IdGenerator.defaultIdGenerator)));
|
|
255
|
+
const generateText = options => Effect.useSpan("LanguageModel.generateText", {
|
|
256
|
+
captureStackTrace: false,
|
|
257
|
+
attributes: {
|
|
258
|
+
concurrency: options.concurrency,
|
|
259
|
+
toolChoice: options.toolChoice
|
|
260
|
+
}
|
|
261
|
+
}, Effect.fnUntraced(function* (span) {
|
|
262
|
+
const spanTransformer = yield* getSpanTransformer;
|
|
263
|
+
const providerOptions = {
|
|
264
|
+
prompt: Prompt.make(options.prompt),
|
|
265
|
+
tools: [],
|
|
266
|
+
toolChoice: "none",
|
|
267
|
+
responseFormat: {
|
|
268
|
+
type: "text"
|
|
269
|
+
},
|
|
270
|
+
span
|
|
271
|
+
};
|
|
272
|
+
const content = yield* generateContent(options, providerOptions);
|
|
273
|
+
applySpanTransformer(spanTransformer, content, providerOptions);
|
|
274
|
+
return new GenerateTextResponse(content);
|
|
275
|
+
}, Effect.catchTag("ParseError", error => AiError.MalformedOutput.fromParseError({
|
|
276
|
+
module: "LanguageModel",
|
|
277
|
+
method: "generateText",
|
|
278
|
+
error
|
|
279
|
+
})), (effect, span) => Effect.withParentSpan(effect, span), Effect.provideService(_IdGenerator.IdGenerator, idGenerator)));
|
|
280
|
+
const generateObject = options => {
|
|
281
|
+
const schema = options.schema;
|
|
282
|
+
const objectName = getObjectName(options.objectName, schema);
|
|
283
|
+
return Effect.useSpan("LanguageModel.generateObject", {
|
|
284
|
+
captureStackTrace: false,
|
|
285
|
+
attributes: {
|
|
286
|
+
objectName,
|
|
287
|
+
concurrency: options.concurrency,
|
|
288
|
+
toolChoice: options.toolChoice
|
|
289
|
+
}
|
|
290
|
+
}, Effect.fnUntraced(function* (span) {
|
|
291
|
+
const spanTransformer = yield* getSpanTransformer;
|
|
292
|
+
const providerOptions = {
|
|
293
|
+
prompt: Prompt.make(options.prompt),
|
|
294
|
+
tools: [],
|
|
295
|
+
toolChoice: "none",
|
|
296
|
+
responseFormat: {
|
|
297
|
+
type: "json",
|
|
298
|
+
objectName,
|
|
299
|
+
schema
|
|
300
|
+
},
|
|
301
|
+
span
|
|
302
|
+
};
|
|
303
|
+
const content = yield* generateContent(options, providerOptions);
|
|
304
|
+
applySpanTransformer(spanTransformer, content, providerOptions);
|
|
305
|
+
const value = yield* resolveStructuredOutput(content, schema);
|
|
306
|
+
return new GenerateObjectResponse(value, content);
|
|
307
|
+
}, Effect.catchTag("ParseError", error => AiError.MalformedOutput.fromParseError({
|
|
308
|
+
module: "LanguageModel",
|
|
309
|
+
method: "generateText",
|
|
310
|
+
error
|
|
311
|
+
})), (effect, span) => Effect.withParentSpan(effect, span), Effect.provideService(_IdGenerator.IdGenerator, idGenerator)));
|
|
312
|
+
};
|
|
313
|
+
const streamText = Effect.fnUntraced(function* (options) {
|
|
314
|
+
const span = yield* Effect.makeSpanScoped("LanguageModel.streamText", {
|
|
315
|
+
captureStackTrace: false,
|
|
316
|
+
attributes: {
|
|
317
|
+
concurrency: options.concurrency,
|
|
318
|
+
toolChoice: options.toolChoice
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
const providerOptions = {
|
|
322
|
+
prompt: Prompt.make(options.prompt),
|
|
323
|
+
tools: [],
|
|
324
|
+
toolChoice: "none",
|
|
325
|
+
responseFormat: {
|
|
326
|
+
type: "text"
|
|
327
|
+
},
|
|
328
|
+
span
|
|
329
|
+
};
|
|
330
|
+
// Resolve the content stream for the request
|
|
331
|
+
const stream = yield* streamContent(options, providerOptions);
|
|
332
|
+
// Return the stream immediately if there is no span transformer
|
|
333
|
+
const spanTransformer = yield* getSpanTransformer;
|
|
334
|
+
if (Option.isNone(spanTransformer)) {
|
|
335
|
+
return stream;
|
|
336
|
+
}
|
|
337
|
+
// Otherwise aggregate generated content and apply the span transformer
|
|
338
|
+
// when the stream is finished
|
|
339
|
+
let content = [];
|
|
340
|
+
return stream.pipe(Stream.mapChunks(chunk => {
|
|
341
|
+
content = [...content, ...chunk];
|
|
342
|
+
return chunk;
|
|
343
|
+
}), Stream.ensuring(Effect.sync(() => {
|
|
344
|
+
spanTransformer.value({
|
|
345
|
+
...providerOptions,
|
|
346
|
+
response: content
|
|
347
|
+
});
|
|
348
|
+
})));
|
|
349
|
+
}, Stream.unwrapScoped, Stream.mapError(error => ParseResult.isParseError(error) ? AiError.MalformedOutput.fromParseError({
|
|
350
|
+
module: "LanguageModel",
|
|
351
|
+
method: "streamText",
|
|
352
|
+
error
|
|
353
|
+
}) : error), Stream.provideService(_IdGenerator.IdGenerator, idGenerator));
|
|
354
|
+
const generateContent = Effect.fnUntraced(function* (options, providerOptions) {
|
|
355
|
+
const toolChoice = options.toolChoice ?? "auto";
|
|
356
|
+
// If there is no toolkit, the generated content can be returned immediately
|
|
357
|
+
if (Predicate.isUndefined(options.toolkit)) {
|
|
358
|
+
const ResponseSchema = Schema.mutable(Schema.Array(Response.Part(Toolkit.empty)));
|
|
359
|
+
const rawContent = yield* params.generateText(providerOptions);
|
|
360
|
+
const content = yield* Schema.decodeUnknown(ResponseSchema)(rawContent);
|
|
361
|
+
return content;
|
|
362
|
+
}
|
|
363
|
+
// If there is a toolkit resolve and apply it to the provider options
|
|
364
|
+
const toolkit = yield* resolveToolkit(options.toolkit);
|
|
365
|
+
// If the resolved toolkit is empty, return the generated content immediately
|
|
366
|
+
if (Object.values(toolkit.tools).length === 0) {
|
|
367
|
+
const ResponseSchema = Schema.mutable(Schema.Array(Response.Part(Toolkit.empty)));
|
|
368
|
+
const rawContent = yield* params.generateText(providerOptions);
|
|
369
|
+
const content = yield* Schema.decodeUnknown(ResponseSchema)(rawContent);
|
|
370
|
+
return content;
|
|
371
|
+
}
|
|
372
|
+
const tools = typeof toolChoice === "object" && "oneOf" in toolChoice ? Object.values(toolkit.tools).filter(tool => toolChoice.oneOf.includes(tool.name)) : Object.values(toolkit.tools);
|
|
373
|
+
providerOptions.tools = tools;
|
|
374
|
+
providerOptions.toolChoice = toolChoice;
|
|
375
|
+
// If tool call resolution is disabled, return the response without
|
|
376
|
+
// resolving the tool calls that were generated
|
|
377
|
+
if (options.disableToolCallResolution === true) {
|
|
378
|
+
const ResponseSchema = Schema.mutable(Schema.Array(Response.Part(Toolkit.empty)));
|
|
379
|
+
const rawContent = yield* params.generateText(providerOptions);
|
|
380
|
+
const content = yield* Schema.decodeUnknown(ResponseSchema)(rawContent);
|
|
381
|
+
return content;
|
|
382
|
+
}
|
|
383
|
+
const rawContent = yield* params.generateText(providerOptions);
|
|
384
|
+
// Resolve the generated tool calls
|
|
385
|
+
const toolResults = yield* resolveToolCalls(rawContent, toolkit, options.concurrency);
|
|
386
|
+
const ResponseSchema = Schema.mutable(Schema.Array(Response.Part(toolkit)));
|
|
387
|
+
const content = yield* Schema.decodeUnknown(ResponseSchema)(rawContent);
|
|
388
|
+
// Return the content merged with the tool call results
|
|
389
|
+
return [...content, ...toolResults];
|
|
390
|
+
});
|
|
391
|
+
const streamContent = Effect.fnUntraced(function* (options, providerOptions) {
|
|
392
|
+
const toolChoice = options.toolChoice ?? "auto";
|
|
393
|
+
// If there is no toolkit, return immediately
|
|
394
|
+
if (Predicate.isUndefined(options.toolkit)) {
|
|
395
|
+
const schema = Schema.ChunkFromSelf(Response.StreamPart(Toolkit.empty));
|
|
396
|
+
const decode = Schema.decode(schema);
|
|
397
|
+
return params.streamText(providerOptions).pipe(Stream.mapChunksEffect(decode));
|
|
398
|
+
}
|
|
399
|
+
// If there is a toolkit resolve and apply it to the provider options
|
|
400
|
+
const toolkit = Effect.isEffect(options.toolkit) ? yield* options.toolkit : options.toolkit;
|
|
401
|
+
// If the toolkit is empty, return immediately
|
|
402
|
+
if (Object.values(toolkit.tools).length === 0) {
|
|
403
|
+
const schema = Schema.ChunkFromSelf(Response.StreamPart(Toolkit.empty));
|
|
404
|
+
const decode = Schema.decode(schema);
|
|
405
|
+
return params.streamText(providerOptions).pipe(Stream.mapChunksEffect(decode));
|
|
406
|
+
}
|
|
407
|
+
const tools = typeof toolChoice === "object" && "oneOf" in toolChoice ? Object.values(toolkit.tools).filter(tool => toolChoice.oneOf.includes(tool.name)) : Object.values(toolkit.tools);
|
|
408
|
+
providerOptions.tools = tools;
|
|
409
|
+
providerOptions.toolChoice = toolChoice;
|
|
410
|
+
// If tool call resolution is disabled, return the response without
|
|
411
|
+
// resolving the tool calls that were generated
|
|
412
|
+
if (options.disableToolCallResolution === true) {
|
|
413
|
+
const schema = Schema.ChunkFromSelf(Response.StreamPart(toolkit));
|
|
414
|
+
const decode = Schema.decode(schema);
|
|
415
|
+
return params.streamText(providerOptions).pipe(Stream.mapChunksEffect(decode));
|
|
416
|
+
}
|
|
417
|
+
const ResponseSchema = Schema.Chunk(Response.StreamPart(toolkit));
|
|
418
|
+
const decode = Schema.decode(ResponseSchema);
|
|
419
|
+
return params.streamText(providerOptions).pipe(Stream.mapChunksEffect(Effect.fnUntraced(function* (chunk) {
|
|
420
|
+
const rawContent = Chunk.toArray(chunk);
|
|
421
|
+
const toolResults = yield* resolveToolCalls(rawContent, toolkit, options.concurrency);
|
|
422
|
+
const content = yield* decode(rawContent);
|
|
423
|
+
return Chunk.unsafeFromArray([...content, ...toolResults]);
|
|
424
|
+
})));
|
|
425
|
+
});
|
|
426
|
+
return {
|
|
427
|
+
generateText,
|
|
428
|
+
generateObject,
|
|
429
|
+
streamText
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
// =============================================================================
|
|
433
|
+
// Accessors
|
|
434
|
+
// =============================================================================
|
|
435
|
+
/**
|
|
436
|
+
* Generate text using a language model.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* import { LanguageModel } from "@effect/ai"
|
|
441
|
+
* import { Effect } from "effect"
|
|
442
|
+
*
|
|
443
|
+
* const program = Effect.gen(function* () {
|
|
444
|
+
* const response = yield* LanguageModel.generateText({
|
|
445
|
+
* prompt: "Write a haiku about programming",
|
|
446
|
+
* toolChoice: "none"
|
|
447
|
+
* })
|
|
448
|
+
*
|
|
449
|
+
* console.log(response.text)
|
|
450
|
+
* console.log(response.usage.totalTokens)
|
|
451
|
+
*
|
|
452
|
+
* return response
|
|
453
|
+
* })
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
456
|
+
* @since 1.0.0
|
|
457
|
+
* @category Functions
|
|
458
|
+
*/
|
|
459
|
+
const generateText = exports.generateText = /*#__PURE__*/Effect.serviceFunctionEffect(LanguageModel, model => model.generateText);
|
|
460
|
+
/**
|
|
461
|
+
* Generate a structured object from a schema using a language model.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```ts
|
|
465
|
+
* import { LanguageModel } from "@effect/ai"
|
|
466
|
+
* import { Effect, Schema } from "effect"
|
|
467
|
+
*
|
|
468
|
+
* const EventSchema = Schema.Struct({
|
|
469
|
+
* title: Schema.String,
|
|
470
|
+
* date: Schema.String,
|
|
471
|
+
* location: Schema.String
|
|
472
|
+
* })
|
|
473
|
+
*
|
|
474
|
+
* const program = Effect.gen(function* () {
|
|
475
|
+
* const response = yield* LanguageModel.generateObject({
|
|
476
|
+
* prompt: "Extract event info: Tech Conference on March 15th in San Francisco",
|
|
477
|
+
* schema: EventSchema,
|
|
478
|
+
* objectName: "event"
|
|
479
|
+
* })
|
|
480
|
+
*
|
|
481
|
+
* console.log(response.value)
|
|
482
|
+
* // { title: "Tech Conference", date: "March 15th", location: "San Francisco" }
|
|
483
|
+
*
|
|
484
|
+
* return response.value
|
|
485
|
+
* })
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @since 1.0.0
|
|
489
|
+
* @category Functions
|
|
490
|
+
*/
|
|
491
|
+
const generateObject = exports.generateObject = /*#__PURE__*/Effect.serviceFunctionEffect(LanguageModel, model => model.generateObject);
|
|
492
|
+
/**
|
|
493
|
+
* Generate text using a language model with streaming output.
|
|
494
|
+
*
|
|
495
|
+
* Returns a stream of response parts that are emitted as soon as they are
|
|
496
|
+
* available from the model, enabling real-time text generation experiences.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* import { LanguageModel } from "@effect/ai"
|
|
501
|
+
* import { Effect, Stream, Console } from "effect"
|
|
502
|
+
*
|
|
503
|
+
* const program = LanguageModel.streamText({
|
|
504
|
+
* prompt: "Write a story about a space explorer"
|
|
505
|
+
* }).pipe(Stream.runForEach((part) => {
|
|
506
|
+
* if (part.type === "text-delta") {
|
|
507
|
+
* return Console.log(part.delta)
|
|
508
|
+
* }
|
|
509
|
+
* return Effect.void
|
|
510
|
+
* }))
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* @since 1.0.0
|
|
514
|
+
* @category Functions
|
|
515
|
+
*/
|
|
516
|
+
const streamText = options => Stream.unwrap(LanguageModel.pipe(Effect.map(model => model.streamText(options))));
|
|
517
|
+
// =============================================================================
|
|
518
|
+
// Tool Call Resolution
|
|
519
|
+
// =============================================================================
|
|
520
|
+
exports.streamText = streamText;
|
|
521
|
+
const resolveToolCalls = (content, toolkit, concurrency) => {
|
|
522
|
+
const toolNames = [];
|
|
523
|
+
const toolCalls = [];
|
|
524
|
+
for (const part of content) {
|
|
525
|
+
if (part.type === "tool-call") {
|
|
526
|
+
toolNames.push(part.name);
|
|
527
|
+
if (part.providerExecuted === true) {
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
toolCalls.push(part);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return Effect.forEach(toolCalls, toolCall => {
|
|
534
|
+
return toolkit.handle(toolCall.name, toolCall.params).pipe(Effect.map(({
|
|
535
|
+
encodedResult,
|
|
536
|
+
result
|
|
537
|
+
}) => Response.makePart("tool-result", {
|
|
538
|
+
id: toolCall.id,
|
|
539
|
+
name: toolCall.name,
|
|
540
|
+
result,
|
|
541
|
+
encodedResult,
|
|
542
|
+
providerName: toolCall.providerName,
|
|
543
|
+
providerExecuted: false
|
|
544
|
+
})));
|
|
545
|
+
}, {
|
|
546
|
+
concurrency
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
// =============================================================================
|
|
550
|
+
// Utilities
|
|
551
|
+
// =============================================================================
|
|
552
|
+
const resolveToolkit = toolkit => Effect.isEffect(toolkit) ? toolkit : Effect.succeed(toolkit);
|
|
553
|
+
const getObjectName = (objectName, schema) => Predicate.isNotUndefined(objectName) ? objectName : "_tag" in schema ? schema._tag : "identifier" in schema ? schema.identifier : "generateObject";
|
|
554
|
+
const resolveStructuredOutput = /*#__PURE__*/Effect.fnUntraced(function* (response, ResultSchema) {
|
|
555
|
+
const text = [];
|
|
556
|
+
for (const part of response) {
|
|
557
|
+
if (part.type === "text") {
|
|
558
|
+
text.push(part.text);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (text.length === 0) {
|
|
562
|
+
return yield* new AiError.MalformedOutput({
|
|
563
|
+
module: "LanguageModel",
|
|
564
|
+
method: "generateObject",
|
|
565
|
+
description: "No object was generated by the large language model"
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
const decode = Schema.decode(Schema.parseJson(ResultSchema));
|
|
569
|
+
return yield* Effect.mapError(decode(text.join("")), cause => new AiError.MalformedOutput({
|
|
570
|
+
module: "LanguageModel",
|
|
571
|
+
method: "generateObject",
|
|
572
|
+
description: "Generated object failed to conform to provided schema",
|
|
573
|
+
cause
|
|
574
|
+
}));
|
|
575
|
+
});
|
|
576
|
+
const applySpanTransformer = (transformer, response, options) => {
|
|
577
|
+
if (Option.isSome(transformer)) {
|
|
578
|
+
transformer.value({
|
|
579
|
+
...options,
|
|
580
|
+
response: response
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
//# sourceMappingURL=LanguageModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LanguageModel.js","names":["Chunk","_interopRequireWildcard","require","Context","Effect","Option","ParseResult","Predicate","Schema","Stream","AiError","_IdGenerator","Prompt","Response","_Telemetry","Toolkit","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","LanguageModel","Tag","exports","GenerateTextResponse","content","constructor","text","part","type","push","join","reasoning","filter","reasoningText","length","undefined","toolCalls","toolResults","finishReason","finishPart","find","isUndefined","reason","usage","Usage","inputTokens","outputTokens","totalTokens","reasoningTokens","cachedInputTokens","GenerateObjectResponse","value","make","fnUntraced","params","parentSpanTransformer","serviceOption","CurrentSpanTransformer","getSpanTransformer","pipe","map","orElse","idGenerator","IdGenerator","getOrElse","defaultIdGenerator","generateText","options","useSpan","captureStackTrace","attributes","concurrency","toolChoice","span","spanTransformer","providerOptions","prompt","tools","responseFormat","generateContent","applySpanTransformer","catchTag","error","MalformedOutput","fromParseError","module","method","effect","withParentSpan","provideService","generateObject","schema","objectName","getObjectName","resolveStructuredOutput","streamText","makeSpanScoped","stream","streamContent","isNone","mapChunks","chunk","ensuring","sync","response","unwrapScoped","mapError","isParseError","toolkit","ResponseSchema","mutable","Array","Part","empty","rawContent","decodeUnknown","resolveToolkit","values","tool","oneOf","includes","name","disableToolCallResolution","resolveToolCalls","ChunkFromSelf","StreamPart","decode","mapChunksEffect","isEffect","toArray","unsafeFromArray","serviceFunctionEffect","model","unwrap","toolNames","providerExecuted","forEach","toolCall","handle","encodedResult","result","makePart","id","providerName","succeed","isNotUndefined","_tag","identifier","ResultSchema","description","parseJson","cause","transformer","isSome"],"sources":["../../src/LanguageModel.ts"],"sourcesContent":[null],"mappings":";;;;;;AAkDA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,MAAA,GAAAP,uBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,uBAAA,CAAAC,OAAA;AAGA,IAAAQ,OAAA,GAAAT,uBAAA,CAAAC,OAAA;AACA,IAAAS,YAAA,GAAAT,OAAA;AACA,IAAAU,MAAA,GAAAX,uBAAA,CAAAC,OAAA;AACA,IAAAW,QAAA,GAAAZ,uBAAA,CAAAC,OAAA;AAEA,IAAAY,UAAA,GAAAZ,OAAA;AAEA,IAAAa,OAAA,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Schema = _interopRequireWildcard(require("effect/Schema"));
|
|
23
23
|
var AST = _interopRequireWildcard(require("effect/SchemaAST"));
|
|
24
24
|
var FindMyWay = _interopRequireWildcard(require("find-my-way-ts"));
|
|
25
|
-
var AiTool = _interopRequireWildcard(require("./AiTool.js"));
|
|
26
25
|
var _McpSchema = require("./McpSchema.js");
|
|
26
|
+
var AiTool = _interopRequireWildcard(require("./Tool.js"));
|
|
27
27
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
28
28
|
/**
|
|
29
29
|
* @since 1.0.0
|
|
@@ -76,6 +76,7 @@ class McpServer extends /*#__PURE__*/Context.Tag("@effect/ai/McpServer")() {
|
|
|
76
76
|
return McpServer.of({
|
|
77
77
|
notifications: notifications.client,
|
|
78
78
|
notificationsMailbox,
|
|
79
|
+
initializedClients: new Set(),
|
|
79
80
|
get tools() {
|
|
80
81
|
return tools;
|
|
81
82
|
},
|
|
@@ -268,7 +269,11 @@ const run = exports.run = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
|
268
269
|
payload: encoded
|
|
269
270
|
};
|
|
270
271
|
const clientIds = yield* patchedProtocol.clientIds;
|
|
271
|
-
for (const clientId of
|
|
272
|
+
for (const clientId of server.initializedClients) {
|
|
273
|
+
if (!clientIds.has(clientId)) {
|
|
274
|
+
server.initializedClients.delete(clientId);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
272
277
|
yield* patchedProtocol.send(clientId, message);
|
|
273
278
|
}
|
|
274
279
|
})), Effect.catchAllCause(() => Effect.void), Effect.forever, Effect.forkScoped);
|
|
@@ -427,7 +432,7 @@ const registerToolkit = exports.registerToolkit = /*#__PURE__*/Effect.fnUntraced
|
|
|
427
432
|
const registry = yield* McpServer;
|
|
428
433
|
const built = yield* toolkit;
|
|
429
434
|
const context = yield* Effect.context();
|
|
430
|
-
for (const tool of built.tools) {
|
|
435
|
+
for (const tool of Object.values(built.tools)) {
|
|
431
436
|
const mcpTool = new _McpSchema.Tool({
|
|
432
437
|
name: tool.name,
|
|
433
438
|
description: tool.description,
|
|
@@ -718,7 +723,9 @@ const layerHandlers = serverInfo => _McpSchema.ClientRpcs.toLayer(Effect.gen(fun
|
|
|
718
723
|
return {
|
|
719
724
|
// Requests
|
|
720
725
|
ping: () => Effect.succeed({}),
|
|
721
|
-
initialize(params
|
|
726
|
+
initialize(params, {
|
|
727
|
+
clientId
|
|
728
|
+
}) {
|
|
722
729
|
const requestedVersion = params.protocolVersion;
|
|
723
730
|
const capabilities = {
|
|
724
731
|
completions: {}
|
|
@@ -739,6 +746,7 @@ const layerHandlers = serverInfo => _McpSchema.ClientRpcs.toLayer(Effect.gen(fun
|
|
|
739
746
|
listChanged: true
|
|
740
747
|
};
|
|
741
748
|
}
|
|
749
|
+
server.initializedClients.add(clientId);
|
|
742
750
|
return Effect.succeed({
|
|
743
751
|
capabilities,
|
|
744
752
|
serverInfo,
|