effect 4.0.0-beta.11 → 4.0.0-beta.13
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/dist/Config.d.ts +157 -0
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +56 -1
- package/dist/Config.js.map +1 -1
- package/dist/Effect.d.ts +79 -0
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +26 -0
- package/dist/Effect.js.map +1 -1
- package/dist/Fiber.d.ts +2 -2
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +3 -6
- package/dist/Graph.js.map +1 -1
- package/dist/ManagedRuntime.d.ts +1 -1
- package/dist/ManagedRuntime.js +1 -1
- package/dist/Random.d.ts +17 -0
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +17 -0
- package/dist/Random.js.map +1 -1
- package/dist/Schedule.js +1 -1
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +3 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/SchemaAST.js +1 -1
- package/dist/SchemaAST.js.map +1 -1
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +59 -44
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/request.js +2 -2
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/schema/annotations.js +2 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +49 -18
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +134 -58
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +49 -12
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +33 -6
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +16 -0
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +14 -0
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/CliOutput.js +24 -2
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +41 -6
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +64 -31
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +162 -0
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -0
- package/dist/unstable/cli/GlobalFlag.js +164 -0
- package/dist/unstable/cli/GlobalFlag.js.map +1 -0
- package/dist/unstable/cli/HelpDoc.d.ts +10 -0
- package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +1 -5
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +4 -22
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/help.d.ts +19 -0
- package/dist/unstable/cli/internal/help.d.ts.map +1 -0
- package/dist/unstable/cli/internal/help.js +54 -0
- package/dist/unstable/cli/internal/help.js.map +1 -0
- package/dist/unstable/cli/internal/parser.js +20 -35
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +2 -2
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +28 -4
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +3 -8
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +13 -24
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +4 -8
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +6 -1
- package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerError.js +26 -17
- package/dist/unstable/http/HttpServerError.js.map +1 -1
- package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
- package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
- package/dist/unstable/http/internal/preResponseHandler.js +10 -0
- package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +4 -4
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js +14 -0
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +34 -9
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +0 -7
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +5 -10
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +1 -1
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +3 -3
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +3 -3
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/sql/SqlError.d.ts +14 -14
- package/dist/unstable/sql/SqlError.d.ts.map +1 -1
- package/dist/unstable/sql/SqlError.js +9 -3
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/package.json +1 -1
- package/src/Config.ts +171 -9
- package/src/Effect.ts +80 -0
- package/src/Fiber.ts +9 -2
- package/src/Graph.ts +16 -6
- package/src/ManagedRuntime.ts +1 -1
- package/src/Random.ts +18 -0
- package/src/Schedule.ts +1 -1
- package/src/Schema.ts +1 -1
- package/src/SchemaAST.ts +1 -1
- package/src/index.ts +47 -0
- package/src/internal/effect.ts +82 -49
- package/src/internal/request.ts +2 -2
- package/src/internal/schema/annotations.ts +2 -0
- package/src/unstable/ai/LanguageModel.ts +54 -24
- package/src/unstable/ai/McpSchema.ts +59 -13
- package/src/unstable/ai/McpServer.ts +44 -6
- package/src/unstable/ai/Tool.ts +15 -0
- package/src/unstable/cli/CliOutput.ts +32 -2
- package/src/unstable/cli/Command.ts +95 -38
- package/src/unstable/cli/GlobalFlag.ts +342 -0
- package/src/unstable/cli/HelpDoc.ts +12 -0
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/command.ts +5 -30
- package/src/unstable/cli/internal/help.ts +66 -0
- package/src/unstable/cli/internal/parser.ts +23 -52
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +2 -2
- package/src/unstable/http/HttpClient.ts +45 -10
- package/src/unstable/http/HttpEffect.ts +20 -39
- package/src/unstable/http/HttpMiddleware.ts +4 -14
- package/src/unstable/http/HttpServerError.ts +29 -18
- package/src/unstable/http/internal/preResponseHandler.ts +15 -0
- package/src/unstable/httpapi/HttpApiBuilder.ts +1 -1
- package/src/unstable/reactivity/Atom.ts +7 -7
- package/src/unstable/rpc/Rpc.ts +1 -1
- package/src/unstable/rpc/RpcSchema.ts +17 -0
- package/src/unstable/rpc/RpcSerialization.ts +44 -9
- package/src/unstable/rpc/RpcServer.ts +10 -19
- package/src/unstable/schema/VariantSchema.ts +6 -6
- package/src/unstable/sql/SqlError.ts +11 -9
- package/dist/unstable/cli/internal/builtInFlags.d.ts +0 -7
- package/dist/unstable/cli/internal/builtInFlags.d.ts.map +0 -1
- package/dist/unstable/cli/internal/builtInFlags.js +0 -44
- package/dist/unstable/cli/internal/builtInFlags.js.map +0 -1
- package/src/unstable/cli/internal/builtInFlags.ts +0 -78
|
@@ -949,9 +949,8 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
949
949
|
return content as Array<Response.Part<Tools>>
|
|
950
950
|
}
|
|
951
951
|
|
|
952
|
-
// Pre-resolve tool approvals before calling the LLM
|
|
952
|
+
// Pre-resolve pending tool approvals before calling the LLM
|
|
953
953
|
if (hasPendingApprovals) {
|
|
954
|
-
// Validate all approved tools exist in the toolkit
|
|
955
954
|
for (const approval of approved) {
|
|
956
955
|
if (approval.toolCall && !toolkit.tools[approval.toolCall.name]) {
|
|
957
956
|
return yield* AiError.make({
|
|
@@ -965,7 +964,6 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
965
964
|
}
|
|
966
965
|
}
|
|
967
966
|
|
|
968
|
-
// Execute approved tools and create denial results
|
|
969
967
|
const approvedResults = yield* executeApprovedToolCalls(
|
|
970
968
|
approved,
|
|
971
969
|
toolkit,
|
|
@@ -974,23 +972,27 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
974
972
|
const deniedResults = createDenialResults(denied)
|
|
975
973
|
const preResolvedResults = [...approvedResults, ...deniedResults]
|
|
976
974
|
|
|
977
|
-
// Add pre-resolved results to the prompt
|
|
978
975
|
if (preResolvedResults.length > 0) {
|
|
979
|
-
const toolMessage = Prompt.makeMessage("tool", {
|
|
980
|
-
content: preResolvedResults
|
|
981
|
-
})
|
|
982
976
|
providerOptions.prompt = Prompt.fromMessages([
|
|
983
977
|
...providerOptions.prompt.content,
|
|
984
|
-
|
|
978
|
+
Prompt.makeMessage("tool", { content: preResolvedResults })
|
|
985
979
|
])
|
|
986
980
|
}
|
|
981
|
+
}
|
|
987
982
|
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
983
|
+
// Strip all resolved approval artifacts (both current and from previous
|
|
984
|
+
// rounds) in a single pass before sending to the provider.
|
|
985
|
+
{
|
|
986
|
+
const { approved: allResolved, denied: allDenied } = collectToolApprovals(
|
|
987
|
+
providerOptions.prompt.content
|
|
993
988
|
)
|
|
989
|
+
if (allResolved.length > 0 || allDenied.length > 0) {
|
|
990
|
+
providerOptions.prompt = stripResolvedApprovals(
|
|
991
|
+
providerOptions.prompt,
|
|
992
|
+
allResolved,
|
|
993
|
+
allDenied
|
|
994
|
+
)
|
|
995
|
+
}
|
|
994
996
|
}
|
|
995
997
|
|
|
996
998
|
const tools = typeof toolChoice === "object" && "oneOf" in toolChoice
|
|
@@ -1137,9 +1139,10 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
1137
1139
|
>
|
|
1138
1140
|
}
|
|
1139
1141
|
|
|
1140
|
-
// Pre-resolve tool approvals before calling the LLM
|
|
1142
|
+
// Pre-resolve pending tool approvals before calling the LLM
|
|
1143
|
+
let preResolvedStreamParts: Array<Response.StreamPart<Tools>> = []
|
|
1144
|
+
|
|
1141
1145
|
if (hasPendingApprovals) {
|
|
1142
|
-
// Validate all approved tools exist in the toolkit
|
|
1143
1146
|
for (const approval of pendingApproved) {
|
|
1144
1147
|
if (approval.toolCall && !toolkit.tools[approval.toolCall.name]) {
|
|
1145
1148
|
return yield* AiError.make({
|
|
@@ -1153,7 +1156,6 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
1153
1156
|
}
|
|
1154
1157
|
}
|
|
1155
1158
|
|
|
1156
|
-
// Execute approved tools and create denial results
|
|
1157
1159
|
const approvedResults = yield* executeApprovedToolCalls(
|
|
1158
1160
|
pendingApproved,
|
|
1159
1161
|
toolkit,
|
|
@@ -1162,22 +1164,43 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
1162
1164
|
const deniedResults = createDenialResults(pendingDenied)
|
|
1163
1165
|
const preResolvedResults = [...approvedResults, ...deniedResults]
|
|
1164
1166
|
|
|
1165
|
-
// Add pre-resolved results to the prompt
|
|
1166
1167
|
if (preResolvedResults.length > 0) {
|
|
1167
|
-
const toolMessage = Prompt.makeMessage("tool", {
|
|
1168
|
-
content: preResolvedResults
|
|
1169
|
-
})
|
|
1170
1168
|
providerOptions.prompt = Prompt.fromMessages([
|
|
1171
1169
|
...providerOptions.prompt.content,
|
|
1172
|
-
|
|
1170
|
+
Prompt.makeMessage("tool", { content: preResolvedResults })
|
|
1173
1171
|
])
|
|
1174
1172
|
}
|
|
1175
1173
|
|
|
1176
|
-
//
|
|
1174
|
+
// Emit pre-resolved tool-results as stream parts so Chat.streamText
|
|
1175
|
+
// persists them to history. This lets collectToolApprovals find them
|
|
1176
|
+
// on subsequent rounds and skip the now-resolved approvals.
|
|
1177
|
+
// Note: r.result is already encoded (from executeApprovedToolCalls /
|
|
1178
|
+
// createDenialResults), so it goes into both result and encodedResult.
|
|
1179
|
+
for (const r of preResolvedResults) {
|
|
1180
|
+
preResolvedStreamParts.push(
|
|
1181
|
+
Response.makePart("tool-result", {
|
|
1182
|
+
id: r.id,
|
|
1183
|
+
name: r.name,
|
|
1184
|
+
providerExecuted: false,
|
|
1185
|
+
preliminary: false,
|
|
1186
|
+
result: r.result,
|
|
1187
|
+
encodedResult: r.result,
|
|
1188
|
+
isFailure: r.isFailure
|
|
1189
|
+
}) as Response.StreamPart<Tools>
|
|
1190
|
+
)
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// Strip all resolved approval artifacts (both current and from previous
|
|
1195
|
+
// rounds) in a single pass before sending to the provider.
|
|
1196
|
+
const { approved: allResolved, denied: allDenied } = collectToolApprovals(
|
|
1197
|
+
providerOptions.prompt.content
|
|
1198
|
+
)
|
|
1199
|
+
if (allResolved.length > 0 || allDenied.length > 0) {
|
|
1177
1200
|
providerOptions.prompt = stripResolvedApprovals(
|
|
1178
1201
|
providerOptions.prompt,
|
|
1179
|
-
|
|
1180
|
-
|
|
1202
|
+
allResolved,
|
|
1203
|
+
allDenied
|
|
1181
1204
|
)
|
|
1182
1205
|
}
|
|
1183
1206
|
|
|
@@ -1215,6 +1238,13 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
1215
1238
|
| Schema.SchemaError
|
|
1216
1239
|
>()
|
|
1217
1240
|
|
|
1241
|
+
// Emit pre-resolved tool results so Chat.streamText persists them to
|
|
1242
|
+
// history. This ensures collectToolApprovals({ excludeResolved }) can
|
|
1243
|
+
// find the corresponding tool-results on future rounds.
|
|
1244
|
+
if (preResolvedStreamParts.length > 0) {
|
|
1245
|
+
yield* Queue.offerAll(queue, preResolvedStreamParts)
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1218
1248
|
// FiberSet to track concurrent tool call handlers
|
|
1219
1249
|
const toolCallFibers = yield* FiberSet.make<void, AiError.AiError>()
|
|
1220
1250
|
|
|
@@ -120,7 +120,7 @@ export class ResultMeta extends Schema.Opaque<ResultMeta>()(Schema.Struct({
|
|
|
120
120
|
* This result property is reserved by the protocol to allow clients and
|
|
121
121
|
* servers to attach additional metadata to their responses.
|
|
122
122
|
*/
|
|
123
|
-
_meta: optional(Schema.Record(Schema.String, Schema.
|
|
123
|
+
_meta: optional(Schema.Record(Schema.String, Schema.Json))
|
|
124
124
|
})) {}
|
|
125
125
|
|
|
126
126
|
/**
|
|
@@ -132,7 +132,7 @@ export class NotificationMeta extends Schema.Opaque<NotificationMeta>()(Schema.S
|
|
|
132
132
|
* This parameter name is reserved by MCP to allow clients and servers to
|
|
133
133
|
* attach additional metadata to their notifications.
|
|
134
134
|
*/
|
|
135
|
-
_meta: optional(Schema.Record(Schema.String, Schema.
|
|
135
|
+
_meta: optional(Schema.Record(Schema.String, Schema.Json))
|
|
136
136
|
})) {}
|
|
137
137
|
|
|
138
138
|
/**
|
|
@@ -240,6 +240,11 @@ export class ClientCapabilities extends Schema.Class<ClientCapabilities>(
|
|
|
240
240
|
* Experimental, non-standard capabilities that the client supports.
|
|
241
241
|
*/
|
|
242
242
|
experimental: optional(Schema.Record(Schema.String, Schema.Struct({}))),
|
|
243
|
+
/**
|
|
244
|
+
* Optional extensions capabilities advertised by the client.
|
|
245
|
+
* Keys are extension identifiers following <vendor-prefix>/<extension-name> (e.g. "io.modelcontextprotocol/ui").
|
|
246
|
+
*/
|
|
247
|
+
extensions: optional(Schema.Record(Schema.TemplateLiteral([Schema.String, "/", Schema.String]), Schema.Json)),
|
|
243
248
|
/**
|
|
244
249
|
* Present if the client supports listing roots.
|
|
245
250
|
*/
|
|
@@ -272,6 +277,11 @@ export class ServerCapabilities extends Schema.Opaque<ServerCapabilities>()(Sche
|
|
|
272
277
|
* Experimental, non-standard capabilities that the server supports.
|
|
273
278
|
*/
|
|
274
279
|
experimental: optional(Schema.Record(Schema.String, Schema.Struct({}))),
|
|
280
|
+
/**
|
|
281
|
+
* Optional extensions capabilities advertised by the server.
|
|
282
|
+
* Keys are extension identifiers following <vendor-prefix>/<extension-name> (e.g. "io.modelcontextprotocol/ui").
|
|
283
|
+
*/
|
|
284
|
+
extensions: optional(Schema.Record(Schema.TemplateLiteral([Schema.String, "/", Schema.String]), Schema.Json)),
|
|
275
285
|
/**
|
|
276
286
|
* Present if the server supports sending log messages to the client.
|
|
277
287
|
*/
|
|
@@ -321,8 +331,8 @@ export class ServerCapabilities extends Schema.Opaque<ServerCapabilities>()(Sche
|
|
|
321
331
|
* @since 4.0.0
|
|
322
332
|
* @category errors
|
|
323
333
|
*/
|
|
324
|
-
export class
|
|
325
|
-
"@effect/ai/McpSchema/
|
|
334
|
+
export class McpErrorBase extends Schema.Class<McpErrorBase>(
|
|
335
|
+
"@effect/ai/McpSchema/McpErrorBase"
|
|
326
336
|
)({
|
|
327
337
|
/**
|
|
328
338
|
* The error type that occurred.
|
|
@@ -371,7 +381,7 @@ export const PARSE_ERROR_CODE = -32700 as const
|
|
|
371
381
|
* @category errors
|
|
372
382
|
*/
|
|
373
383
|
export class ParseError extends Schema.ErrorClass<ParseError>("effect/ai/McpSchema/ParseError")({
|
|
374
|
-
...
|
|
384
|
+
...McpErrorBase.fields,
|
|
375
385
|
_tag: Schema.tag("ParseError"),
|
|
376
386
|
code: Schema.tag(PARSE_ERROR_CODE)
|
|
377
387
|
}) {}
|
|
@@ -381,7 +391,7 @@ export class ParseError extends Schema.ErrorClass<ParseError>("effect/ai/McpSche
|
|
|
381
391
|
* @category errors
|
|
382
392
|
*/
|
|
383
393
|
export class InvalidRequest extends Schema.ErrorClass<InvalidRequest>("effect/ai/McpSchema/InvalidRequest")({
|
|
384
|
-
...
|
|
394
|
+
...McpErrorBase.fields,
|
|
385
395
|
_tag: Schema.tag("InvalidRequest"),
|
|
386
396
|
code: Schema.tag(INVALID_REQUEST_ERROR_CODE)
|
|
387
397
|
}) {}
|
|
@@ -391,7 +401,7 @@ export class InvalidRequest extends Schema.ErrorClass<InvalidRequest>("effect/ai
|
|
|
391
401
|
* @category errors
|
|
392
402
|
*/
|
|
393
403
|
export class MethodNotFound extends Schema.ErrorClass<MethodNotFound>("effect/ai/McpSchema/MethodNotFound")({
|
|
394
|
-
...
|
|
404
|
+
...McpErrorBase.fields,
|
|
395
405
|
_tag: Schema.tag("MethodNotFound"),
|
|
396
406
|
code: Schema.tag(METHOD_NOT_FOUND_ERROR_CODE)
|
|
397
407
|
}) {}
|
|
@@ -401,7 +411,7 @@ export class MethodNotFound extends Schema.ErrorClass<MethodNotFound>("effect/ai
|
|
|
401
411
|
* @category errors
|
|
402
412
|
*/
|
|
403
413
|
export class InvalidParams extends Schema.ErrorClass<InvalidParams>("effect/ai/McpSchema/InvalidParams")({
|
|
404
|
-
...
|
|
414
|
+
...McpErrorBase.fields,
|
|
405
415
|
_tag: Schema.tag("InvalidParams"),
|
|
406
416
|
code: Schema.tag(INVALID_PARAMS_ERROR_CODE)
|
|
407
417
|
}) {}
|
|
@@ -411,13 +421,26 @@ export class InvalidParams extends Schema.ErrorClass<InvalidParams>("effect/ai/M
|
|
|
411
421
|
* @category errors
|
|
412
422
|
*/
|
|
413
423
|
export class InternalError extends Schema.ErrorClass<InternalError>("effect/ai/McpSchema/InternalError")({
|
|
414
|
-
...
|
|
424
|
+
...McpErrorBase.fields,
|
|
415
425
|
_tag: Schema.tag("InternalError"),
|
|
416
426
|
code: Schema.tag(INTERNAL_ERROR_CODE)
|
|
417
427
|
}) {
|
|
418
428
|
static readonly notImplemented = new InternalError({ message: "Not implemented" })
|
|
419
429
|
}
|
|
420
430
|
|
|
431
|
+
/**
|
|
432
|
+
* @since 4.0.0
|
|
433
|
+
* @category errors
|
|
434
|
+
*/
|
|
435
|
+
export const McpError = Schema.Union([
|
|
436
|
+
ParseError,
|
|
437
|
+
InvalidRequest,
|
|
438
|
+
MethodNotFound,
|
|
439
|
+
InvalidParams,
|
|
440
|
+
InternalError,
|
|
441
|
+
McpErrorBase
|
|
442
|
+
])
|
|
443
|
+
|
|
421
444
|
// =============================================================================
|
|
422
445
|
// Ping
|
|
423
446
|
// =============================================================================
|
|
@@ -615,7 +638,14 @@ export class Resource extends Schema.Class<Resource>(
|
|
|
615
638
|
* This can be used by Hosts to display file sizes and estimate context
|
|
616
639
|
* window usage.
|
|
617
640
|
*/
|
|
618
|
-
size: optional(Schema.Number)
|
|
641
|
+
size: optional(Schema.Number),
|
|
642
|
+
/**
|
|
643
|
+
* Optional additional metadata for the client.
|
|
644
|
+
*
|
|
645
|
+
* This parameter name is reserved by MCP to allow clients and servers to
|
|
646
|
+
* attach additional metadata to resources.
|
|
647
|
+
*/
|
|
648
|
+
_meta: optional(Schema.Record(Schema.String, Schema.Json))
|
|
619
649
|
}) {}
|
|
620
650
|
|
|
621
651
|
/**
|
|
@@ -656,7 +686,12 @@ export class ResourceTemplate extends Schema.Class<ResourceTemplate>(
|
|
|
656
686
|
/**
|
|
657
687
|
* Optional annotations for the client.
|
|
658
688
|
*/
|
|
659
|
-
annotations: optional(Annotations)
|
|
689
|
+
annotations: optional(Annotations),
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Optional additional metadata for the client.
|
|
693
|
+
*/
|
|
694
|
+
_meta: optional(Schema.Record(Schema.String, Schema.Json))
|
|
660
695
|
}) {}
|
|
661
696
|
|
|
662
697
|
/**
|
|
@@ -673,7 +708,11 @@ export class ResourceContents extends Schema.Opaque<ResourceContents>()(Schema.S
|
|
|
673
708
|
/**
|
|
674
709
|
* The MIME type of this resource, if known.
|
|
675
710
|
*/
|
|
676
|
-
mimeType: optional(Schema.String)
|
|
711
|
+
mimeType: optional(Schema.String),
|
|
712
|
+
/**
|
|
713
|
+
* Optional additional metadata for the client.
|
|
714
|
+
*/
|
|
715
|
+
_meta: optional(Schema.Record(Schema.String, Schema.Json))
|
|
677
716
|
})) {}
|
|
678
717
|
|
|
679
718
|
/**
|
|
@@ -1183,7 +1222,14 @@ export class Tool extends Schema.Class<Tool>(
|
|
|
1183
1222
|
/**
|
|
1184
1223
|
* Optional additional tool information.
|
|
1185
1224
|
*/
|
|
1186
|
-
annotations: optional(ToolAnnotations)
|
|
1225
|
+
annotations: optional(ToolAnnotations),
|
|
1226
|
+
/**
|
|
1227
|
+
* Optional additional metadata for the client.
|
|
1228
|
+
*
|
|
1229
|
+
* This parameter name is reserved by MCP to allow clients and servers to
|
|
1230
|
+
* attach additional metadata to resources.
|
|
1231
|
+
*/
|
|
1232
|
+
_meta: optional(Schema.Record(Schema.String, Schema.Json))
|
|
1187
1233
|
}) {}
|
|
1188
1234
|
|
|
1189
1235
|
/**
|
|
@@ -9,6 +9,7 @@ import * as Layer from "../../Layer.ts"
|
|
|
9
9
|
import * as Option from "../../Option.ts"
|
|
10
10
|
import * as Queue from "../../Queue.ts"
|
|
11
11
|
import * as RcMap from "../../RcMap.ts"
|
|
12
|
+
import { CurrentLogLevel } from "../../References.ts"
|
|
12
13
|
import * as Schema from "../../Schema.ts"
|
|
13
14
|
import * as AST from "../../SchemaAST.ts"
|
|
14
15
|
import * as ServiceMap from "../../ServiceMap.ts"
|
|
@@ -548,6 +549,7 @@ export const registerToolkit: <Tools extends Record<string, Tool.Any>>(
|
|
|
548
549
|
>)
|
|
549
550
|
const services = yield* Effect.services<never>()
|
|
550
551
|
for (const tool of Object.values(built.tools)) {
|
|
552
|
+
const toolMeta = ServiceMap.getOrUndefined(tool.annotations, Tool.Meta)
|
|
551
553
|
const mcpTool = new McpTool({
|
|
552
554
|
name: tool.name,
|
|
553
555
|
description: Tool.getDescription(tool),
|
|
@@ -561,7 +563,8 @@ export const registerToolkit: <Tools extends Record<string, Tool.Any>>(
|
|
|
561
563
|
destructiveHint: ServiceMap.get(tool.annotations, Tool.Destructive),
|
|
562
564
|
idempotentHint: ServiceMap.get(tool.annotations, Tool.Idempotent),
|
|
563
565
|
openWorldHint: ServiceMap.get(tool.annotations, Tool.OpenWorld)
|
|
564
|
-
}
|
|
566
|
+
},
|
|
567
|
+
_meta: toolMeta
|
|
565
568
|
})
|
|
566
569
|
yield* registry.addTool({
|
|
567
570
|
tool: mcpTool,
|
|
@@ -1075,6 +1078,7 @@ const layerHandlers = (serverInfo: {
|
|
|
1075
1078
|
ClientRpcs.toLayer(
|
|
1076
1079
|
Effect.gen(function*() {
|
|
1077
1080
|
const server = yield* McpServer
|
|
1081
|
+
let currentLogLevel = yield* CurrentLogLevel
|
|
1078
1082
|
|
|
1079
1083
|
return ClientRpcs.of({
|
|
1080
1084
|
// Requests
|
|
@@ -1105,17 +1109,51 @@ const layerHandlers = (serverInfo: {
|
|
|
1105
1109
|
: LATEST_PROTOCOL_VERSION
|
|
1106
1110
|
})
|
|
1107
1111
|
},
|
|
1108
|
-
"completion/complete":
|
|
1109
|
-
|
|
1110
|
-
|
|
1112
|
+
"completion/complete": (r) =>
|
|
1113
|
+
server.completion(r).pipe(
|
|
1114
|
+
Effect.provideService(CurrentLogLevel, currentLogLevel)
|
|
1115
|
+
),
|
|
1116
|
+
"logging/setLevel": ({ level }) =>
|
|
1117
|
+
Effect.sync(() => {
|
|
1118
|
+
switch (level) {
|
|
1119
|
+
case "notice":
|
|
1120
|
+
case "info":
|
|
1121
|
+
currentLogLevel = "Info"
|
|
1122
|
+
break
|
|
1123
|
+
case "error":
|
|
1124
|
+
currentLogLevel = "Error"
|
|
1125
|
+
break
|
|
1126
|
+
case "debug":
|
|
1127
|
+
currentLogLevel = "Debug"
|
|
1128
|
+
break
|
|
1129
|
+
case "warning":
|
|
1130
|
+
currentLogLevel = "Warn"
|
|
1131
|
+
break
|
|
1132
|
+
case "critical":
|
|
1133
|
+
case "alert":
|
|
1134
|
+
case "emergency":
|
|
1135
|
+
currentLogLevel = "Fatal"
|
|
1136
|
+
break
|
|
1137
|
+
}
|
|
1138
|
+
}),
|
|
1139
|
+
"prompts/get": (r) =>
|
|
1140
|
+
server.getPromptResult(r).pipe(
|
|
1141
|
+
Effect.provideService(CurrentLogLevel, currentLogLevel)
|
|
1142
|
+
),
|
|
1111
1143
|
"prompts/list": () => Effect.sync(() => new ListPromptsResult({ prompts: server.prompts })),
|
|
1112
1144
|
"resources/list": () => Effect.sync(() => new ListResourcesResult({ resources: server.resources })),
|
|
1113
|
-
"resources/read": ({ uri }) =>
|
|
1145
|
+
"resources/read": ({ uri }) =>
|
|
1146
|
+
server.findResource(uri).pipe(
|
|
1147
|
+
Effect.provideService(CurrentLogLevel, currentLogLevel)
|
|
1148
|
+
),
|
|
1114
1149
|
"resources/subscribe": () => InternalError.notImplemented.asEffect(),
|
|
1115
1150
|
"resources/unsubscribe": () => InternalError.notImplemented.asEffect(),
|
|
1116
1151
|
"resources/templates/list": () =>
|
|
1117
1152
|
Effect.sync(() => new ListResourceTemplatesResult({ resourceTemplates: server.resourceTemplates })),
|
|
1118
|
-
"tools/call":
|
|
1153
|
+
"tools/call": (r) =>
|
|
1154
|
+
server.callTool(r).pipe(
|
|
1155
|
+
Effect.provideService(CurrentLogLevel, currentLogLevel)
|
|
1156
|
+
),
|
|
1119
1157
|
"tools/list": () => Effect.sync(() => new ListToolsResult({ tools: server.tools })),
|
|
1120
1158
|
|
|
1121
1159
|
// Notifications
|
package/src/unstable/ai/Tool.ts
CHANGED
|
@@ -1661,6 +1661,21 @@ export const getJsonSchemaFromSchema = <S extends Schema.Top>(schema: S, options
|
|
|
1661
1661
|
*/
|
|
1662
1662
|
export class Title extends ServiceMap.Service<Title, string>()("effect/ai/Tool/Title") {}
|
|
1663
1663
|
|
|
1664
|
+
/**
|
|
1665
|
+
* Annotation for providing tool metadata for MCP.
|
|
1666
|
+
*
|
|
1667
|
+
* @example
|
|
1668
|
+
* ```ts
|
|
1669
|
+
* import { Tool } from "effect/unstable/ai"
|
|
1670
|
+
*
|
|
1671
|
+
* const myCalculatorUi = Tool.make("calculator_ui", {})
|
|
1672
|
+
* .annotate(Tool.Meta, { ui: { resourceUri: "ui://example/calculator-ui" } })
|
|
1673
|
+
* ```
|
|
1674
|
+
* @since 1.0.0
|
|
1675
|
+
* @category annotations
|
|
1676
|
+
*/
|
|
1677
|
+
export class Meta extends ServiceMap.Service<Meta, Record<string, unknown>>()("effect/ai/Tool/Meta") {}
|
|
1678
|
+
|
|
1664
1679
|
/**
|
|
1665
1680
|
* Annotation indicating whether a tool only reads data without making changes.
|
|
1666
1681
|
*
|
|
@@ -409,6 +409,8 @@ const renderTable = (rows: ReadonlyArray<Row>, widthCap: number) => {
|
|
|
409
409
|
return rows.map(({ left, right }) => ` ${pad(left, col)}${right}`).join("\n")
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
const formatSubcommandName = (name: string, alias: string | undefined): string => alias ? `${name}, ${alias}` : name
|
|
413
|
+
|
|
412
414
|
/**
|
|
413
415
|
* Color functions interface for help formatting.
|
|
414
416
|
* @internal
|
|
@@ -497,6 +499,34 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
|
|
|
497
499
|
sections.push("")
|
|
498
500
|
}
|
|
499
501
|
|
|
502
|
+
// Global Flags section
|
|
503
|
+
if (doc.globalFlags && doc.globalFlags.length > 0) {
|
|
504
|
+
sections.push(colors.bold("GLOBAL FLAGS"))
|
|
505
|
+
|
|
506
|
+
const globalFlagRows: Array<Row> = doc.globalFlags.map((flag) => {
|
|
507
|
+
const names: Array<string> = []
|
|
508
|
+
|
|
509
|
+
// Add main name with -- prefix first
|
|
510
|
+
names.push(colors.green(`--${flag.name}`))
|
|
511
|
+
|
|
512
|
+
// Add aliases after (like -f) to match expected ordering
|
|
513
|
+
for (const alias of flag.aliases) {
|
|
514
|
+
names.push(colors.green(alias))
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const namesPart = names.join(", ")
|
|
518
|
+
const typePart = flag.type !== "boolean" ? ` ${colors.dim(flag.type)}` : ""
|
|
519
|
+
|
|
520
|
+
return {
|
|
521
|
+
left: namesPart + typePart,
|
|
522
|
+
right: flag.description ?? ""
|
|
523
|
+
}
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
sections.push(renderTable(globalFlagRows, 30))
|
|
527
|
+
sections.push("")
|
|
528
|
+
}
|
|
529
|
+
|
|
500
530
|
// Subcommands section
|
|
501
531
|
if (doc.subcommands && doc.subcommands.length > 0) {
|
|
502
532
|
const ungrouped = doc.subcommands.find((group) => group.group === undefined)
|
|
@@ -505,7 +535,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
|
|
|
505
535
|
sections.push(colors.bold("SUBCOMMANDS"))
|
|
506
536
|
sections.push(renderTable(
|
|
507
537
|
ungrouped.commands.map((sub) => ({
|
|
508
|
-
left: colors.cyan(sub.name),
|
|
538
|
+
left: colors.cyan(formatSubcommandName(sub.name, sub.alias)),
|
|
509
539
|
right: sub.shortDescription ?? sub.description
|
|
510
540
|
})),
|
|
511
541
|
20
|
|
@@ -520,7 +550,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
|
|
|
520
550
|
sections.push(colors.bold(`${group.group}:`))
|
|
521
551
|
sections.push(renderTable(
|
|
522
552
|
group.commands.map((sub) => ({
|
|
523
|
-
left: colors.cyan(sub.name),
|
|
553
|
+
left: colors.cyan(formatSubcommandName(sub.name, sub.alias)),
|
|
524
554
|
right: sub.shortDescription ?? sub.description
|
|
525
555
|
})),
|
|
526
556
|
20
|