@gjermundgaraba/effect-actions 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -43
- package/dist/Action.d.mts +31 -118
- package/dist/Action.mjs +15 -53
- package/dist/ActionCli.d.mts +60 -28
- package/dist/ActionCli.mjs +54 -48
- package/dist/ActionHttp.d.mts +18 -67
- package/dist/ActionHttp.mjs +20 -70
- package/dist/ActionMcp.d.mts +25 -31
- package/dist/ActionMcp.mjs +140 -74
- package/dist/ActionRpc.d.mts +147 -0
- package/dist/ActionRpc.mjs +113 -0
- package/dist/ActionToolkit.d.mts +5 -8
- package/dist/ActionToolkit.mjs +3 -3
- package/dist/Authentication.d.mts +15 -15
- package/dist/Authentication.mjs +42 -96
- package/dist/Testing.d.mts +32 -25
- package/dist/Testing.mjs +45 -30
- package/dist/{internal/authentication.d.mts → authentication/provider.d.mts} +41 -9
- package/dist/authentication/provider.mjs +12 -0
- package/dist/authentication/refusal.mjs +36 -0
- package/dist/{internal/cli.d.mts → cli/commands.d.mts} +16 -12
- package/dist/cli/commands.mjs +302 -0
- package/dist/{internal → contract}/call.d.mts +2 -2
- package/dist/contract/call.mjs +10 -0
- package/dist/{internal → contract}/errors.d.mts +13 -10
- package/dist/{internal → contract}/errors.mjs +9 -14
- package/dist/{internal → contract}/implementation.d.mts +37 -21
- package/dist/{internal → contract}/implementation.mjs +18 -49
- package/dist/contract/media.d.mts +13 -0
- package/dist/contract/media.mjs +18 -0
- package/dist/contract/rules.d.mts +25 -0
- package/dist/{internal/actions.mjs → contract/rules.mjs} +6 -42
- package/dist/{internal → http}/client.d.mts +7 -9
- package/dist/http/client.mjs +17 -0
- package/dist/http/declared.mjs +20 -0
- package/dist/http/schema-errors.mjs +9 -0
- package/dist/mcp/protocol.d.mts +17 -0
- package/dist/mcp/protocol.mjs +149 -0
- package/dist/stdio/console.mjs +64 -0
- package/dist/{internal → testing}/memory.d.mts +1 -1
- package/dist/{internal → testing}/memory.mjs +5 -17
- package/dist/toolkit/tools.mjs +29 -0
- package/docs/Action-failures.md +47 -0
- package/docs/Action-in-process.md +93 -0
- package/docs/Action.md +206 -424
- package/docs/ActionCli-failures.md +102 -0
- package/docs/ActionCli.md +206 -292
- package/docs/ActionHttp-failures.md +83 -0
- package/docs/ActionHttp.md +202 -281
- package/docs/ActionMcp-failures.md +31 -0
- package/docs/ActionMcp.md +229 -193
- package/docs/ActionRpc-failures.md +21 -0
- package/docs/ActionRpc.md +178 -0
- package/docs/ActionToolkit-failures.md +15 -0
- package/docs/ActionToolkit.md +100 -117
- package/docs/Authentication-advanced.md +139 -0
- package/docs/Authentication-failures.md +99 -0
- package/docs/Authentication.md +142 -392
- package/docs/CONTEXT.md +39 -23
- package/docs/README.md +71 -35
- package/docs/Testing-failures.md +20 -0
- package/docs/Testing.md +186 -151
- package/docs/guarantees.md +35 -95
- package/docs/setup-failures.md +34 -0
- package/docs/setup.md +88 -87
- package/examples/README.md +68 -0
- package/examples/assistant/README.md +92 -0
- package/examples/assistant/src/agent.ts +92 -0
- package/examples/assistant/src/cli.ts +34 -0
- package/examples/assistant/src/commands.ts +25 -0
- package/examples/assistant/src/identity/Identity.ts +33 -0
- package/examples/assistant/src/identity/authorize.ts +24 -0
- package/examples/assistant/src/identity/handlers.ts +10 -0
- package/examples/assistant/src/identity/members.ts +9 -0
- package/examples/assistant/src/identity/permissions.ts +23 -0
- package/examples/assistant/src/scripted.ts +23 -0
- package/examples/assistant/src/tasks/Tasks.ts +63 -0
- package/examples/assistant/src/tasks/handlers.ts +25 -0
- package/examples/assistant/src/tasks/store.ts +96 -0
- package/examples/assistant/src/toolkit.ts +30 -0
- package/examples/assistant/test/commands.test.ts +57 -0
- package/examples/assistant/test/identity/identity.test.ts +43 -0
- package/examples/assistant/test/tasks/store.test.ts +48 -0
- package/examples/assistant/test/tasks/tasks.test.ts +75 -0
- package/examples/assistant/test/toolkit.test.ts +121 -0
- package/examples/kitchen-sink/README.md +317 -0
- package/examples/kitchen-sink/src/Actions.ts +19 -0
- package/examples/kitchen-sink/src/Api.ts +24 -0
- package/examples/kitchen-sink/src/Rpc.ts +12 -0
- package/examples/kitchen-sink/src/admin/Admin.ts +59 -0
- package/examples/kitchen-sink/src/admin/authenticate.ts +18 -0
- package/examples/kitchen-sink/src/admin/authorize.ts +27 -0
- package/examples/kitchen-sink/src/admin/grants.ts +22 -0
- package/examples/kitchen-sink/src/admin/handlers.ts +21 -0
- package/examples/kitchen-sink/src/admin/keys.ts +8 -0
- package/examples/kitchen-sink/src/agent.ts +47 -0
- package/examples/kitchen-sink/src/assistant/Assistant.ts +82 -0
- package/examples/kitchen-sink/src/assistant/conversations.ts +71 -0
- package/examples/kitchen-sink/src/assistant/demo-model.ts +33 -0
- package/examples/kitchen-sink/src/assistant/handlers.ts +146 -0
- package/examples/kitchen-sink/src/attachments/Attachments.ts +48 -0
- package/examples/kitchen-sink/src/attachments/download.ts +49 -0
- package/examples/kitchen-sink/src/attachments/handlers.ts +38 -0
- package/examples/kitchen-sink/src/attachments/store.ts +58 -0
- package/examples/kitchen-sink/src/browser.ts +33 -0
- package/examples/kitchen-sink/src/cli.ts +85 -0
- package/examples/kitchen-sink/src/config.ts +18 -0
- package/examples/kitchen-sink/src/identity/Identity.ts +61 -0
- package/examples/kitchen-sink/src/identity/authenticate.ts +87 -0
- package/examples/kitchen-sink/src/identity/authorize.ts +16 -0
- package/examples/kitchen-sink/src/identity/directory.ts +52 -0
- package/examples/kitchen-sink/src/identity/handlers.ts +9 -0
- package/examples/kitchen-sink/src/identity/members.ts +13 -0
- package/examples/kitchen-sink/src/identity/quota.ts +62 -0
- package/examples/kitchen-sink/src/issues/Issues.ts +109 -0
- package/examples/kitchen-sink/src/issues/assistant.ts +23 -0
- package/examples/kitchen-sink/src/issues/guide.ts +37 -0
- package/examples/kitchen-sink/src/issues/handlers.ts +37 -0
- package/examples/kitchen-sink/src/issues/store.ts +96 -0
- package/examples/kitchen-sink/src/issues/write-limit.ts +41 -0
- package/examples/kitchen-sink/src/memory.ts +30 -0
- package/examples/kitchen-sink/src/ops.ts +42 -0
- package/examples/kitchen-sink/src/request-policy.ts +63 -0
- package/examples/kitchen-sink/src/routes.ts +120 -0
- package/examples/kitchen-sink/src/sdk.ts +46 -0
- package/examples/kitchen-sink/src/seed.ts +65 -0
- package/examples/kitchen-sink/src/server.ts +62 -0
- package/examples/kitchen-sink/src/stdio.ts +34 -0
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +28 -0
- package/examples/kitchen-sink/src/workspaces/handlers.ts +23 -0
- package/examples/kitchen-sink/src/workspaces/registry.ts +46 -0
- package/examples/kitchen-sink/src/workspaces/tenant.ts +17 -0
- package/examples/kitchen-sink/test/admin/admin.test.ts +67 -0
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +435 -0
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +161 -0
- package/examples/kitchen-sink/test/identity/identity.test.ts +137 -0
- package/examples/kitchen-sink/test/identity/session.test.ts +110 -0
- package/examples/kitchen-sink/test/issues/assistant.test.ts +75 -0
- package/examples/kitchen-sink/test/issues/issues.test.ts +135 -0
- package/examples/kitchen-sink/test/request-policy.test.ts +125 -0
- package/examples/kitchen-sink/test/routes.test.ts +123 -0
- package/examples/kitchen-sink/test/support/scripted.ts +40 -0
- package/examples/live-rpc/README.md +107 -0
- package/examples/live-rpc/src/Rpc.ts +8 -0
- package/examples/live-rpc/src/browser.ts +98 -0
- package/examples/live-rpc/src/chat/Chat.ts +75 -0
- package/examples/live-rpc/src/chat/authorize.ts +16 -0
- package/examples/live-rpc/src/chat/handlers.ts +50 -0
- package/examples/live-rpc/src/chat/room.ts +23 -0
- package/examples/live-rpc/src/chat/store.ts +54 -0
- package/examples/live-rpc/src/client.ts +37 -0
- package/examples/live-rpc/src/identity/Identity.ts +19 -0
- package/examples/live-rpc/src/identity/members.ts +8 -0
- package/examples/live-rpc/src/identity/verifier.ts +23 -0
- package/examples/live-rpc/src/routes.ts +22 -0
- package/examples/live-rpc/src/server.ts +43 -0
- package/examples/live-rpc/test/browser.test.ts +105 -0
- package/examples/live-rpc/test/chat/chat.test.ts +69 -0
- package/examples/live-rpc/test/routes.test.ts +99 -0
- package/examples/live-rpc/test/server.test.ts +75 -0
- package/examples/mcp-tools/README.md +136 -0
- package/examples/mcp-tools/src/instructions.ts +12 -0
- package/examples/mcp-tools/src/printers/Printers.ts +119 -0
- package/examples/mcp-tools/src/printers/fake.ts +115 -0
- package/examples/mcp-tools/src/printers/farm.ts +136 -0
- package/examples/mcp-tools/src/printers/handlers.ts +29 -0
- package/examples/mcp-tools/src/routes.ts +52 -0
- package/examples/mcp-tools/src/server.ts +30 -0
- package/examples/mcp-tools/src/stdio.ts +26 -0
- package/examples/mcp-tools/test/printers/printers.test.ts +189 -0
- package/examples/mcp-tools/test/routes.test.ts +202 -0
- package/examples/notes-service/README.md +108 -0
- package/examples/notes-service/src/Api.ts +13 -0
- package/examples/notes-service/src/browser.ts +41 -0
- package/examples/notes-service/src/cli.ts +22 -0
- package/examples/notes-service/src/commands.ts +89 -0
- package/examples/notes-service/src/identity/Identity.ts +31 -0
- package/examples/notes-service/src/identity/authorize.ts +18 -0
- package/examples/notes-service/src/identity/handlers.ts +10 -0
- package/examples/notes-service/src/identity/users.ts +9 -0
- package/examples/notes-service/src/identity/verifier.ts +36 -0
- package/examples/notes-service/src/notes/Notes.ts +91 -0
- package/examples/notes-service/src/notes/handlers.ts +33 -0
- package/examples/notes-service/src/notes/store.ts +73 -0
- package/examples/notes-service/src/routes.ts +45 -0
- package/examples/notes-service/src/server.ts +26 -0
- package/examples/notes-service/src/status/Status.ts +10 -0
- package/examples/notes-service/src/status/handlers.ts +14 -0
- package/examples/notes-service/src/stdio.ts +25 -0
- package/examples/notes-service/test/commands.test.ts +134 -0
- package/examples/notes-service/test/notes/notes.test.ts +103 -0
- package/examples/notes-service/test/routes.test.ts +84 -0
- package/examples/quickstart/README.md +31 -0
- package/examples/quickstart/src/Api.ts +5 -0
- package/examples/quickstart/src/client.ts +13 -0
- package/examples/quickstart/src/greeting/Greeting.ts +12 -0
- package/examples/quickstart/src/greeting/handlers.ts +6 -0
- package/examples/quickstart/src/routes.ts +11 -0
- package/examples/quickstart/src/server.ts +16 -0
- package/examples/quickstart/test/greeting/greeting.test.ts +18 -0
- package/package.json +32 -14
- package/dist/internal/actions.d.mts +0 -9
- package/dist/internal/authentication.mjs +0 -11
- package/dist/internal/call.mjs +0 -12
- package/dist/internal/cli.mjs +0 -328
- package/dist/internal/client.mjs +0 -25
- package/dist/internal/console.mjs +0 -77
- package/dist/internal/declared.d.mts +0 -13
- package/dist/internal/declared.mjs +0 -34
- package/dist/internal/mcp.d.mts +0 -11
- package/dist/internal/mcp.mjs +0 -52
- package/dist/internal/refusal.mjs +0 -67
- package/dist/internal/schema-errors.mjs +0 -20
- package/dist/internal/tools.mjs +0 -44
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# ActionCli failure modes
|
|
2
|
+
|
|
3
|
+
What you see when something is wrong, and the fix. Search for a fragment of the message.
|
|
4
|
+
The tasks are in [ActionCli.md](ActionCli.md).
|
|
5
|
+
|
|
6
|
+
## Flags and input
|
|
7
|
+
|
|
8
|
+
- `Unrecognized flag: --<field> in command …` for an input field: a field listed in `positional`
|
|
9
|
+
has no flag. Pass its value as an argument.
|
|
10
|
+
- `Missing value for flag --<flag>`, or `Unrecognized flag: -x`, for a value starting with `-`:
|
|
11
|
+
Effect's parser reads a value written apart from its flag as a flag itself when it starts with
|
|
12
|
+
`-`, `-` alone and a number such as `-5` excepted: `--note -x` is a missing value, and
|
|
13
|
+
`--note --help` prints help. Write `--<flag>=<value>`; `--` does not help, since what follows
|
|
14
|
+
it is positional.
|
|
15
|
+
- `InvalidInput` naming an unexpected key: `--input` or a flag's JSON holds a field the schema
|
|
16
|
+
does not declare, such as a misspelling.
|
|
17
|
+
- `InvalidInput` from a command whose input is not a struct, run without `--input`: the schema
|
|
18
|
+
rejects the default `{}`. Pass `--input`.
|
|
19
|
+
- `InvalidInput` for a flag's value that looks right: a flag takes the encoded value, and reads
|
|
20
|
+
its text as JSON when the field accepts that kind of JSON value. Quote a string that reads as
|
|
21
|
+
JSON: `--id '"123"'` for a `String | Number` field. Malformed JSON is taken as text.
|
|
22
|
+
- A command with a `stdin` field waits without output: nothing closes stdin, such as a parent
|
|
23
|
+
process holding the pipe, or `ssh` run without `-n`. Pipe the value in, or redirect stdin from
|
|
24
|
+
a file or `/dev/null`.
|
|
25
|
+
|
|
26
|
+
## Thrown when a command is built
|
|
27
|
+
|
|
28
|
+
- `Required positional argument after an optional one: <field>`, or
|
|
29
|
+
`Repeated positional argument before another one: <field>`: `positional` lists every required
|
|
30
|
+
field before any optional one, and an array field last.
|
|
31
|
+
- `Not an input field: <field>`: `positional` names no field of the input.
|
|
32
|
+
- `Not a flag's input field: <field>`: an `aliases` key names a field that is positional, read
|
|
33
|
+
from stdin, or no field.
|
|
34
|
+
- `Not a required input field: <field>`: `stdin` names an optional field, or no field.
|
|
35
|
+
- `Positional arguments need named input fields`, `Aliases need named input fields: <fields>`, or
|
|
36
|
+
`Stdin needs named input fields: <field>`: the action's input is not a struct.
|
|
37
|
+
- `Duplicate flag: --<name>, claimed by ...`: two flags of one command share a name, such as two
|
|
38
|
+
fields with one kebab-case name (`userId`, `user_id`), a `json` field beside `render`'s
|
|
39
|
+
`--json`, or an alias another flag's name or alias takes. Rename the field or the alias, or
|
|
40
|
+
drop `render`. A field named like a global flag (`help`, `version`, `log-level`) is not a
|
|
41
|
+
clash: its flag shadows the global one on that command.
|
|
42
|
+
- `Duplicate command: <name>, claimed by action ... and action ...`: two actions of an aggregate
|
|
43
|
+
have the same kebab-case name. Give one a `name` in `commands`, or use separate aggregates.
|
|
44
|
+
- `Duplicate command: <name>, claimed by action ... and subcommands`: a command passed in
|
|
45
|
+
`subcommands` has a derived command's name. Rename either.
|
|
46
|
+
- `Unknown commands: <keys>`: a `commands` key names no action. Use the action's own name, not
|
|
47
|
+
its kebab-case command name.
|
|
48
|
+
- `Listed in actions, but no implementation holds it: <names>`, or
|
|
49
|
+
`but the binding does not hold it`: `actions` lists a contract that the implementations, or the
|
|
50
|
+
binding, do not hold, by identity. `(another contract)` marks one whose name they hold, as a
|
|
51
|
+
second copy of the contracts module makes. List the contract they implement or bind.
|
|
52
|
+
- `Action "x" has no implementation here`, or a type error at `command`: no implementation passed
|
|
53
|
+
has that contract. Pass the implementation, and select with the exact contract value it
|
|
54
|
+
implements; an equal-looking action does not match.
|
|
55
|
+
- `Action "x" is not in this HTTP binding`, or a type error at `remoteCommand`: the action was not
|
|
56
|
+
passed to this binding's `ActionHttp.make`. Select with the exact contract value it received.
|
|
57
|
+
|
|
58
|
+
## Types
|
|
59
|
+
|
|
60
|
+
- An argument of type `Binding<…>` not assignable at `make` or `command`, an implementation not
|
|
61
|
+
assignable at `remote` or `remoteCommand`, or `client` refused at `make` or `command`: `make`
|
|
62
|
+
and `command` take implementations; `remote` and `remoteCommand` take a binding, and alone take
|
|
63
|
+
`client`. To choose by a condition, build a command from each:
|
|
64
|
+
`remotely ? ActionCli.remote(Http, options) : ActionCli.make(users, options)`.
|
|
65
|
+
- `Type 'HttpClient' is not assignable to type 'never'` in the pipe that runs a remote command:
|
|
66
|
+
provide `NodeHttpClient.layerUndici` (or `FetchHttpClient.layer`).
|
|
67
|
+
- A local command requires an identity service no handler yields: its action is protected, and
|
|
68
|
+
requires the identity its contract declares. Provide it on the command
|
|
69
|
+
([Name the caller](ActionCli.md#name-the-caller)); do not make the contract public to satisfy
|
|
70
|
+
the requirement.
|
|
71
|
+
- Type error at `Effect.catchTag("UserNotFound", ...)` after `Command.run`: a command fails with
|
|
72
|
+
`UserError`. Use `Effect.catchReason("UserError", "UserNotFound", ...)`.
|
|
73
|
+
- Type error at `Effect.catchReason("UserError", "<Tag>", ...)`, its tag typed `never`: a failure
|
|
74
|
+
of the command has no `_tag`, such as a builder's plain `Error`. Fail with a tagged error, such
|
|
75
|
+
as a `Schema.TaggedError` or `Data.TaggedError`.
|
|
76
|
+
|
|
77
|
+
## Running
|
|
78
|
+
|
|
79
|
+
- `--help` or a mistyped flag connects to a database, or fails reading config: services provided
|
|
80
|
+
around `Command.run` are built before parsing. Provide them on the command,
|
|
81
|
+
`Command.provide(layer)`.
|
|
82
|
+
- `ERROR (#n): ConfigError: SchemaError(Expected string at ["NOTES_TOKEN"])` from a public
|
|
83
|
+
command, exit 1, on stdout, or on stderr under `logToStderr`: the client provided on the
|
|
84
|
+
command requires a token, and a failure of what a command is provided is `runMain`'s report,
|
|
85
|
+
not the command's JSON. Read the token with `Config.option` and add the header only when it is
|
|
86
|
+
there. Where every command needs it, keep it required and map the failure, in the Effect that
|
|
87
|
+
provides the client, to `new CliError.UserError({ cause, userMessage })`:
|
|
88
|
+
[notes-service/src/commands.ts](../examples/notes-service/src/commands.ts).
|
|
89
|
+
- `HttpClientError` whose `reason._tag` is `InvalidUrlError`, from a remote command: its client
|
|
90
|
+
has no `baseUrl` and prepends no URL.
|
|
91
|
+
- 401 `Unauthenticated` from a remote command: a remote command adds no headers of its own. Add
|
|
92
|
+
credentials in `client`'s `transformClient`, or on the `HttpClient` the command is provided.
|
|
93
|
+
- Another command's request goes to the API's URL, or carries its token: an `HttpClient`
|
|
94
|
+
configured around the whole program rewrites every request the program makes. Configure it in
|
|
95
|
+
the `client` option, or provide it on the remote command alone.
|
|
96
|
+
- A report with a stack on stdout, `ERROR (#1): ...`, instead of JSON on stderr: a defect, or a
|
|
97
|
+
failure of a layer the host provides, which `runMain` reports. Fix the defect; apply
|
|
98
|
+
`ActionCli.logToStderr` to keep such reports off stdout.
|
|
99
|
+
- `ERROR (#n)` with a stack for a declared error, such as `UserNotFound`, from a command built
|
|
100
|
+
with `Command.make`: a command of your own that calls `Action.client` or `ActionHttp.client`
|
|
101
|
+
fails with the action's own error. Pipe the command's whole Effect through
|
|
102
|
+
`ActionCli.toUserError`, given the binding or the actions it calls, or derive the command with `ActionCli.command`.
|