effect 4.1.3 → 4.1.4
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/SchemaRepresentation.d.ts +17 -3
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +4 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ai/Chat.d.ts +1 -1
- package/dist/ai/Chat.d.ts.map +1 -1
- package/dist/ai/Chat.js.map +1 -1
- package/dist/ai/LanguageModel.d.ts +23 -4
- package/dist/ai/LanguageModel.d.ts.map +1 -1
- package/dist/ai/LanguageModel.js +8 -4
- package/dist/ai/LanguageModel.js.map +1 -1
- package/dist/ai/McpClient.d.ts +0 -5
- package/dist/ai/McpClient.d.ts.map +1 -1
- package/dist/ai/McpClient.js +1 -11
- package/dist/ai/McpClient.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +110 -110
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpServer.d.ts +1 -3
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +1 -3
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/WorkloadIdentity.d.ts +111 -0
- package/dist/ai/WorkloadIdentity.d.ts.map +1 -0
- package/dist/ai/WorkloadIdentity.js +227 -0
- package/dist/ai/WorkloadIdentity.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +2 -4
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpSkills.js +80 -2
- package/dist/ai/internal/mcpSkills.js.map +1 -1
- package/dist/ai/internal/structured-output.js +5 -1
- package/dist/ai/internal/structured-output.js.map +1 -1
- package/dist/cli/Command.d.ts.map +1 -1
- package/dist/cli/Command.js +3 -1
- package/dist/cli/Command.js.map +1 -1
- package/dist/cli/internal/lexer.js +13 -0
- package/dist/cli/internal/lexer.js.map +1 -1
- package/dist/cli/internal/parser.js +23 -16
- package/dist/cli/internal/parser.js.map +1 -1
- package/dist/cli/internal/wizard.d.ts.map +1 -1
- package/dist/cli/internal/wizard.js +4 -0
- package/dist/cli/internal/wizard.js.map +1 -1
- package/dist/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/http/HttpMiddleware.js +4 -2
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/internal/requestState.js +15 -0
- package/dist/http/internal/requestState.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +47 -0
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +66 -0
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +9 -1
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +5 -1
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/HttpApiSchema.d.ts +66 -0
- package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
- package/dist/http-api/HttpApiSchema.js +66 -1
- package/dist/http-api/HttpApiSchema.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +141 -35
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +3 -0
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/testing/TestClock.js +3 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/package.json +1 -1
- package/src/SchemaRepresentation.ts +18 -3
- package/src/ai/Chat.ts +9 -3
- package/src/ai/LanguageModel.ts +70 -14
- package/src/ai/McpClient.ts +1 -11
- package/src/ai/McpServer.ts +1 -3
- package/src/ai/WorkloadIdentity.ts +318 -0
- package/src/ai/index.ts +6 -0
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +3 -1
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +3 -1
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +3 -1
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +3 -1
- package/src/ai/internal/mcpRuntime.ts +2 -6
- package/src/ai/internal/mcpSkills.ts +70 -2
- package/src/ai/internal/structured-output.ts +6 -1
- package/src/cli/Command.ts +5 -1
- package/src/cli/internal/lexer.ts +14 -0
- package/src/cli/internal/parser.ts +28 -20
- package/src/cli/internal/wizard.ts +4 -0
- package/src/http/HttpMiddleware.ts +13 -2
- package/src/http/internal/requestState.ts +20 -0
- package/src/http-api/HttpApi.ts +80 -0
- package/src/http-api/HttpApiBuilder.ts +9 -1
- package/src/http-api/HttpApiClient.ts +13 -2
- package/src/http-api/HttpApiSchema.ts +68 -2
- package/src/internal/schema/fromJsonSchemaDocument.ts +154 -34
- package/src/internal/schema/toCodeDocument.ts +8 -0
- package/src/internal/version.ts +1 -1
- package/src/testing/TestClock.ts +1 -1
package/src/ai/index.ts
CHANGED
|
@@ -7,9 +7,10 @@ import * as McpCore from "../mcpCore.ts"
|
|
|
7
7
|
import * as McpProtocol from "../mcpProtocol.ts"
|
|
8
8
|
import * as McpRuntime from "../mcpRuntime.ts"
|
|
9
9
|
import * as McpSchema from "../mcpSchema/v2024_11_05.ts"
|
|
10
|
+
import * as McpSkills from "../mcpSkills.ts"
|
|
10
11
|
|
|
11
12
|
// Pings can arrive before initialize and do not require a client session.
|
|
12
|
-
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").middleware(
|
|
13
|
+
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").merge(McpSkills.LegacyRpcs).middleware(
|
|
13
14
|
PublicMcpSchema.McpServerClientMiddleware
|
|
14
15
|
).add(McpSchema.Ping)
|
|
15
16
|
|
|
@@ -121,6 +122,7 @@ export const protocol = McpProtocol.make({
|
|
|
121
122
|
handlerRpcs: AdapterRpcs,
|
|
122
123
|
makeHandlers: (core, lifecycle) =>
|
|
123
124
|
AdapterRpcs.of({
|
|
125
|
+
...McpSkills.legacyHandlers(core),
|
|
124
126
|
initialize: (request, { client }) =>
|
|
125
127
|
lifecycle.initialize(McpSchema.protocolVersion, profileFromInitialize(request), client.id).pipe(
|
|
126
128
|
Effect.map((result) =>
|
|
@@ -7,9 +7,10 @@ import * as McpCore from "../mcpCore.ts"
|
|
|
7
7
|
import * as McpProtocol from "../mcpProtocol.ts"
|
|
8
8
|
import * as McpRuntime from "../mcpRuntime.ts"
|
|
9
9
|
import * as McpSchema from "../mcpSchema/v2025_03_26.ts"
|
|
10
|
+
import * as McpSkills from "../mcpSkills.ts"
|
|
10
11
|
|
|
11
12
|
// Pings can arrive before initialize and do not require a client session.
|
|
12
|
-
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").middleware(
|
|
13
|
+
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").merge(McpSkills.LegacyRpcs).middleware(
|
|
13
14
|
PublicMcpSchema.McpServerClientMiddleware
|
|
14
15
|
).add(McpSchema.Ping)
|
|
15
16
|
|
|
@@ -124,6 +125,7 @@ export const protocol = McpProtocol.make({
|
|
|
124
125
|
handlerRpcs: AdapterRpcs,
|
|
125
126
|
makeHandlers: (core, lifecycle) =>
|
|
126
127
|
AdapterRpcs.of({
|
|
128
|
+
...McpSkills.legacyHandlers(core),
|
|
127
129
|
initialize: (request, { client }) =>
|
|
128
130
|
lifecycle.initialize(McpSchema.protocolVersion, profileFromInitialize(request), client.id).pipe(
|
|
129
131
|
Effect.map((result) =>
|
|
@@ -9,9 +9,10 @@ import * as McpCore from "../mcpCore.ts"
|
|
|
9
9
|
import * as McpProtocol from "../mcpProtocol.ts"
|
|
10
10
|
import * as McpRuntime from "../mcpRuntime.ts"
|
|
11
11
|
import * as McpSchema from "../mcpSchema/v2025_06_18.ts"
|
|
12
|
+
import * as McpSkills from "../mcpSkills.ts"
|
|
12
13
|
|
|
13
14
|
// Pings can arrive before initialize and do not require a client session.
|
|
14
|
-
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").middleware(
|
|
15
|
+
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").merge(McpSkills.LegacyRpcs).middleware(
|
|
15
16
|
PublicMcpSchema.McpServerClientMiddleware
|
|
16
17
|
).add(McpSchema.Ping)
|
|
17
18
|
|
|
@@ -143,6 +144,7 @@ export const protocol = McpProtocol.make({
|
|
|
143
144
|
handlerRpcs: AdapterRpcs,
|
|
144
145
|
makeHandlers: (core, lifecycle) =>
|
|
145
146
|
AdapterRpcs.of({
|
|
147
|
+
...McpSkills.legacyHandlers(core),
|
|
146
148
|
initialize: (request, { client }) =>
|
|
147
149
|
lifecycle.initialize(McpSchema.protocolVersion, profileFromInitialize(request), client.id).pipe(
|
|
148
150
|
Effect.map((result) =>
|
|
@@ -8,9 +8,10 @@ import * as McpCore from "../mcpCore.ts"
|
|
|
8
8
|
import * as McpProtocol from "../mcpProtocol.ts"
|
|
9
9
|
import * as McpRuntime from "../mcpRuntime.ts"
|
|
10
10
|
import * as McpSchema from "../mcpSchema/v2025_11_25.ts"
|
|
11
|
+
import * as McpSkills from "../mcpSkills.ts"
|
|
11
12
|
|
|
12
13
|
// Pings can arrive before initialize and do not require a client session.
|
|
13
|
-
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").middleware(
|
|
14
|
+
const ClientRequestRpcs = McpSchema.ClientRequestRpcs.omit("ping").merge(McpSkills.LegacyRpcs).middleware(
|
|
14
15
|
PublicMcpSchema.McpServerClientMiddleware
|
|
15
16
|
).add(McpSchema.Ping)
|
|
16
17
|
|
|
@@ -133,6 +134,7 @@ export const protocol = McpProtocol.make({
|
|
|
133
134
|
handlerRpcs: AdapterRpcs,
|
|
134
135
|
makeHandlers: (core, lifecycle) =>
|
|
135
136
|
AdapterRpcs.of({
|
|
137
|
+
...McpSkills.legacyHandlers(core),
|
|
136
138
|
initialize: (request, { client }) =>
|
|
137
139
|
lifecycle.initialize(McpSchema.protocolVersion, {
|
|
138
140
|
protocolVersion: McpSchema.protocolVersion,
|
|
@@ -13,7 +13,6 @@ import * as HttpServerResponse from "../../http/HttpServerResponse.ts"
|
|
|
13
13
|
import * as Layer from "../../Layer.ts"
|
|
14
14
|
import type * as LogLevel from "../../LogLevel.ts"
|
|
15
15
|
import * as Predicate from "../../Predicate.ts"
|
|
16
|
-
import * as Rec from "../../Record.ts"
|
|
17
16
|
import * as Result from "../../Result.ts"
|
|
18
17
|
import * as RpcGroup from "../../rpc/RpcGroup.ts"
|
|
19
18
|
import type * as RpcMessage from "../../rpc/RpcMessage.ts"
|
|
@@ -533,10 +532,6 @@ export const make = Effect.fnUntraced(function*(
|
|
|
533
532
|
registrationPresence: options.core.registrationPresence
|
|
534
533
|
}
|
|
535
534
|
const handlerTarget = registry.handlerTarget(contextMap, installationContext)
|
|
536
|
-
// Skills requires 2026-07-28, so sessionful revisions never declare it.
|
|
537
|
-
const sessionfulExtensions = options.serverInfo.extensions === undefined
|
|
538
|
-
? undefined
|
|
539
|
-
: Rec.remove(options.serverInfo.extensions, McpSkills.EXTENSION_ID)
|
|
540
535
|
for (const protocol of registry.protocols) {
|
|
541
536
|
if (protocol.runtime._tag === "Stateless") {
|
|
542
537
|
yield* protocol.installHandlers(options.core, undefined, handlerTarget)
|
|
@@ -560,7 +555,8 @@ export const make = Effect.fnUntraced(function*(
|
|
|
560
555
|
: {}),
|
|
561
556
|
...(presence.prompts ? { prompts: { listChanged: true } } : {})
|
|
562
557
|
}
|
|
563
|
-
|
|
558
|
+
const extensions = McpSkills.declareExtension(options.serverInfo.extensions, presence.skills)
|
|
559
|
+
if (extensions !== undefined) capabilities.extensions = extensions
|
|
564
560
|
const initializePayload = PublicMcpSchema.Initialize.payloadSchema.make({
|
|
565
561
|
protocolVersion,
|
|
566
562
|
capabilities: profile.clientCapabilities,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Skills extension (SEP-2640): wire schemas
|
|
3
|
-
*
|
|
2
|
+
* The Skills extension (SEP-2640): wire schemas, the catalog behind a static
|
|
3
|
+
* skill, and the handlers shared by the sessionful adapters.
|
|
4
4
|
*/
|
|
5
5
|
import * as Cause from "../../Cause.ts"
|
|
6
6
|
import * as Digest from "../../crypto/Digest.ts"
|
|
@@ -15,6 +15,7 @@ import * as Schema from "../../Schema.ts"
|
|
|
15
15
|
import * as PublicMcpSchema from "../McpSchema.ts"
|
|
16
16
|
import type * as McpCore from "./mcpCore.ts"
|
|
17
17
|
import * as McpProtocol from "./mcpProtocol.ts"
|
|
18
|
+
import * as Legacy from "./mcpSchema/v2024_11_05.ts"
|
|
18
19
|
import * as Stateless from "./mcpSchema/v2026_07_28.ts"
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -58,6 +59,41 @@ const Skill = Schema.Struct({
|
|
|
58
59
|
// invalid entry instead of rejecting the whole page.
|
|
59
60
|
const ListedSkills = Schema.Array(Schema.Unknown)
|
|
60
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export class LegacyListSkills extends Rpc.make("skills/list", {
|
|
66
|
+
success: Schema.Struct({ ...Legacy.PaginatedResult.fields, skills: ListedSkills }),
|
|
67
|
+
error: Legacy.McpError,
|
|
68
|
+
payload: Schema.UndefinedOr(Legacy.PaginatedRequest)
|
|
69
|
+
}) {}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export class LegacyGetSkill extends Rpc.make("skills/get", {
|
|
75
|
+
success: Schema.Struct({ ...Legacy.ResultMeta.fields, skill: Skill }),
|
|
76
|
+
error: Legacy.McpError,
|
|
77
|
+
payload: { ...Legacy.RequestMeta.fields, uri: Schema.String }
|
|
78
|
+
}) {}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export class LegacyReadResourceDirectory extends Rpc.make("resources/directory/read", {
|
|
84
|
+
success: Schema.Struct({ ...Legacy.PaginatedResult.fields, resources: Schema.Array(Legacy.Resource) }),
|
|
85
|
+
error: Legacy.McpError,
|
|
86
|
+
payload: { ...Legacy.PaginatedRequest.fields, uri: Schema.String }
|
|
87
|
+
}) {}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The extension's methods on revisions before 2026-07-28, which have no
|
|
91
|
+
* result caching attributes.
|
|
92
|
+
*
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
export class LegacyRpcs extends RpcGroup.make(LegacyListSkills, LegacyGetSkill, LegacyReadResourceDirectory) {}
|
|
96
|
+
|
|
61
97
|
/**
|
|
62
98
|
* @internal
|
|
63
99
|
*/
|
|
@@ -142,6 +178,38 @@ export const requireSkills = (core: McpCore.McpCore, method: string) =>
|
|
|
142
178
|
(presence) => presence.skills ? Effect.void : Effect.fail(methodNotFound(method))
|
|
143
179
|
)
|
|
144
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Handlers for {@link LegacyRpcs}, for the sessionful adapters.
|
|
183
|
+
*
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
export const legacyHandlers = (core: McpCore.McpCore) => ({
|
|
187
|
+
"skills/list": Effect.fnUntraced(function*(request: typeof LegacyListSkills.payloadSchema.Type) {
|
|
188
|
+
yield* requireSkills(core, "skills/list")
|
|
189
|
+
const skills = yield* McpProtocol.listForClient(core.skills.list, request?.cursor)
|
|
190
|
+
return { skills }
|
|
191
|
+
}),
|
|
192
|
+
"skills/get": Effect.fnUntraced(function*(request: typeof LegacyGetSkill.payloadSchema.Type) {
|
|
193
|
+
yield* requireSkills(core, "skills/get")
|
|
194
|
+
const client = yield* PublicMcpSchema.McpServerClient
|
|
195
|
+
const skill = yield* core.skills.get(request.uri, McpProtocol.invocationFromClient(client)).pipe(
|
|
196
|
+
Effect.mapError(McpProtocol.ProtocolError.fromFeature)
|
|
197
|
+
)
|
|
198
|
+
return { skill }
|
|
199
|
+
}),
|
|
200
|
+
"resources/directory/read": Effect.fnUntraced(function*(
|
|
201
|
+
request: typeof LegacyReadResourceDirectory.payloadSchema.Type
|
|
202
|
+
) {
|
|
203
|
+
yield* requireSkills(core, "resources/directory/read")
|
|
204
|
+
yield* McpProtocol.rejectCursor(request.cursor)
|
|
205
|
+
const client = yield* PublicMcpSchema.McpServerClient
|
|
206
|
+
const resources = yield* core.skills.readDirectory(request.uri, McpProtocol.invocationFromClient(client)).pipe(
|
|
207
|
+
Effect.mapError(McpProtocol.ProtocolError.fromFeature)
|
|
208
|
+
)
|
|
209
|
+
return { resources }
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
|
|
145
213
|
// =============================================================================
|
|
146
214
|
// Static skills
|
|
147
215
|
// =============================================================================
|
|
@@ -312,7 +312,7 @@ function compilerAnnotations(
|
|
|
312
312
|
|
|
313
313
|
function optionalToNullable(type: SchemaAST.AST): SchemaAST.AST {
|
|
314
314
|
return SchemaAST.decodeTo(
|
|
315
|
-
new SchemaAST.Union([type, SchemaAST.null]),
|
|
315
|
+
isNullable(type) ? SchemaAST.replaceContext(type, undefined) : new SchemaAST.Union([type, SchemaAST.null]),
|
|
316
316
|
SchemaAST.optionalKey(SchemaAST.toType(type)),
|
|
317
317
|
SchemaTransformation.transformOptional({
|
|
318
318
|
decode: Option.filter(Predicate.isNotNull),
|
|
@@ -321,6 +321,11 @@ function optionalToNullable(type: SchemaAST.AST): SchemaAST.AST {
|
|
|
321
321
|
)
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
function isNullable(ast: SchemaAST.AST): boolean {
|
|
325
|
+
if (ast.checks !== undefined || ast.encoding !== undefined) return false
|
|
326
|
+
return SchemaAST.isNull(ast) || (SchemaAST.isUnion(ast) && ast.types.some(isNullable))
|
|
327
|
+
}
|
|
328
|
+
|
|
324
329
|
function prepareChecks(checks: SchemaAST.Checks | undefined): SchemaAST.Checks | undefined {
|
|
325
330
|
if (checks === undefined) return undefined
|
|
326
331
|
const out = SchemaAST.mapOrSame(checks, prepareCheck)
|
package/src/cli/Command.ts
CHANGED
|
@@ -3676,9 +3676,13 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
|
|
|
3676
3676
|
const { colors } = yield* Prompt.Theme
|
|
3677
3677
|
return yield* Effect.gen(function*() {
|
|
3678
3678
|
yield* Console.log(Wizard.renderIntroduction(command.name, config.version, command.description, colors))
|
|
3679
|
+
// The wizard prompts for the selected command's inputs, so drop the typed ones.
|
|
3680
|
+
const selectedTokens = new Set(Parser.getSelectedCommandTokens(remainder, command))
|
|
3679
3681
|
const prefix = [
|
|
3680
3682
|
command.name,
|
|
3681
|
-
...
|
|
3683
|
+
...tokens.filter((token) =>
|
|
3684
|
+
!selectedTokens.has(token) && !(token._tag === "LongOption" && token.name === "wizard")
|
|
3685
|
+
).map(Lexer.formatToken)
|
|
3682
3686
|
]
|
|
3683
3687
|
const wizardResult = yield* Wizard.run(command, { commandPath, prefix })
|
|
3684
3688
|
yield* Console.log(Wizard.renderCompletion(wizardResult.displayArgs, colors))
|
|
@@ -46,6 +46,20 @@ export function lex(argv: ReadonlyArray<string>): LexResult {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Formats a token as an argument. Short option clusters become one argument
|
|
51
|
+
* per flag.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export const formatToken = (token: Token): string => {
|
|
56
|
+
if (token._tag === "Value") return token.value
|
|
57
|
+
if (token._tag === "LongOption") return token.raw
|
|
58
|
+
// Numeric aliases need long-option syntax to avoid becoming negative numbers.
|
|
59
|
+
const flag = negativeNumberRegex.test(token.raw) ? `--${token.flag}` : token.raw
|
|
60
|
+
return token.value === undefined ? flag : `${flag}=${token.value}`
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
const negativeNumberRegex = /^-(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/
|
|
50
64
|
|
|
51
65
|
const lexTokens = (args: ReadonlyArray<string>): ReadonlyArray<Token> => {
|
|
@@ -58,26 +58,7 @@ export const parseArgs = (
|
|
|
58
58
|
Effect.gen(function*() {
|
|
59
59
|
const { tokens, trailingOperands: afterEndOfOptions } = lexResult
|
|
60
60
|
const newCommandPath = [...commandPath, command.name]
|
|
61
|
-
|
|
62
|
-
const commandImpl = toImpl(command)
|
|
63
|
-
const singles = commandImpl.config.flags.flatMap(Param.extractSingleParams)
|
|
64
|
-
const flagParams = singles.filter(Param.isFlagParam)
|
|
65
|
-
const flagRegistry = createFlagRegistry(flagParams)
|
|
66
|
-
|
|
67
|
-
const inheritedSingles = commandImpl.contextConfig.flags.flatMap(Param.extractSingleParams)
|
|
68
|
-
const inheritedFlagParams = inheritedSingles.filter(Param.isFlagParam)
|
|
69
|
-
const inheritedFlagRegistry = createFlagRegistry(inheritedFlagParams)
|
|
70
|
-
const inheritedNames = new Set(inheritedFlagParams.map((param) => param.name))
|
|
71
|
-
|
|
72
|
-
const context: CommandContext = {
|
|
73
|
-
command,
|
|
74
|
-
commandPath: newCommandPath,
|
|
75
|
-
flagRegistry,
|
|
76
|
-
inheritedFlagRegistry,
|
|
77
|
-
localFlagNames: flagParams.filter((param) => !inheritedNames.has(param.name)).map((param) => param.name)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const result = scanCommandLevel(tokens, context)
|
|
61
|
+
const result = scanCommandLevel(tokens, makeCommandContext(command, newCommandPath))
|
|
81
62
|
|
|
82
63
|
if (result._tag === "Leaf") {
|
|
83
64
|
return {
|
|
@@ -104,6 +85,20 @@ export const parseArgs = (
|
|
|
104
85
|
}
|
|
105
86
|
})
|
|
106
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Returns the subset of `tokens` left for the selected command once its
|
|
90
|
+
* ancestors have consumed subcommand names and inherited flags.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
export const getSelectedCommandTokens = (
|
|
95
|
+
tokens: ReadonlyArray<Token>,
|
|
96
|
+
command: Command.Any
|
|
97
|
+
): ReadonlyArray<Token> => {
|
|
98
|
+
const result = scanCommandLevel(tokens, makeCommandContext(command, []))
|
|
99
|
+
return result._tag === "Leaf" ? tokens : getSelectedCommandTokens(result.childTokens, result.sub)
|
|
100
|
+
}
|
|
101
|
+
|
|
107
102
|
/* ========================================================================== */
|
|
108
103
|
/* Types */
|
|
109
104
|
/* ========================================================================== */
|
|
@@ -945,6 +940,19 @@ const processValue = (
|
|
|
945
940
|
/* Command Level Scanning */
|
|
946
941
|
/* ========================================================================== */
|
|
947
942
|
|
|
943
|
+
const makeCommandContext = (command: Command.Any, commandPath: ReadonlyArray<string>): CommandContext => {
|
|
944
|
+
const flagParams = extractFlagParams(command)
|
|
945
|
+
const inheritedFlagParams = extractContextFlagParams(command)
|
|
946
|
+
const inheritedNames = new Set(inheritedFlagParams.map((param) => param.name))
|
|
947
|
+
return {
|
|
948
|
+
command,
|
|
949
|
+
commandPath,
|
|
950
|
+
flagRegistry: createFlagRegistry(flagParams),
|
|
951
|
+
inheritedFlagRegistry: createFlagRegistry(inheritedFlagParams),
|
|
952
|
+
localFlagNames: flagParams.filter((param) => !inheritedNames.has(param.name)).map((param) => param.name)
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
948
956
|
/**
|
|
949
957
|
* Scans a single command level, processing all tokens.
|
|
950
958
|
*
|
|
@@ -84,6 +84,10 @@ const promptCommand: (
|
|
|
84
84
|
|
|
85
85
|
if (config.arguments.length > 0) {
|
|
86
86
|
yield* Console.log(renderSection(sectionName, "ARGUMENTS", colors))
|
|
87
|
+
// Keep positional answers from binding to preceding boolean flags.
|
|
88
|
+
if (visibleSubcommands.length === 0) {
|
|
89
|
+
commandLine.push(commandLineArg("--"))
|
|
90
|
+
}
|
|
87
91
|
for (const param of config.arguments) {
|
|
88
92
|
commandLine.push(...yield* promptParam(param))
|
|
89
93
|
}
|
|
@@ -288,6 +288,12 @@ const responseSpanExit = (
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
const withStateNames = (
|
|
292
|
+
names: ReadonlyArray<string | RegExp>,
|
|
293
|
+
stateNames: ReadonlyArray<string | RegExp> | undefined
|
|
294
|
+
): ReadonlyArray<string | RegExp> =>
|
|
295
|
+
stateNames === undefined || stateNames.length === 0 ? names : [...names, ...stateNames]
|
|
296
|
+
|
|
291
297
|
/**
|
|
292
298
|
* Middleware that creates a server trace span for each request and records request and response HTTP attributes.
|
|
293
299
|
*
|
|
@@ -317,7 +323,8 @@ export const tracer: <E, R>(
|
|
|
317
323
|
span.end(endTime, responseSpanExit(fiber, request, exit.value))
|
|
318
324
|
return undefined
|
|
319
325
|
}
|
|
320
|
-
const
|
|
326
|
+
const state = Context.getOrUndefined(prevServices, CurrentRequestState)
|
|
327
|
+
const redactedHeaderNames = withStateNames(fiber.getRef(Headers.CurrentRedactedNames), state?.redactedHeaderNames)
|
|
321
328
|
const headerFilter = fiber.getRef(TracerHeaderFilter)
|
|
322
329
|
// Complete the span before the request fiber exits so shutdown can flush it.
|
|
323
330
|
let response: HttpServerResponse
|
|
@@ -337,7 +344,11 @@ export const tracer: <E, R>(
|
|
|
337
344
|
span.attribute("http.request.method", request.method)
|
|
338
345
|
const url = Request.toURL(request)
|
|
339
346
|
if (Option.isSome(url)) {
|
|
340
|
-
tracing.addUrlAttributes(
|
|
347
|
+
tracing.addUrlAttributes(
|
|
348
|
+
span,
|
|
349
|
+
url.value,
|
|
350
|
+
withStateNames(fiber.getRef(UrlParams.CurrentRedactedNames), state?.redactedUrlParamNames)
|
|
351
|
+
)
|
|
341
352
|
}
|
|
342
353
|
if (request.headers["user-agent"] !== undefined) {
|
|
343
354
|
span.attribute("user_agent.original", request.headers["user-agent"])
|
|
@@ -10,6 +10,8 @@ import type { PreResponseHandler } from "../HttpEffect.ts"
|
|
|
10
10
|
export class RequestState {
|
|
11
11
|
preResponseHandler: PreResponseHandler | undefined = undefined
|
|
12
12
|
loggerDisabled = false
|
|
13
|
+
redactedUrlParamNames: ReadonlyArray<string | RegExp> = []
|
|
14
|
+
redactedHeaderNames: ReadonlyArray<string | RegExp> = []
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -31,3 +33,21 @@ export const appendPreResponseHandlerUnsafe = (context: Context.Context<never>,
|
|
|
31
33
|
(request, response) => Effect.flatMap(prev(request, response), (response) => handler(request, response))
|
|
32
34
|
: handler
|
|
33
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds names to redact in the server span of the current request. The span
|
|
39
|
+
* is recorded after the handler restores its context, so scoped updates of
|
|
40
|
+
* `CurrentRedactedNames` do not reach it.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export const addRedactedNamesUnsafe = (
|
|
45
|
+
context: Context.Context<never>,
|
|
46
|
+
urlParamNames: ReadonlyArray<string | RegExp>,
|
|
47
|
+
headerNames: ReadonlyArray<string | RegExp>
|
|
48
|
+
): void => {
|
|
49
|
+
const state = Context.getOrUndefined(context, CurrentRequestState)
|
|
50
|
+
if (state === undefined) return
|
|
51
|
+
if (urlParamNames.length > 0) state.redactedUrlParamNames = [...state.redactedUrlParamNames, ...urlParamNames]
|
|
52
|
+
if (headerNames.length > 0) state.redactedHeaderNames = [...state.redactedHeaderNames, ...headerNames]
|
|
53
|
+
}
|
package/src/http-api/HttpApi.ts
CHANGED
|
@@ -16,6 +16,7 @@ import * as InternalRecord from "../internal/record.ts"
|
|
|
16
16
|
import { type Pipeable, pipeArguments } from "../Pipeable.ts"
|
|
17
17
|
import * as Predicate from "../Predicate.ts"
|
|
18
18
|
import * as Record from "../Record.ts"
|
|
19
|
+
import * as RegExp_ from "../RegExp.ts"
|
|
19
20
|
import type * as Schema from "../Schema.ts"
|
|
20
21
|
import type * as SchemaAST from "../SchemaAST.ts"
|
|
21
22
|
import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
|
|
@@ -484,6 +485,52 @@ export class ErrorParseOptions extends Context.Service<
|
|
|
484
485
|
SchemaAST.ParseOptions
|
|
485
486
|
>()("effect/http-api/HttpApi/ErrorParseOptions") {}
|
|
486
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Declares query parameters and headers whose values are only sometimes secret,
|
|
490
|
+
* so they are redacted in spans without being modelled as `Redacted`.
|
|
491
|
+
*
|
|
492
|
+
* **Details**
|
|
493
|
+
*
|
|
494
|
+
* Names are wire names after encoding, matched like `Headers.isRedactedName`:
|
|
495
|
+
* strings case-insensitively, regular expressions by test. A string query name
|
|
496
|
+
* also matches the bracketed keys of a nested parameter, such as
|
|
497
|
+
* `buildargs[NPM_TOKEN]` for `buildargs`. For the endpoint's client request and
|
|
498
|
+
* server span, they extend `UrlParams.CurrentRedactedNames` and
|
|
499
|
+
* `Headers.CurrentRedactedNames`. Names from the API, its groups and its
|
|
500
|
+
* endpoints are combined. Values sent and decoded are unchanged.
|
|
501
|
+
*
|
|
502
|
+
* **Gotchas**
|
|
503
|
+
*
|
|
504
|
+
* - `addHttpApi` copies the added API's annotations onto its groups like any
|
|
505
|
+
* other annotation, so a group's own `RedactedNames` replaces them. Repeat
|
|
506
|
+
* the names on the group to keep both.
|
|
507
|
+
* - Only URL and header attributes use these names. `user_agent.original` and
|
|
508
|
+
* the messages of span errors are recorded as is.
|
|
509
|
+
*
|
|
510
|
+
* **Example** (Redacting Docker build arguments)
|
|
511
|
+
*
|
|
512
|
+
* ```ts
|
|
513
|
+
* import { Schema } from "effect"
|
|
514
|
+
* import { HttpApi, HttpApiEndpoint } from "effect/http-api"
|
|
515
|
+
*
|
|
516
|
+
* const Build = HttpApiEndpoint.post("build", "/build", {
|
|
517
|
+
* query: { buildargs: Schema.optional(Schema.Record(Schema.String, Schema.String)) },
|
|
518
|
+
* headers: { "x-registry-config": Schema.optional(Schema.String) }
|
|
519
|
+
* }).annotate(HttpApi.RedactedNames, {
|
|
520
|
+
* query: ["buildargs"],
|
|
521
|
+
* headers: ["x-registry-config"]
|
|
522
|
+
* })
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
525
|
+
* @stability unstable
|
|
526
|
+
* @category services
|
|
527
|
+
* @since 4.0.0
|
|
528
|
+
*/
|
|
529
|
+
export class RedactedNames extends Context.Service<RedactedNames, {
|
|
530
|
+
readonly query?: ReadonlyArray<string | RegExp> | undefined
|
|
531
|
+
readonly headers?: ReadonlyArray<string | RegExp> | undefined
|
|
532
|
+
}>()("effect/http-api/HttpApi/RedactedNames") {}
|
|
533
|
+
|
|
487
534
|
/**
|
|
488
535
|
* @internal
|
|
489
536
|
*/
|
|
@@ -510,3 +557,36 @@ export const getSlotParseOptions = (annotations: Context.Context<never>): SlotPa
|
|
|
510
557
|
error: Context.getOrUndefined(annotations, ErrorParseOptions) ?? fallback
|
|
511
558
|
}
|
|
512
559
|
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* @internal
|
|
563
|
+
*/
|
|
564
|
+
export interface EndpointRedactedNames {
|
|
565
|
+
readonly query: ReadonlyArray<string | RegExp>
|
|
566
|
+
readonly headers: ReadonlyArray<string | RegExp>
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Combines the `RedactedNames` of an API, group and endpoint. A string query
|
|
571
|
+
* name also matches the bracketed keys of a nested parameter.
|
|
572
|
+
*
|
|
573
|
+
* @internal
|
|
574
|
+
*/
|
|
575
|
+
export const getEndpointRedactedNames = (
|
|
576
|
+
api: Pick<Top, "annotations">,
|
|
577
|
+
group: HttpApiGroup.Top,
|
|
578
|
+
endpoint: HttpApiEndpoint.Top
|
|
579
|
+
): EndpointRedactedNames | undefined => {
|
|
580
|
+
const query: Array<string | RegExp> = []
|
|
581
|
+
const headers: Array<string | RegExp> = []
|
|
582
|
+
for (const annotations of [api.annotations, group.annotations, endpoint.annotations]) {
|
|
583
|
+
const options = Context.getOrUndefined(annotations, RedactedNames)
|
|
584
|
+
if (options === undefined) continue
|
|
585
|
+
for (const name of options.query ?? []) {
|
|
586
|
+
query.push(name)
|
|
587
|
+
if (typeof name === "string") query.push(new RegExp(`^${RegExp_.escape(name)}\\[`, "i"))
|
|
588
|
+
}
|
|
589
|
+
if (options.headers !== undefined) headers.push(...options.headers)
|
|
590
|
+
}
|
|
591
|
+
return query.length === 0 && headers.length === 0 ? undefined : { query, headers }
|
|
592
|
+
}
|
|
@@ -31,6 +31,7 @@ import { HttpServerRequest } from "../http/HttpServerRequest.ts"
|
|
|
31
31
|
import * as Respondable from "../http/HttpServerRespondable.ts"
|
|
32
32
|
import * as Response from "../http/HttpServerResponse.ts"
|
|
33
33
|
import type { HttpServerResponse } from "../http/HttpServerResponse.ts"
|
|
34
|
+
import { addRedactedNamesUnsafe } from "../http/internal/requestState.ts"
|
|
34
35
|
import * as Multipart from "../http/Multipart.ts"
|
|
35
36
|
import * as UrlParams from "../http/UrlParams.ts"
|
|
36
37
|
import { stringOrRedacted } from "../internal/redacted.ts"
|
|
@@ -966,8 +967,9 @@ function handlerToHttpEffect(
|
|
|
966
967
|
|
|
967
968
|
const shouldParsePayload = endpoint.payload.size > 0 && !isRaw
|
|
968
969
|
const payloadBy = shouldParsePayload ? buildPayloadDecoders(endpoint.payload, options.payload) : undefined
|
|
970
|
+
const redactedNames = HttpApi.getEndpointRedactedNames(api, group, endpoint)
|
|
969
971
|
|
|
970
|
-
|
|
972
|
+
const effect = applyMiddleware(
|
|
971
973
|
group,
|
|
972
974
|
endpoint,
|
|
973
975
|
context,
|
|
@@ -1057,6 +1059,12 @@ function handlerToHttpEffect(
|
|
|
1057
1059
|
}),
|
|
1058
1060
|
Effect.provideContext(context)
|
|
1059
1061
|
)
|
|
1062
|
+
if (redactedNames === undefined) return effect
|
|
1063
|
+
// Added before middleware and decoding run, so their failures are redacted too.
|
|
1064
|
+
return Effect.withFiber((fiber) => {
|
|
1065
|
+
addRedactedNamesUnsafe(fiber.context, redactedNames.query, redactedNames.headers)
|
|
1066
|
+
return effect
|
|
1067
|
+
})
|
|
1060
1068
|
}
|
|
1061
1069
|
|
|
1062
1070
|
/**
|
|
@@ -19,7 +19,7 @@ import * as Effect from "../Effect.ts"
|
|
|
19
19
|
import * as Ndjson from "../encoding/Ndjson.ts"
|
|
20
20
|
import * as Sse from "../encoding/Sse.ts"
|
|
21
21
|
import { identity } from "../Function.ts"
|
|
22
|
-
import
|
|
22
|
+
import * as Headers from "../http/Headers.ts"
|
|
23
23
|
import * as HttpBody from "../http/HttpBody.ts"
|
|
24
24
|
import * as HttpClient from "../http/HttpClient.ts"
|
|
25
25
|
import * as HttpClientError from "../http/HttpClientError.ts"
|
|
@@ -507,6 +507,7 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
507
507
|
)
|
|
508
508
|
|
|
509
509
|
const middlewareKeys = Array.from(onEndpointOptions.middleware, (tag) => `${tag.key}/Client`)
|
|
510
|
+
const redactedNames = HttpApi.getEndpointRedactedNames(api, group, endpoint)
|
|
510
511
|
|
|
511
512
|
const endpointFn = Effect.fnUntraced(function*(
|
|
512
513
|
request: {
|
|
@@ -575,13 +576,14 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
575
576
|
httpRequest = HttpClientRequest.upgrade(httpRequest, upgrade.protocol)
|
|
576
577
|
}
|
|
577
578
|
|
|
578
|
-
const
|
|
579
|
+
const execute = executeMiddleware(
|
|
579
580
|
group,
|
|
580
581
|
endpoint,
|
|
581
582
|
httpRequest,
|
|
582
583
|
middlewareKeys,
|
|
583
584
|
middlewareKeys.length - 1
|
|
584
585
|
)
|
|
586
|
+
const response = yield* (redactedNames === undefined ? execute : withRedactedNames(execute, redactedNames))
|
|
585
587
|
|
|
586
588
|
if (request?.responseMode === "response-only") {
|
|
587
589
|
return response
|
|
@@ -603,6 +605,15 @@ export const makeClient = <ApiId extends string, Groups extends HttpApiGroup.Con
|
|
|
603
605
|
})
|
|
604
606
|
})
|
|
605
607
|
|
|
608
|
+
const withRedactedNames = <A, E, R>(
|
|
609
|
+
effect: Effect.Effect<A, E, R>,
|
|
610
|
+
redactedNames: HttpApi.EndpointRedactedNames
|
|
611
|
+
): Effect.Effect<A, E, R> =>
|
|
612
|
+
effect.pipe(
|
|
613
|
+
Effect.updateService(UrlParams.CurrentRedactedNames, (names) => [...names, ...redactedNames.query]),
|
|
614
|
+
Effect.updateService(Headers.CurrentRedactedNames, (names) => [...names, ...redactedNames.headers])
|
|
615
|
+
)
|
|
616
|
+
|
|
606
617
|
/**
|
|
607
618
|
* Constructs a type-safe client for an HTTP API using the `HttpClient` service,
|
|
608
619
|
* endpoint schemas, middleware, and optional client or response transformations.
|