@gjermundgaraba/effect-actions 0.24.0 → 0.25.1
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/README.md +2 -2
- package/dist/Action.mjs +2 -2
- package/dist/ActionMcp.d.mts +3 -1
- package/dist/ActionMcp.mjs +7 -4
- package/dist/ActionRpc.mjs +5 -2
- package/dist/ActionToolkit.d.mts +3 -0
- package/dist/ActionToolkit.mjs +13 -2
- package/dist/Webhook.d.mts +3 -1
- package/dist/authentication/provider.d.mts +4 -3
- package/dist/contract/callback.mjs +0 -4
- package/dist/contract/feed.mjs +1 -1
- package/dist/contract/implementation.d.mts +5 -15
- package/dist/contract/lift.mjs +80 -0
- package/dist/contract/log.mjs +1 -1
- package/dist/contract/media.d.mts +3 -2
- package/dist/contract/media.mjs +3 -2
- package/dist/contract/push.mjs +6 -10
- package/dist/contract/status.mjs +13 -2
- package/dist/contract/subscribe.mjs +0 -4
- package/dist/http/events.d.mts +2 -2
- package/dist/http/events.mjs +5 -2
- package/dist/mcp/bridge.mjs +8 -4
- package/dist/mcp/client.mjs +2 -1
- package/dist/mcp/protocol.mjs +2 -79
- package/dist/webhook/attempt.mjs +2 -2
- package/dist/webhook/health.mjs +99 -0
- package/dist/webhook/receiver.mjs +2 -2
- package/dist/webhook/signing.mjs +4 -11
- package/dist/webhook/stored.mjs +23 -13
- package/dist/webhook/subscriptions.mjs +34 -46
- package/docs/Action-failures.md +1 -1
- package/docs/ActionCli.md +1 -1
- package/docs/ActionHttp.md +1 -1
- package/docs/ActionMcp.md +2 -2
- package/docs/ActionRpc.md +0 -4
- package/docs/ActionToolkit.md +1 -0
- package/docs/Authentication-advanced.md +16 -19
- package/docs/Authentication-failures.md +1 -1
- package/docs/Authentication.md +0 -4
- package/docs/README.md +1 -1
- package/docs/Webhook.md +3 -6
- package/docs/setup.md +5 -5
- package/examples/build-events/src/notifier/routes.ts +3 -6
- package/examples/build-events/src/notifier.ts +4 -2
- package/examples/build-events/test/notifier.test.ts +1 -1
- package/examples/kitchen-sink/README.md +3 -3
- package/examples/kitchen-sink/src/identity/authenticate.ts +2 -2
- package/examples/kitchen-sink/src/identity/workspace-header.ts +19 -0
- package/examples/kitchen-sink/src/routes.ts +2 -2
- package/examples/live-rpc/src/chat/room.ts +0 -4
- package/examples/notes-service/src/identity/Identity.ts +0 -4
- package/package.json +2 -2
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -22
package/README.md
CHANGED
|
@@ -76,10 +76,10 @@ Effect.gen(function* () {
|
|
|
76
76
|
## Install
|
|
77
77
|
|
|
78
78
|
```sh
|
|
79
|
-
pnpm add @gjermundgaraba/effect-actions effect@~4.1.
|
|
79
|
+
pnpm add @gjermundgaraba/effect-actions effect@~4.1.1
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.1.
|
|
82
|
+
It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.1.1` to serve or run a CLI from Node, and `@types/node` for its `node:` imports. Every module is a subpath import (`.../Action`, `.../ActionHttp`, ...); there is no package root, so a contracts-only bundle never loads a server.
|
|
83
83
|
|
|
84
84
|
## Examples
|
|
85
85
|
|
package/dist/Action.mjs
CHANGED
|
@@ -12,9 +12,9 @@ import { inputOf, jsonRoundTrip, onProgressOf, watchInput } from "./contract/cal
|
|
|
12
12
|
import { acquireFeeds, eventsOf, feedBuilders } from "./contract/feed.mjs";
|
|
13
13
|
import { NotServed, SubscriptionError } from "./Event.mjs";
|
|
14
14
|
import { polledOn, queuedPush, readOn } from "./contract/push.mjs";
|
|
15
|
+
import { Image } from "./contract/media.mjs";
|
|
15
16
|
import { selectFrom } from "./contract/serving.mjs";
|
|
16
17
|
import { watching } from "./contract/watch.mjs";
|
|
17
|
-
import { Image } from "./contract/media.mjs";
|
|
18
18
|
import { Idempotency, keyed, layerIdempotency } from "./contract/idempotency.mjs";
|
|
19
19
|
import { Array as Array$1, Cause, Effect, Function, Layer, Predicate, Schema, Stream as Stream$1 } from "effect";
|
|
20
20
|
// src/contract/Action.ts
|
|
@@ -121,7 +121,7 @@ const watcherOf = (feeds) => (event, input, options) => {
|
|
|
121
121
|
poll: polledOn("In process", event.name)((cursor) => feed.poll(value, cursor, { subscriber })),
|
|
122
122
|
stream: (cursor) => Stream$1.unwrap(Effect.flatMap(feed.stream(value), (open) => Effect.map(queuedPush(open, cursor, Effect.succeed, {
|
|
123
123
|
ending: Function.identity,
|
|
124
|
-
|
|
124
|
+
positions: "watermark",
|
|
125
125
|
capacity: 1
|
|
126
126
|
}), (queue) => Stream$1.fromQueue(queue)))).pipe(readOn("In process", event.name))
|
|
127
127
|
}, options).pipe(Stream$1.ensuring(feed.release?.(value, subscriber) ?? Effect.void));
|
package/dist/ActionMcp.d.mts
CHANGED
|
@@ -38,6 +38,7 @@ export interface Options<E = never, R = never, A extends Any$1 | Any = Any$1 | A
|
|
|
38
38
|
* - A service known at startup is read in a `Layer.unwrap` around the feature, which closes over it: the endpoint then needs it at startup, and shares it with the tools.
|
|
39
39
|
* - A layer provided to this layer itself is built again for the features alone, so a resource reads another store than the tools write: provide it around the endpoint.
|
|
40
40
|
* - They cannot read the caller, which `authentication` gives protected tools alone: content that depends on the caller is an action.
|
|
41
|
+
* - A `McpServer.middleware` layer merged into them, a `McpServer.visibility` one included, runs for the actions' tools and not for the features beside it: provide it around the endpoint to reach both.
|
|
41
42
|
*/
|
|
42
43
|
readonly features?: Layer.Layer<never, E, R> | undefined;
|
|
43
44
|
}
|
|
@@ -59,7 +60,8 @@ export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any =
|
|
|
59
60
|
* **Gotchas**
|
|
60
61
|
*
|
|
61
62
|
* - A credential a request presents is still verified, on a public tool's call too: an expired or invalid one answers 401, its challenge naming `invalid_token`, on which a client refreshes it or signs in again.
|
|
62
|
-
* - `tools/list` names every tool, protected ones included:
|
|
63
|
+
* - `tools/list` names every tool, protected ones included: to list only the public ones to a request sending no credential, provide around the endpoint a `McpServer.visibility` returning `false` for a protected tool's `target` when, under Bearer, `headers["authorization"]` is absent, as the endpoint verifies a credential sent before it answers the listing. Or serve public tools on an endpoint of their own.
|
|
64
|
+
* - A client shown no protected tool never calls one, so it never gets the 401 that starts its sign-in: hide them only from clients that sign in before listing, such as one configured with a token.
|
|
63
65
|
* - A client of a 2025 revision opens a session, which on an endpoint serving a protected tool only a signed-in caller does: it signs in for every request there, a public tool's call and `tools/list` included.
|
|
64
66
|
* - Every prompt and resource request needs a credential, listings included: to offer them signed out, serve them on an endpoint without protected tools.
|
|
65
67
|
* - A handler that sends a notification starts the response, so a refusal after it is an `isError: true` tool result, not the 401 or 403 a client re-authorizes on: refuse in `authorize`.
|
package/dist/ActionMcp.mjs
CHANGED
|
@@ -5,11 +5,12 @@ import { toolSuccessOf } from "./contract/stream.mjs";
|
|
|
5
5
|
import { acquire, answeringWhole } from "./contract/implementation.mjs";
|
|
6
6
|
import { inputParseOptions } from "./contract/call.mjs";
|
|
7
7
|
import { hintsOf } from "./contract/hints.mjs";
|
|
8
|
+
import { liftOf, liftedFrom } from "./contract/lift.mjs";
|
|
8
9
|
import { promote, providerOf } from "./authentication/provider.mjs";
|
|
9
10
|
import { provideServed, selectFrom } from "./contract/serving.mjs";
|
|
10
11
|
import { recordStepUp } from "./authentication/refusal.mjs";
|
|
11
12
|
import { withStderrConsole } from "./stdio/console.mjs";
|
|
12
|
-
import { defaultPath, fieldKey, httpProtocol, isMisplaced, isObjectSchema,
|
|
13
|
+
import { defaultPath, fieldKey, httpProtocol, isMisplaced, isObjectSchema, protocols, toolJsonSchema } from "./mcp/protocol.mjs";
|
|
13
14
|
import { eventSchemasOf, refuseUnservable, serveWebhooks, withEvents } from "./mcp/bridge.mjs";
|
|
14
15
|
import { progressNotifier } from "./mcp/progress.mjs";
|
|
15
16
|
import { McpCallError } from "./mcp/reply.mjs";
|
|
@@ -100,6 +101,7 @@ const registerTools = Effect.fnUntraced(function* (apps, authentication) {
|
|
|
100
101
|
yield* registry.addTool({
|
|
101
102
|
tool,
|
|
102
103
|
annotations: Context.empty(),
|
|
104
|
+
services: built,
|
|
103
105
|
handle: (payload) => Effect.annotateCurrentSpan({ tool: action.name }).pipe(Effect.andThen(() => decode(payload ?? {})), Effect.mapError(({ message }) => new McpSchema.InvalidParams({ message: new AiError.ToolParameterValidationError({
|
|
104
106
|
toolName: action.name,
|
|
105
107
|
description: message
|
|
@@ -109,7 +111,7 @@ const registerTools = Effect.fnUntraced(function* (apps, authentication) {
|
|
|
109
111
|
content: nativeJsonTextOf(encoded)
|
|
110
112
|
})),
|
|
111
113
|
onSuccess: (success) => Effect.map(encodeSuccess(success), (encoded) => resultOf(encoded, success))
|
|
112
|
-
}))), Effect.catchCause(internalErrorOnDefect)
|
|
114
|
+
}))), Effect.catchCause(internalErrorOnDefect))
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
});
|
|
@@ -149,7 +151,7 @@ const namedMethods = /* @__PURE__ */ new Map([
|
|
|
149
151
|
["events/poll", "event"],
|
|
150
152
|
["events/stream", "event"]
|
|
151
153
|
]);
|
|
152
|
-
const openOf = (contracts) => new Set(contracts.
|
|
154
|
+
const openOf = (contracts) => new Set(contracts.flatMap(({ name, caller }) => caller === Anyone ? [name] : []));
|
|
153
155
|
const requiresAuthentication = (actions, events) => {
|
|
154
156
|
const open = {
|
|
155
157
|
tool: openOf(actions),
|
|
@@ -163,7 +165,8 @@ const requiresAuthentication = (actions, events) => {
|
|
|
163
165
|
if (anonymousMethods.has(method)) return false;
|
|
164
166
|
const named = namedMethods.get(method);
|
|
165
167
|
if (named === void 0) return true;
|
|
166
|
-
const
|
|
168
|
+
const sent = headers["mcp-name"];
|
|
169
|
+
const name = sent === void 0 ? void 0 : McpServer.decodeNameHeader(sent);
|
|
167
170
|
return name === void 0 || !open[named].has(name);
|
|
168
171
|
};
|
|
169
172
|
};
|
package/dist/ActionRpc.mjs
CHANGED
|
@@ -178,7 +178,10 @@ const subscriptionHandlerOf = (feed, steps, error, keeper) => {
|
|
|
178
178
|
const call = Effect.gen(function* () {
|
|
179
179
|
const { input, cursor } = yield* Effect.mapError(decode(payload), InvalidInput.fromSchemaError);
|
|
180
180
|
const open = yield* feed.stream(yield* decodeEventInput(input));
|
|
181
|
-
if (keeper === void 0) return yield* queuedPush(open, cursor, encode, {
|
|
181
|
+
if (keeper === void 0) return yield* queuedPush(open, cursor, encode, {
|
|
182
|
+
ending: boundary,
|
|
183
|
+
positions: "heartbeat"
|
|
184
|
+
});
|
|
182
185
|
yield* keeper.keep({
|
|
183
186
|
clientId: options.client.id,
|
|
184
187
|
requestId: options.requestId,
|
|
@@ -195,7 +198,7 @@ const subscriptionHandlerOf = (feed, steps, error, keeper) => {
|
|
|
195
198
|
});
|
|
196
199
|
return yield* queuedPush(open, cursor, encode, {
|
|
197
200
|
ending: boundary,
|
|
198
|
-
|
|
201
|
+
positions: "watermark"
|
|
199
202
|
});
|
|
200
203
|
});
|
|
201
204
|
const wrapped = throughSteps(steps, call, {
|
package/dist/ActionToolkit.d.mts
CHANGED
|
@@ -88,6 +88,9 @@ type ProgressOf<P> = P extends Codec ? Schema.decodeTo<Schema.declare<Reported<P
|
|
|
88
88
|
*
|
|
89
89
|
* - An action answering a stream, `Action.Stream`, answers its elements collected into one array once the stream ends, its tool's success that array.
|
|
90
90
|
* - An action declaring `progress` streams each value as a result with `preliminary: true` before its success, its `result` `{ _tag: "Progress", value }`, so its tool's success schema is that or `success`; a model reads the success alone.
|
|
91
|
+
* - An image where `Action.Image` lifts one reaches the model as a `file` part of the result's `modelOutput`, after one `text` part of the other fields' JSON when the success has any, while `result` and `encodedResult` keep it: a `Chat`'s history holds each image twice, its bytes and their base64.
|
|
92
|
+
* - A provider that takes only text tool results reads each image as a placeholder, `[image/png omitted]` as `Prompt.toolModelOutputToText` writes it, so its model never sees the image.
|
|
93
|
+
* - `setSuccess(…)` on a generated tool drops the mapping: the model reads the JSON again, the bytes in base64.
|
|
91
94
|
* - A success is a result with `isFailure: false`, `result` the value and `encodedResult` its JSON; a declared error a result with `isFailure: true` and `result` the error, which the model reads, never a raised failure; a refusal as `Action.Unauthenticated` and `Action.Forbidden` say.
|
|
92
95
|
* - Arguments that do not decode are a result with `isFailure: true` whose `result` is an `AiError` with `reason` a `ToolParameterValidationError`, never `InvalidInput`, and neither `authorize` nor the handler runs; undeclared arguments are dropped and the call runs.
|
|
93
96
|
* - A defect, or a failure the action's errors reject, is the call's defect; a success or an error that does not encode fails the call with an `AiError`, `Failed to encode result for tool …`.
|
package/dist/ActionToolkit.mjs
CHANGED
|
@@ -4,8 +4,9 @@ import { progressSink } from "./contract/progress.mjs";
|
|
|
4
4
|
import { toolSuccessOf } from "./contract/stream.mjs";
|
|
5
5
|
import { Implementation, acquire, answeringWhole, provideHandlers, select, toList } from "./contract/implementation.mjs";
|
|
6
6
|
import { hintsOf } from "./contract/hints.mjs";
|
|
7
|
+
import { liftOf, liftedFrom } from "./contract/lift.mjs";
|
|
7
8
|
import { Effect, Schema, SchemaGetter } from "effect";
|
|
8
|
-
import { Tool, Toolkit } from "effect/ai";
|
|
9
|
+
import { Prompt, Tool, Toolkit } from "effect/ai";
|
|
9
10
|
// src/toolkit/ActionToolkit.ts
|
|
10
11
|
const annotateIfGiven = (tool, key, value) => value === void 0 ? tool : tool.annotate(key, value);
|
|
11
12
|
const annotateFromContract = (tool, action) => {
|
|
@@ -28,6 +29,15 @@ const ProgressOf = (progress) => Schema.TaggedStruct("Progress", { value: progre
|
|
|
28
29
|
value: reported.value
|
|
29
30
|
}))
|
|
30
31
|
}));
|
|
32
|
+
const modelOutputOf = (success) => {
|
|
33
|
+
const lift = liftOf(success);
|
|
34
|
+
if (lift.fields.length === 0) return;
|
|
35
|
+
const encodeRest = lift.rest === void 0 ? void 0 : Schema.encodeUnknownSync(Schema.toCodecJson(lift.rest));
|
|
36
|
+
return (result) => [...encodeRest === void 0 ? [] : [Prompt.textPart({ text: JSON.stringify(encodeRest(result)) })], ...liftedFrom(lift, result).map(({ value }) => Prompt.filePart({
|
|
37
|
+
mediaType: value.mimeType,
|
|
38
|
+
data: value.data
|
|
39
|
+
}))];
|
|
40
|
+
};
|
|
31
41
|
const jsonToolOf = (action) => {
|
|
32
42
|
const success = toolSuccessOf(action.success);
|
|
33
43
|
return Tool.make(action.name, {
|
|
@@ -35,7 +45,8 @@ const jsonToolOf = (action) => {
|
|
|
35
45
|
parameters: Schema.toCodecJson(action.input),
|
|
36
46
|
success: Schema.toCodecJson(action.progress === void 0 ? success : Schema.Union([ProgressOf(action.progress), success])),
|
|
37
47
|
failure: Schema.toCodecJson(Schema.Union(projectedErrors(action))),
|
|
38
|
-
failureMode: "return"
|
|
48
|
+
failureMode: "return",
|
|
49
|
+
toModelOutput: modelOutputOf(success)
|
|
39
50
|
});
|
|
40
51
|
};
|
|
41
52
|
function make(apps, options) {
|
package/dist/Webhook.d.mts
CHANGED
|
@@ -44,7 +44,9 @@ export interface Options {
|
|
|
44
44
|
* - A subscription suspended stays suspended when restored, until its subscriber's refresh delivers again.
|
|
45
45
|
* - Secrets and identities are kept as JSON, as given, so give the layer a store only the server reads.
|
|
46
46
|
* - A kept subscription whose input or identity no longer decodes, as after a schema change, is reported at each build and never restored, until its subscriber unsubscribes it.
|
|
47
|
-
* -
|
|
47
|
+
* - The build lists every key of the store, a `SELECT id` over a SQL store's whole table or a read of the file store's directory, and restores those under `effect-actions/webhook/`: where the application keeps many keys in that store, give the layer one of its own.
|
|
48
|
+
* - A store whose keys cannot be listed as the layer builds fails the build, as the file store's does on a file name that is not percent-encoding, such as `100%.txt`; a write that fails later is reported and tried again with the next.
|
|
49
|
+
* - Writes still pending 5 seconds into the layer's close are reported as `UnfinishedWrites` and dropped: the next build restores each subscription as last written, missing one subscribed since and keeping one removed since.
|
|
48
50
|
* - A callback's verification is not kept: a restored subscription delivers on, and a new one to the same callback after a restart is verified again.
|
|
49
51
|
*/
|
|
50
52
|
readonly persist?: boolean | undefined;
|
|
@@ -114,10 +114,11 @@ export type DescriptorOf<O> = [O] extends [{
|
|
|
114
114
|
export type Matching<A extends Pick<Any$2, "caller">, D> = unknown extends Covered<Protected<A>> ? unknown : [Exclude<Covered<Protected<A>>, D extends Descriptor<infer I, unknown, Security, string, Errors> ? I : never>] extends [never] ? unknown : {
|
|
115
115
|
readonly "Authentication descriptor does not cover every protected action": never;
|
|
116
116
|
};
|
|
117
|
-
|
|
118
|
-
export type RemoteRequest<App, A extends Any$2> = ServedRequest<App, Extract<A, {
|
|
117
|
+
type PublicRequest<App, A extends Any$2> = ServedRequest<App, Extract<A, {
|
|
119
118
|
readonly caller: typeof Anyone;
|
|
120
|
-
}
|
|
119
|
+
}>>;
|
|
120
|
+
type ProtectedRequestLessIdentity<App, A extends Any$2> = Exclude<ServedRequest<App, Protected<A>>, Identity<Protected<A>>>;
|
|
121
|
+
export type RemoteRequest<App, A extends Any$2> = PublicRequest<App, A> | ProtectedRequestLessIdentity<App, A>;
|
|
121
122
|
/**
|
|
122
123
|
* The identity a remote layer's authentication provides every request, where `App` serves only
|
|
123
124
|
* protected actions of `A` and event types of `E`: its middleware reading it then owes nothing.
|
|
@@ -9,10 +9,6 @@ const SigningSecret = Schema.Struct({
|
|
|
9
9
|
const secretPrefix = "whsec_";
|
|
10
10
|
const decodeBase64 = Schema.decodeUnknownOption(Schema.Uint8ArrayFromBase64);
|
|
11
11
|
const keyOf = (text) => text.startsWith(secretPrefix) ? Option.filter(decodeBase64(text.slice(6)), (key) => key.length >= 24 && key.length <= 64) : Option.none();
|
|
12
|
-
/**
|
|
13
|
-
* A webhook's signing secret, as Standard Webhooks writes one: `whsec_` and the base64 of 24 to
|
|
14
|
-
* 64 bytes, decoded as the `SigningSecret` it is.
|
|
15
|
-
*/
|
|
16
12
|
const WebhookSecret = Schema.String.annotate({ description: "whsec_ and the base64 of 24 to 64 random bytes, which signs each delivery." }).pipe(Schema.decodeTo(SigningSecret, SchemaTransformation.transformEffect({
|
|
17
13
|
decode: (text, options) => Option.match(keyOf(text), {
|
|
18
14
|
onNone: () => Effect.fail(new SchemaIssue.InvalidValue({ message: "whsec_ and the base64 of 24 to 64 random bytes" }, text, options)),
|
package/dist/contract/feed.mjs
CHANGED
|
@@ -111,7 +111,7 @@ const logRun = (event, source, log) => {
|
|
|
111
111
|
stream: (input, cursor) => Stream.unwrap(Effect.map(keyOf(source, input), (key) => log.follow(cursor, logPageSize).pipe(Stream.mapEffect((read) => Effect.map(received(input, key, read), (items) => fedOf({
|
|
112
112
|
items,
|
|
113
113
|
truncated: read.truncated,
|
|
114
|
-
from: read.
|
|
114
|
+
from: read.from,
|
|
115
115
|
to: read.cursor
|
|
116
116
|
}))), Stream.flattenIterable)))
|
|
117
117
|
};
|
|
@@ -7,15 +7,9 @@ import { Any as Any$1 } from "../Action.mjs";
|
|
|
7
7
|
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
8
8
|
/** Decoded values at the dispatch boundary every surface shares. */
|
|
9
9
|
export type ErasedValue = Any$1["input"]["Type"];
|
|
10
|
-
/**
|
|
11
|
-
* A handler as written, erased: its answer, or the stream of an action answering one. Method
|
|
12
|
-
* extraction makes the argument bivariant: a surface selects the action before it invokes a
|
|
13
|
-
* handler, so its decoded input is the matching handler input, and handlers are not widened at
|
|
14
|
-
* their public API.
|
|
15
|
-
*/
|
|
16
10
|
export type WrittenHandler<R> = {
|
|
17
|
-
|
|
18
|
-
}["
|
|
11
|
+
bivarianceHack(input: ErasedValue, reporting?: Reporting): Effect.Effect<ErasedValue, ErasedValue, R> | Stream.Stream<ErasedValue, ErasedValue, R>;
|
|
12
|
+
}["bivarianceHack"];
|
|
19
13
|
/**
|
|
20
14
|
* A handler behind its action's authentication, authorization and declared errors, as a surface
|
|
21
15
|
* calls it. For an action answering a stream it succeeds at once with the call's stream, which
|
|
@@ -48,9 +42,7 @@ export interface Memoized<S, E, R> {
|
|
|
48
42
|
* its handlers' builder, `RA` what its authorizer reads per request, and `EAX` and `RAX` the
|
|
49
43
|
* failures and services of the authorizer's builder.
|
|
50
44
|
*/
|
|
51
|
-
export declare class Implementation<A extends Any$1, RequestServices
|
|
52
|
-
readonly [name: string]: unknown;
|
|
53
|
-
}, EX, RX, RA = never, EAX = never, RAX = never> {
|
|
45
|
+
export declare class Implementation<A extends Any$1, RequestServices, EX, RX, RA = never, EAX = never, RAX = never> {
|
|
54
46
|
#private;
|
|
55
47
|
/** Type-only: each action's handler's request-time requirements. */
|
|
56
48
|
readonly "~request": RequestServices;
|
|
@@ -98,9 +90,7 @@ export declare class Implementation<A extends Any$1, RequestServices extends {
|
|
|
98
90
|
* admits every implementation, while a value of this type owes `unknown`, which no surface can be
|
|
99
91
|
* given.
|
|
100
92
|
*/
|
|
101
|
-
export type AnyImplementation<A extends Any$1 = Any$1> = Implementation<A,
|
|
102
|
-
readonly [name: string]: unknown;
|
|
103
|
-
}, unknown, unknown, unknown, unknown, unknown>;
|
|
93
|
+
export type AnyImplementation<A extends Any$1 = Any$1> = Implementation<A, unknown, unknown, unknown, unknown, unknown, unknown>;
|
|
104
94
|
/** What a surface serves: one implementation, of actions or of events, or a list of them. */
|
|
105
95
|
export type Served = AnyImplementation | AnyEventImplementation | ReadonlyArray<AnyImplementation | AnyEventImplementation>;
|
|
106
96
|
/** What a surface serving no events takes: one action implementation, or a list of them. */
|
|
@@ -192,7 +182,7 @@ type AuthenticationOf<A extends Any$1> = A["caller"] extends typeof Anyone ? nev
|
|
|
192
182
|
export type RequestOf<App, A extends Any$1> = App extends {
|
|
193
183
|
readonly "~request": infer R;
|
|
194
184
|
readonly "~authorizeRequest": infer RA;
|
|
195
|
-
} ? A extends Any$1 ? [A["name"] & keyof R] extends [never] ? never : R[A["name"] & keyof R] | (A["caller"] extends typeof Anyone ? never : RA) | AuthenticationOf<A> : never : never;
|
|
185
|
+
} ? A extends Any$1 ? unknown extends R ? unknown : [A["name"] & keyof R] extends [never] ? never : R[A["name"] & keyof R] | (A["caller"] extends typeof Anyone ? never : RA) | AuthenticationOf<A> : never : never;
|
|
196
186
|
type OwnActions<App> = Extract<ActionOf<App>, Any$1>;
|
|
197
187
|
/**
|
|
198
188
|
* What a surface serving the actions `Listed` of the implementations `App` fails with at startup:
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { unsuspended } from "./ast.mjs";
|
|
2
|
+
import { Media, kindOf } from "./media.mjs";
|
|
3
|
+
import { Predicate, Schema, SchemaAST } from "effect";
|
|
4
|
+
// src/contract/lift.ts
|
|
5
|
+
const isMedia = Schema.is(Media);
|
|
6
|
+
const isMediaArray = Schema.is(Schema.Array(Media));
|
|
7
|
+
const kindOfUnsuspended = (ast) => kindOf(unsuspended(ast));
|
|
8
|
+
const wholeSuccessMediaOf = (suspended) => {
|
|
9
|
+
const ast = unsuspended(suspended);
|
|
10
|
+
const one = kindOf(ast);
|
|
11
|
+
if (one !== void 0) return {
|
|
12
|
+
kind: one,
|
|
13
|
+
many: false
|
|
14
|
+
};
|
|
15
|
+
if (!SchemaAST.isArrays(ast) || ast.encoding !== void 0) return;
|
|
16
|
+
const [kind, ...others] = new Set([...ast.elements, ...ast.rest].map(kindOfUnsuspended));
|
|
17
|
+
return kind === void 0 || others.length > 0 ? void 0 : {
|
|
18
|
+
kind,
|
|
19
|
+
many: true
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const mediaFieldOf = (field) => {
|
|
23
|
+
const optional = field.context?.isOptional === true;
|
|
24
|
+
const ast = unsuspended(field);
|
|
25
|
+
if (optional && SchemaAST.isUnion(ast) && ast.types.length === 2) {
|
|
26
|
+
const [definedMember, ...otherDefinedMembers] = ast.types.filter((member) => !SchemaAST.isUndefined(member));
|
|
27
|
+
const kind = definedMember === void 0 || otherDefinedMembers.length > 0 ? void 0 : kindOfUnsuspended(definedMember);
|
|
28
|
+
return kind === void 0 ? void 0 : {
|
|
29
|
+
kind,
|
|
30
|
+
many: false
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const whole = wholeSuccessMediaOf(ast);
|
|
34
|
+
return whole === void 0 || optional && whole.many ? void 0 : whole;
|
|
35
|
+
};
|
|
36
|
+
const liftOf = (success) => {
|
|
37
|
+
const ast = unsuspended(success.ast);
|
|
38
|
+
const whole = wholeSuccessMediaOf(ast);
|
|
39
|
+
if (whole !== void 0) return {
|
|
40
|
+
fields: [{
|
|
41
|
+
name: void 0,
|
|
42
|
+
...whole
|
|
43
|
+
}],
|
|
44
|
+
rest: void 0
|
|
45
|
+
};
|
|
46
|
+
if (!SchemaAST.isObjects(ast) || ast.encoding !== void 0) return {
|
|
47
|
+
fields: [],
|
|
48
|
+
rest: success
|
|
49
|
+
};
|
|
50
|
+
const fields = ast.propertySignatures.flatMap(({ name, type }) => {
|
|
51
|
+
const field = mediaFieldOf(type);
|
|
52
|
+
return field === void 0 ? [] : [{
|
|
53
|
+
name: String(name),
|
|
54
|
+
...field
|
|
55
|
+
}];
|
|
56
|
+
});
|
|
57
|
+
if (fields.length === 0) return {
|
|
58
|
+
fields,
|
|
59
|
+
rest: success
|
|
60
|
+
};
|
|
61
|
+
const names = new Set(fields.map(({ name }) => name));
|
|
62
|
+
const rest = ast.propertySignatures.filter(({ name }) => !names.has(name));
|
|
63
|
+
const { identifier: _identifierOfWholeSuccess, ...annotationsOfRest } = ast.annotations ?? {};
|
|
64
|
+
return {
|
|
65
|
+
fields,
|
|
66
|
+
rest: rest.length === 0 && ast.indexSignatures.length === 0 ? void 0 : Schema.make(new SchemaAST.Objects(rest, ast.indexSignatures, annotationsOfRest))
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const liftedFrom = (lift, success) => lift.fields.flatMap(({ name, kind, many }) => {
|
|
70
|
+
const field = name !== void 0 && Predicate.hasProperty(success, name) ? success[name] : void 0;
|
|
71
|
+
const value = name === void 0 ? success : field;
|
|
72
|
+
const listed = isMediaArray(value) ? value : [];
|
|
73
|
+
const single = isMedia(value) ? [value] : [];
|
|
74
|
+
return (many ? listed : single).map((media) => ({
|
|
75
|
+
kind,
|
|
76
|
+
field: name,
|
|
77
|
+
value: media
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
export { liftOf, liftedFrom };
|
package/dist/contract/log.mjs
CHANGED
|
@@ -100,7 +100,7 @@ const makeLogStore = (storage, { maxAge = defaultBounds.maxAge, maxEvents = defa
|
|
|
100
100
|
at: stored.at,
|
|
101
101
|
value: stored.logged
|
|
102
102
|
})),
|
|
103
|
-
|
|
103
|
+
from: cursorAt(epoch, after),
|
|
104
104
|
cursor: cursorAt(epoch, page.at(-1)?.[0] ?? after),
|
|
105
105
|
truncated,
|
|
106
106
|
hasMore: pending.length > limit
|
|
@@ -2,8 +2,9 @@ import { Schema, SchemaAST } from "effect";
|
|
|
2
2
|
/**
|
|
3
3
|
* An image, a media field of a success: `{ data: Uint8Array, mimeType: string }`, `mimeType` such
|
|
4
4
|
* as `image/png`. A top-level field of a struct success, one, optional, or a required array, or the
|
|
5
|
-
* whole success, one or an array: an MCP tool lifts it into an image block of its own,
|
|
6
|
-
* surface sends it as JSON, the bytes in
|
|
5
|
+
* whole success, one or an array: an MCP tool lifts it into an image block of its own, a toolkit tool
|
|
6
|
+
* into a file part of what its model reads, and every other surface sends it as JSON, the bytes in
|
|
7
|
+
* base64. `ActionMcp` refuses it anywhere else, and a toolkit sends it there in the JSON.
|
|
7
8
|
*
|
|
8
9
|
* **Gotchas**
|
|
9
10
|
*
|
package/dist/contract/media.mjs
CHANGED
|
@@ -8,8 +8,9 @@ const Media = Schema.Struct({
|
|
|
8
8
|
/**
|
|
9
9
|
* An image, a media field of a success: `{ data: Uint8Array, mimeType: string }`, `mimeType` such
|
|
10
10
|
* as `image/png`. A top-level field of a struct success, one, optional, or a required array, or the
|
|
11
|
-
* whole success, one or an array: an MCP tool lifts it into an image block of its own,
|
|
12
|
-
* surface sends it as JSON, the bytes in
|
|
11
|
+
* whole success, one or an array: an MCP tool lifts it into an image block of its own, a toolkit tool
|
|
12
|
+
* into a file part of what its model reads, and every other surface sends it as JSON, the bytes in
|
|
13
|
+
* base64. `ActionMcp` refuses it anywhere else, and a toolkit sends it there in the JSON.
|
|
13
14
|
*
|
|
14
15
|
* **Gotchas**
|
|
15
16
|
*
|
package/dist/contract/push.mjs
CHANGED
|
@@ -4,10 +4,6 @@ import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
|
|
|
4
4
|
import { defaultNextPoll } from "./feed.mjs";
|
|
5
5
|
import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "effect";
|
|
6
6
|
// src/contract/push.ts
|
|
7
|
-
/**
|
|
8
|
-
* A push subscription read on through a failure no refusal explains, such as an upstream's
|
|
9
|
-
* outage: its cause is logged and reported, and reading resumes from the position reached.
|
|
10
|
-
*/
|
|
11
7
|
const Failed = Schema.TaggedStruct("Failed", {});
|
|
12
8
|
const PushedOf = (event) => Schema.Union([
|
|
13
9
|
OccurrenceOf(event),
|
|
@@ -21,7 +17,7 @@ const subscriptionWith = (input) => Schema.Struct({
|
|
|
21
17
|
});
|
|
22
18
|
const SubscriptionOf = (event) => subscriptionWith(event.input);
|
|
23
19
|
const Subscription = subscriptionWith(Schema.Json);
|
|
24
|
-
const
|
|
20
|
+
const defaultCapacity = 16;
|
|
25
21
|
const heartbeatEvery = Duration.seconds(30);
|
|
26
22
|
const isFailed = Schema.is(Failed);
|
|
27
23
|
const readOn = (surface, name) => (sent) => sent.pipe(Stream.mapEffect((element) => isFailed(element) ? Effect.as(Effect.logWarning(`${surface} event "${name}" failed to read, and resumes`), []) : Effect.succeed([element])), Stream.flattenIterable);
|
|
@@ -34,7 +30,7 @@ const polledOn = (surface, name) => (poll) => (cursor) => Effect.catchCauseIf(po
|
|
|
34
30
|
hasMore: false,
|
|
35
31
|
nextPoll: defaultNextPoll
|
|
36
32
|
}));
|
|
37
|
-
const pushed = (open, cursor, deliver, { resumesUnconfirmed = false,
|
|
33
|
+
const pushed = (open, cursor, deliver, { resumesUnconfirmed = false, positions }) => Effect.gen(function* () {
|
|
38
34
|
const confirmed = yield* Latch.make();
|
|
39
35
|
let reached = cursor;
|
|
40
36
|
let active = false;
|
|
@@ -50,7 +46,7 @@ const pushed = (open, cursor, deliver, { resumesUnconfirmed = false, inOrder = f
|
|
|
50
46
|
Checked: (checked) => {
|
|
51
47
|
if (!active) return sent(checked, checked.cursor);
|
|
52
48
|
if (checked.cursor === null || checked.cursor === reached) return Effect.void;
|
|
53
|
-
return
|
|
49
|
+
return positions === "watermark" ? sent(checked, checked.cursor) : movedTo(checked.cursor);
|
|
54
50
|
},
|
|
55
51
|
Occurrence: (occurrence) => Effect.andThen(active ? Effect.void : sent(Checked.make({ cursor: reached }), reached), Effect.suspend(() => sent(occurrence, occurrence.cursor ?? reached)))
|
|
56
52
|
});
|
|
@@ -60,13 +56,13 @@ const pushed = (open, cursor, deliver, { resumesUnconfirmed = false, inOrder = f
|
|
|
60
56
|
});
|
|
61
57
|
const once = Stream.suspend(() => Duration.isZero(wait) ? open(reached) : Stream.unwrap(Effect.as(Effect.sleep(wait), open(reached)))).pipe(Stream.runForEach(delivered), Effect.catchCauseIf(resumes, (cause) => Effect.andThen(reported(cause), deliver(Failed.make({})))), Effect.andThen(waiting));
|
|
62
58
|
const heartbeat = Effect.andThen(confirmed.await, Effect.forever(Effect.andThen(Effect.sleep(heartbeatEvery), () => Effect.suspend(() => deliver(Checked.make({ cursor: reached }))))));
|
|
63
|
-
return yield*
|
|
59
|
+
return yield* positions === "watermark" ? Effect.forever(once) : Effect.raceFirst(Effect.forever(once), heartbeat);
|
|
64
60
|
});
|
|
65
|
-
const queuedPush = (open, cursor, encode, { ending,
|
|
61
|
+
const queuedPush = (open, cursor, encode, { ending, positions, capacity = defaultCapacity }) => Effect.gen(function* () {
|
|
66
62
|
const queue = yield* Queue.bounded(capacity);
|
|
67
63
|
yield* pushed(open, cursor, (sent) => Effect.flatMap(encode(sent), (element) => Queue.offer(queue, element)), {
|
|
68
64
|
resumesUnconfirmed: true,
|
|
69
|
-
|
|
65
|
+
positions
|
|
70
66
|
}).pipe(ending, Queue.into(queue), Effect.forkScoped({ startImmediately: true }));
|
|
71
67
|
return queue;
|
|
72
68
|
});
|
package/dist/contract/status.mjs
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { SchemaAST } from "effect";
|
|
1
|
+
import { Predicate, SchemaAST } from "effect";
|
|
2
2
|
// src/contract/status.ts
|
|
3
|
-
const
|
|
3
|
+
const statusAnnotationsOf = (node) => {
|
|
4
|
+
for (const check of (node.checks ?? []).toReversed()) {
|
|
5
|
+
if (Predicate.hasProperty(check.annotations, "httpApiStatus")) return check.annotations;
|
|
6
|
+
const grouped = check._tag === "FilterGroup" ? statusAnnotationsOf(check) : void 0;
|
|
7
|
+
if (grouped !== void 0) return grouped;
|
|
8
|
+
}
|
|
9
|
+
return Predicate.hasProperty(node.annotations, "httpApiStatus") ? node.annotations : void 0;
|
|
10
|
+
};
|
|
11
|
+
const httpApiStatusOf = (ast) => {
|
|
12
|
+
const status = (statusAnnotationsOf(ast) ?? ast.context?.annotations)?.["httpApiStatus"];
|
|
13
|
+
return Predicate.isNumber(status) ? status : void 0;
|
|
14
|
+
};
|
|
4
15
|
const transientStatuses = /* @__PURE__ */ new Set([
|
|
5
16
|
408,
|
|
6
17
|
429,
|
|
@@ -17,10 +17,6 @@ const WebhookCancellationOf = (event) => Schema.Struct({
|
|
|
17
17
|
input: event.input,
|
|
18
18
|
delivery: WebhookTarget
|
|
19
19
|
});
|
|
20
|
-
/**
|
|
21
|
-
* How a webhook subscription's deliveries are going, as a refresh answers it: whether it is
|
|
22
|
-
* delivering, when it last delivered, and the category of its last failure, since when it fails.
|
|
23
|
-
*/
|
|
24
20
|
const DeliveryStatus = Schema.Struct({
|
|
25
21
|
active: Schema.Boolean,
|
|
26
22
|
lastDeliveryAt: Schema.NullOr(Schema.String),
|
package/dist/http/events.d.mts
CHANGED
|
@@ -20,11 +20,11 @@ export declare const pageOf: <E extends Any>(event: E) => Schema.encodeKeys<Sche
|
|
|
20
20
|
}>, {
|
|
21
21
|
readonly nextPoll: "nextPollMs";
|
|
22
22
|
}>;
|
|
23
|
-
export declare const sentOf: <E extends Any>(event: E) => HttpApiSchema.StreamSse<HttpApiSchema.SseEventFromData<Schema.
|
|
23
|
+
export declare const sentOf: <E extends Any>(event: E) => HttpApiSchema.StreamSse<HttpApiSchema.SseEventFromData<Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
|
|
24
24
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
25
25
|
}>, Schema.TaggedStruct<"Checked", {
|
|
26
26
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
27
|
-
}>, Schema.TaggedStruct<"Failed", {}>]
|
|
27
|
+
}>, Schema.TaggedStruct<"Failed", {}>]>>, Schema.Union<readonly [typeof Unauthenticated, typeof Forbidden]>, {
|
|
28
28
|
readonly _tag: "Gap";
|
|
29
29
|
readonly cursor: string | null;
|
|
30
30
|
} | {
|
package/dist/http/events.mjs
CHANGED
|
@@ -19,7 +19,7 @@ const pageOf = (event) => Schema.Struct({
|
|
|
19
19
|
nextPoll: Schema.DurationFromMillis
|
|
20
20
|
}).pipe(Schema.encodeKeys({ nextPoll: "nextPollMs" }));
|
|
21
21
|
const sentOf = (event) => HttpApiSchema.StreamSse({
|
|
22
|
-
data:
|
|
22
|
+
data: PushedOf(event),
|
|
23
23
|
error: Refusal
|
|
24
24
|
});
|
|
25
25
|
const servedSent = HttpApiSchema.StreamSse({
|
|
@@ -64,7 +64,10 @@ const answering = (feed, authentication) => {
|
|
|
64
64
|
return ({ payload: { input, cursor } }) => Effect.gen(function* () {
|
|
65
65
|
if (((yield* HttpServerRequest.HttpServerRequest).headers["accept"] ?? "").includes("text/event-stream")) {
|
|
66
66
|
const open = yield* feed.stream(input);
|
|
67
|
-
return Stream.fromQueue(yield* queuedPush(open, cursor, encode, {
|
|
67
|
+
return Stream.fromQueue(yield* queuedPush(open, cursor, encode, {
|
|
68
|
+
ending: Function.identity,
|
|
69
|
+
positions: "heartbeat"
|
|
70
|
+
}));
|
|
68
71
|
}
|
|
69
72
|
const subscriber = yield* principalOf(feed.event, authentication);
|
|
70
73
|
return yield* feed.poll(input, cursor, { subscriber });
|
package/dist/mcp/bridge.mjs
CHANGED
|
@@ -10,10 +10,10 @@ import { pushed, refusalIn } from "../contract/push.mjs";
|
|
|
10
10
|
import { promote } from "../authentication/provider.mjs";
|
|
11
11
|
import { recordStepUp } from "../authentication/refusal.mjs";
|
|
12
12
|
import { Active, EventsError, Failed, Heartbeat, Notifications, Occurred, Requests, Terminated, codes, extension, subscriptionIdKey } from "./events.mjs";
|
|
13
|
-
import { isObjectSchema,
|
|
13
|
+
import { isObjectSchema, toolJsonSchema } from "./protocol.mjs";
|
|
14
14
|
import { Cause, Context, Duration, Effect, Exit, Match, Option, Predicate, Result, Schema } from "effect";
|
|
15
15
|
import { HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
16
|
-
import { McpSchema } from "effect/ai";
|
|
16
|
+
import { McpSchema, McpServer } from "effect/ai";
|
|
17
17
|
// src/mcp/bridge.ts
|
|
18
18
|
const isGroup = (u) => Predicate.isObjectKeyword(u) && "merge" in u && Predicate.isFunction(u.merge) && "requests" in u && u.requests instanceof Map;
|
|
19
19
|
const groupOf = (adapter, key) => {
|
|
@@ -47,7 +47,11 @@ const headerMismatch = (request) => Effect.andThen(HttpEffect.appendPreResponseH
|
|
|
47
47
|
code: codes.headerMismatch,
|
|
48
48
|
message: "Mcp-Name header does not match request parameters"
|
|
49
49
|
})));
|
|
50
|
-
const routedTo = (name) => Effect.flatMap(Effect.serviceOption(HttpServerRequest.HttpServerRequest), (request) =>
|
|
50
|
+
const routedTo = (name) => Effect.flatMap(Effect.serviceOption(HttpServerRequest.HttpServerRequest), (request) => {
|
|
51
|
+
if (Option.isNone(request)) return Effect.void;
|
|
52
|
+
const sent = request.value.headers["mcp-name"];
|
|
53
|
+
return sent !== void 0 && McpServer.decodeNameHeader(sent) === name ? Effect.void : headerMismatch(request.value);
|
|
54
|
+
});
|
|
51
55
|
const servedOf = (feed, delivery) => {
|
|
52
56
|
const { event } = feed;
|
|
53
57
|
const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(event.input), inputParseOptions);
|
|
@@ -195,7 +199,7 @@ const withEvents = (base, serving) => {
|
|
|
195
199
|
requestId,
|
|
196
200
|
wire,
|
|
197
201
|
_meta: yield* meta
|
|
198
|
-
}, (deliver) => asSubscriber(feed.event, Effect.flatMap(feed.stream(input), (open) => pushed(open, cursor ?? null, deliver))));
|
|
202
|
+
}, (deliver) => asSubscriber(feed.event, Effect.flatMap(feed.stream(input), (open) => pushed(open, cursor ?? null, deliver, { positions: "heartbeat" }))));
|
|
199
203
|
}).pipe(fromBuilt),
|
|
200
204
|
"events/subscribe": ({ name, arguments: args, delivery: { url, secret }, cursor, ttlMs }) => Effect.gen(function* () {
|
|
201
205
|
yield* routedTo(name);
|
package/dist/mcp/client.mjs
CHANGED
|
@@ -5,9 +5,10 @@ import { assertOnce } from "../contract/names.mjs";
|
|
|
5
5
|
import { progressSink } from "../contract/progress.mjs";
|
|
6
6
|
import { elementOf } from "../contract/stream.mjs";
|
|
7
7
|
import { checked, checkedStream, sendingJson, watchInput } from "../contract/call.mjs";
|
|
8
|
+
import { liftOf } from "../contract/lift.mjs";
|
|
8
9
|
import { split } from "../contract/listed.mjs";
|
|
9
10
|
import { watching } from "../contract/watch.mjs";
|
|
10
|
-
import { defaultPath,
|
|
11
|
+
import { defaultPath, unliftedFrom } from "./protocol.mjs";
|
|
11
12
|
import { NoReply, NoStructuredContent, ProtocolError, StatusError, UndeclaredError, bodyOf, callError, failWith } from "./reply.mjs";
|
|
12
13
|
import { request } from "./request.mjs";
|
|
13
14
|
import { transportOf } from "./watch.mjs";
|