@workel/mcp 0.1.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 +152 -0
- package/dist/api/client.d.ts +126 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +313 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/errors.d.ts +142 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +262 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/mapping.d.ts +147 -0
- package/dist/api/mapping.d.ts.map +1 -0
- package/dist/api/mapping.js +248 -0
- package/dist/api/mapping.js.map +1 -0
- package/dist/api/redact.d.ts +54 -0
- package/dist/api/redact.d.ts.map +1 -0
- package/dist/api/redact.js +193 -0
- package/dist/api/redact.js.map +1 -0
- package/dist/api/types.d.ts +155 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +18 -0
- package/dist/api/types.js.map +1 -0
- package/dist/boot.d.ts +129 -0
- package/dist/boot.d.ts.map +1 -0
- package/dist/boot.js +245 -0
- package/dist/boot.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +77 -0
- package/dist/config.js.map +1 -0
- package/dist/doctor.d.ts +42 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +94 -0
- package/dist/doctor.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +48 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +73 -0
- package/dist/output.js.map +1 -0
- package/dist/remote.d.ts +164 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +456 -0
- package/dist/remote.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +59 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/conventions.d.ts +54 -0
- package/dist/tools/conventions.d.ts.map +1 -0
- package/dist/tools/conventions.js +71 -0
- package/dist/tools/conventions.js.map +1 -0
- package/dist/tools/createComment.d.ts +52 -0
- package/dist/tools/createComment.d.ts.map +1 -0
- package/dist/tools/createComment.js +99 -0
- package/dist/tools/createComment.js.map +1 -0
- package/dist/tools/createEvent.d.ts +63 -0
- package/dist/tools/createEvent.d.ts.map +1 -0
- package/dist/tools/createEvent.js +160 -0
- package/dist/tools/createEvent.js.map +1 -0
- package/dist/tools/createTask.d.ts +53 -0
- package/dist/tools/createTask.d.ts.map +1 -0
- package/dist/tools/createTask.js +136 -0
- package/dist/tools/createTask.js.map +1 -0
- package/dist/tools/defineTool.d.ts +76 -0
- package/dist/tools/defineTool.d.ts.map +1 -0
- package/dist/tools/defineTool.js +31 -0
- package/dist/tools/defineTool.js.map +1 -0
- package/dist/tools/index.d.ts +16 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +49 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registration.d.ts +63 -0
- package/dist/tools/registration.d.ts.map +1 -0
- package/dist/tools/registration.js +95 -0
- package/dist/tools/registration.js.map +1 -0
- package/dist/tools/updateTask.d.ts +53 -0
- package/dist/tools/updateTask.d.ts.map +1 -0
- package/dist/tools/updateTask.js +119 -0
- package/dist/tools/updateTask.js.map +1 -0
- package/dist/tools/workel_events.d.ts +23 -0
- package/dist/tools/workel_events.d.ts.map +1 -0
- package/dist/tools/workel_events.js +60 -0
- package/dist/tools/workel_events.js.map +1 -0
- package/dist/tools/workel_members.d.ts +17 -0
- package/dist/tools/workel_members.d.ts.map +1 -0
- package/dist/tools/workel_members.js +46 -0
- package/dist/tools/workel_members.js.map +1 -0
- package/dist/tools/workel_project_columns.d.ts +13 -0
- package/dist/tools/workel_project_columns.d.ts.map +1 -0
- package/dist/tools/workel_project_columns.js +45 -0
- package/dist/tools/workel_project_columns.js.map +1 -0
- package/dist/tools/workel_projects.d.ts +20 -0
- package/dist/tools/workel_projects.d.ts.map +1 -0
- package/dist/tools/workel_projects.js +74 -0
- package/dist/tools/workel_projects.js.map +1 -0
- package/dist/tools/workel_task_comments.d.ts +21 -0
- package/dist/tools/workel_task_comments.d.ts.map +1 -0
- package/dist/tools/workel_task_comments.js +55 -0
- package/dist/tools/workel_task_comments.js.map +1 -0
- package/dist/tools/workel_tasks.d.ts +23 -0
- package/dist/tools/workel_tasks.d.ts.map +1 -0
- package/dist/tools/workel_tasks.js +104 -0
- package/dist/tools/workel_tasks.js.map +1 -0
- package/dist/tools/workel_whoami.d.ts +16 -0
- package/dist/tools/workel_whoami.d.ts.map +1 -0
- package/dist/tools/workel_whoami.js +36 -0
- package/dist/tools/workel_whoami.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +28 -0
- package/dist/version.js.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Workel MCP Server
|
|
2
|
+
|
|
3
|
+
The official [Model Context Protocol](https://modelcontextprotocol.io) server
|
|
4
|
+
for Workel — a thin, stateless client of the
|
|
5
|
+
[Workel Public API v1](https://developer.workel.com). It exposes a Workel
|
|
6
|
+
workspace to AI agents (Claude, the OpenAI Agents SDK, or any other
|
|
7
|
+
MCP-speaking client) as a small set of well-scoped tools. Every rule that
|
|
8
|
+
actually matters — what this key can see, what it can write, how fast it can
|
|
9
|
+
write it — lives in the Workel API itself; this package holds no authority
|
|
10
|
+
the key doesn't already have. A `curl` request made with the same key can do
|
|
11
|
+
exactly what this server can do, no more.
|
|
12
|
+
|
|
13
|
+
For full per-client setup (Claude Desktop, Claude Code, project-scoped
|
|
14
|
+
`.mcp.json`, and the OpenAI Agents SDK), see
|
|
15
|
+
[developer-docs/mcp.md](../../../developer-docs/mcp.md).
|
|
16
|
+
|
|
17
|
+
## Mint a dedicated read-only key before you start
|
|
18
|
+
|
|
19
|
+
Before pointing any AI client at this server, go to **Workel → Settings →
|
|
20
|
+
Developers** and mint a **new** API key just for this purpose — don't reuse
|
|
21
|
+
a key another integration already holds. Minting a key requires an owner or
|
|
22
|
+
admin role. Grant it only the `read:*` scopes the tools in this release
|
|
23
|
+
actually use (`read:projects`, `read:tasks`, `read:members`, `read:events` —
|
|
24
|
+
see [Tools](#tools) below); leave every `write:*` scope unchecked unless you
|
|
25
|
+
have deliberately decided to let an agent create and edit things in your
|
|
26
|
+
workspace on its own. Use one key per machine or agent, name it so you
|
|
27
|
+
remember what it's for later, and if a machine is retired or a client is
|
|
28
|
+
compromised, **revoke that one key** in Settings → Developers rather than
|
|
29
|
+
rotating a key several tools share — revocation is instant and takes effect
|
|
30
|
+
on the next request.
|
|
31
|
+
|
|
32
|
+
Two things worth understanding before touching the flags described below:
|
|
33
|
+
|
|
34
|
+
- **`WORKEL_ENABLE_WRITES` is a local operator consent flag, not an
|
|
35
|
+
authorization boundary.** It can only ever narrow what an already-scoped
|
|
36
|
+
key is offered, never widen it — and because it lives in a config file or
|
|
37
|
+
environment variable that an AI coding agent typically has write access
|
|
38
|
+
to, an agent running on your machine can flip it back to `true` itself. A
|
|
39
|
+
local flag is not something an untrusted agent can be trusted to leave
|
|
40
|
+
alone. The key's own scopes — granted deliberately at mint time, and
|
|
41
|
+
revocable at any time — are the real gate.
|
|
42
|
+
- **A `WORKEL_API_BASE_URL` override sends your key to another host.**
|
|
43
|
+
Every request this server makes carries your key in the `Authorization`
|
|
44
|
+
header. If `WORKEL_API_BASE_URL` ever points at a URL you don't control,
|
|
45
|
+
that host receives your key on every call. This client refuses a plain
|
|
46
|
+
`http://` override except to `localhost`/`127.0.0.1`/`[::1]` for exactly
|
|
47
|
+
this reason. The same logic applies to a real key pasted into any file: if
|
|
48
|
+
it's ever committed to git, rotating the key is the only real fix —
|
|
49
|
+
**git history is forever**. A later commit that deletes the line does not
|
|
50
|
+
remove it from the repository's history, and anyone who cloned the repo in
|
|
51
|
+
between still has the old key.
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
npx -y @workel/mcp@0.1.0
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Pin the version — `0.1.0` above is this package's current release; check
|
|
60
|
+
`npm view @workel/mcp version` for the latest one before you pin it. The
|
|
61
|
+
unpinned form below is **convenience only**, fine for a one-off manual try,
|
|
62
|
+
not for anything an agent's config runs unattended:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
npx -y @workel/mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Environment variables
|
|
69
|
+
|
|
70
|
+
| Variable | Required | Default | What it does |
|
|
71
|
+
|---|---|---|---|
|
|
72
|
+
| `WORKEL_API_KEY` | Yes | — | Your Workel API key. Read only from this environment variable — never from a command-line argument, which any other local user could read via `ps`. Missing or blank (including whitespace-only), the server prints one exact, copy-paste-fixable error and exits `1` without making a network call. |
|
|
73
|
+
| `WORKEL_API_BASE_URL` | No | `https://api.workel.com/api/public/v1` | Overrides the API host. Must be `https://`, except `http://localhost`, `http://127.0.0.1`, or `http://[::1]`, which are allowed for local development. Trailing slashes are stripped. Read the security note above before setting this. |
|
|
74
|
+
| `WORKEL_ENABLE_WRITES` | No | `false` (any value other than the literal, case-insensitive `true`) | Local consent for write tools — see the security note above. As of this release, no write tool is registered by the server regardless of this value; see [Tools](#tools). |
|
|
75
|
+
| `WORKEL_SKIP_STARTUP_CHECK` | No | `false` | Set to `true` to skip the `GET /me` startup probe and start immediately with every tool this key's scopes could ever reach, without confirming which scopes the key actually carries right now. Useful when working offline or before the API is reachable. |
|
|
76
|
+
| `WORKEL_LOG_LEVEL` | No | `info` | One of `debug`, `info`, `warn`, `error` (case-insensitive). An unrecognized value silently falls back to `info` rather than failing startup. Validated at startup; not yet wired to any log output in this release. |
|
|
77
|
+
|
|
78
|
+
## `doctor`
|
|
79
|
+
|
|
80
|
+
Run `npx -y @workel/mcp@0.1.0 doctor` any time your MCP client reports only
|
|
81
|
+
"server failed to start" with no further detail. It runs the exact same
|
|
82
|
+
startup check the server itself runs — load config, then probe `GET /me` —
|
|
83
|
+
and prints a plain-text report to stdout instead of trying to speak the MCP
|
|
84
|
+
protocol:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
base URL: https://api.workel.com/api/public/v1
|
|
88
|
+
workspace: Acme Inc
|
|
89
|
+
key: ci-key
|
|
90
|
+
scopes: read:projects, read:tasks
|
|
91
|
+
2 tools would register: workel_whoami, workel_list_projects
|
|
92
|
+
write budget: 59/60 remaining this minute
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`doctor` never starts a transport and never talks to your MCP client — it's
|
|
96
|
+
a standalone command you run from a terminal, and it exits `0` on success or
|
|
97
|
+
`1` on any failure (missing/invalid `WORKEL_API_KEY`, an unreachable API, or
|
|
98
|
+
a key the API rejects). Unlike the one-line summary the server prints to
|
|
99
|
+
stderr on a normal boot (which omits the base URL when it's the default),
|
|
100
|
+
`doctor` always prints the effective base URL — including when it's the
|
|
101
|
+
default — because a doctor run is exactly the moment a tampered
|
|
102
|
+
`WORKEL_API_BASE_URL` needs to be visible.
|
|
103
|
+
|
|
104
|
+
## Tools
|
|
105
|
+
|
|
106
|
+
This release registers the following read-only tools. `workel_whoami` needs
|
|
107
|
+
no scope at all and works with any valid key; every other tool is only
|
|
108
|
+
registered when the key's scopes (discovered via the `GET /me` probe above)
|
|
109
|
+
include the scope listed. List tools return 25 results per call by default
|
|
110
|
+
(100 max) and page via an opaque `cursor` / `next_cursor` pair.
|
|
111
|
+
|
|
112
|
+
| Tool | Scope | What it does |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| `workel_whoami` | *(none)* | Identity check: which workspace, which key, its current scopes, and its remaining rate-limit budget. Call this first to confirm the server is configured correctly and see which other tools this key can actually use. |
|
|
115
|
+
| `workel_list_projects` | `read:projects` | List the projects visible to this key. Archived projects, private projects, and the per-user inbox project are never returned. |
|
|
116
|
+
| `workel_get_project` | `read:projects` | Fetch one project by id, including its full (possibly truncated) description. |
|
|
117
|
+
| `workel_list_project_columns` | `read:projects` | List a project's board columns — its kanban lists such as "To Do" or "Done" — not the tasks inside them. |
|
|
118
|
+
| `workel_list_tasks` | `read:tasks` | List tasks, filterable by project, column, completion, and due-date/update-time. There is no text search on this endpoint. |
|
|
119
|
+
| `workel_get_task` | `read:tasks` | Fetch one task by id, including its full (possibly truncated) description. |
|
|
120
|
+
| `workel_list_task_comments` | `read:tasks` | List every comment on a task, oldest first — top-level comments and replies together. |
|
|
121
|
+
| `workel_list_members` | `read:members` | List the workspace's active members — the only tool that returns email addresses. |
|
|
122
|
+
| `workel_list_events` | `read:events` | List events on the workspace and any of its visible projects. |
|
|
123
|
+
|
|
124
|
+
**Write tools are not yet available in this release.** `workel_create_task`,
|
|
125
|
+
`workel_update_task`, `workel_create_task_comment`, and `workel_create_event`
|
|
126
|
+
exist in this package's source, gated behind the `write:tasks` /
|
|
127
|
+
`write:comments` / `write:events` scopes and `WORKEL_ENABLE_WRITES` exactly
|
|
128
|
+
as described in the security note above — but the server does not currently
|
|
129
|
+
register any of them at boot, regardless of a key's scopes or that flag's
|
|
130
|
+
value. Treat the write-tool guidance above as this project's intended
|
|
131
|
+
design, not something you can rely on today; a future release note will say
|
|
132
|
+
when that changes.
|
|
133
|
+
|
|
134
|
+
## Limitations
|
|
135
|
+
|
|
136
|
+
**`replayed` does not prove uniqueness.** Every write this server's tools
|
|
137
|
+
would make carries an `Idempotency-Key`, and the Workel API's idempotency
|
|
138
|
+
store (24-hour retention, scoped to the calling key) replays the exact same
|
|
139
|
+
response for a repeated attempt with the same key and the same request body
|
|
140
|
+
— the second attempt reports `replayed: true`, and nothing is created or
|
|
141
|
+
changed a second time.
|
|
142
|
+
|
|
143
|
+
`replayed: false` means this particular attempt genuinely executed — it does
|
|
144
|
+
**not** mean no duplicate exists anywhere else. In particular: an error
|
|
145
|
+
response is never cached, so retrying after a failure always re-executes for
|
|
146
|
+
real; the idempotency record expires after 24 hours, so a very late retry
|
|
147
|
+
re-executes for real; and the store is namespaced per API key, so the same
|
|
148
|
+
literal `Idempotency-Key` value sent under a *different* key never collides
|
|
149
|
+
with — and never protects against a duplicate created by — the first one.
|
|
150
|
+
Unless a tool call explicitly reuses the same idempotency key across two
|
|
151
|
+
attempts, each attempt is a genuinely independent write as far as the server
|
|
152
|
+
can tell.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single HTTP seam between every MCP tool and the Workel Public API v1.
|
|
3
|
+
*
|
|
4
|
+
* This is where the server's core invariant is enforced: a curl user
|
|
5
|
+
* holding the same API key has exactly the same power as any tool built on
|
|
6
|
+
* this client, no more. The key travels ONLY in the `Authorization` header
|
|
7
|
+
* — never in the URL, never in the query string, never in any other
|
|
8
|
+
* header — and tenancy/scope come entirely from what the server resolves
|
|
9
|
+
* for that key server-side. This client never adds anything to a request
|
|
10
|
+
* that widens what a curl user with the same key could already do.
|
|
11
|
+
*
|
|
12
|
+
* `fetch` and `sleep` are constructor-injected (never read from a
|
|
13
|
+
* global/module scope, never from `process.env`) so every behaviour below
|
|
14
|
+
* — retry timing, header shape, redaction — is testable with no real
|
|
15
|
+
* network call. `createWorkelApiClientFromEnv` is the only place that
|
|
16
|
+
* reaches for the real `fetch` and `src/config.ts`'s environment loading,
|
|
17
|
+
* and only for production wiring; no test needs it.
|
|
18
|
+
*
|
|
19
|
+
* Writes (T9): every POST carries an `Idempotency-Key` header — either the
|
|
20
|
+
* caller's own value, sent verbatim with no reformatting, or (when the
|
|
21
|
+
* caller supplies none) a fresh v4 UUID from `node:crypto`'s
|
|
22
|
+
* `randomUUID()`. That key is generated exactly ONCE per logical `post()`
|
|
23
|
+
* call, above `fetchWithRetry`'s own 429-retry loop, and reused unchanged
|
|
24
|
+
* on the retried attempt — a retried write is provably the same request as
|
|
25
|
+
* far as the server's idempotency store is concerned. PATCH never carries
|
|
26
|
+
* the header at all: read `PublicApiIdempotency::handle()`
|
|
27
|
+
* (`backend/services/laravel-backend/app/Http/Middleware/PublicApi/PublicApiIdempotency.php:65-67`)
|
|
28
|
+
* — it early-returns for any method other than POST — so sending the
|
|
29
|
+
* header on PATCH would only invite a caller to assume a guarantee the
|
|
30
|
+
* server does not provide there.
|
|
31
|
+
*
|
|
32
|
+
* Replay detection: on a cache hit, that same middleware returns the
|
|
33
|
+
* stored response WITH an added `Idempotent-Replay: true` header
|
|
34
|
+
* (PublicApiIdempotency.php:97-99); a freshly-executed response carries no
|
|
35
|
+
* such header. That is a genuinely distinguishable signal, so this client
|
|
36
|
+
* reads it directly rather than keeping any idempotency bookkeeping of its
|
|
37
|
+
* own — the middleware is the sole source of truth for whether a given
|
|
38
|
+
* response was served from its store. (The middleware's OTHER branch — the
|
|
39
|
+
* same key reused with a DIFFERENT body — is a 409 `idempotency_error`,
|
|
40
|
+
* handled by the ordinary error path below, not by this flag; see
|
|
41
|
+
* PublicApiIdempotency.php:86-95.)
|
|
42
|
+
*
|
|
43
|
+
* Write serialization: POST and PATCH issued through one client instance
|
|
44
|
+
* run strictly sequentially, chained on a closure-scoped promise so a
|
|
45
|
+
* second write never starts until the first has settled — success or
|
|
46
|
+
* failure; a rejected write does not block the next one. This is a
|
|
47
|
+
* PER-PROCESS guarantee only. It says nothing about two separate processes
|
|
48
|
+
* (or two separate client instances) racing the same Idempotency-Key —
|
|
49
|
+
* that residual window is exactly what the server's 24h idempotency-record
|
|
50
|
+
* cache exists to close, not this client. GET never joins this queue: a
|
|
51
|
+
* read issued while a write is in flight goes straight to `fetch`.
|
|
52
|
+
*/
|
|
53
|
+
import { type MappedApiError } from './errors';
|
|
54
|
+
export type FetchLike = typeof fetch;
|
|
55
|
+
export type SleepLike = (ms: number) => Promise<void>;
|
|
56
|
+
/** Default per-attempt request deadline. Generous for a JSON API, far below undici's 300s default. */
|
|
57
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
58
|
+
export interface WorkelApiClientDeps {
|
|
59
|
+
baseUrl: string;
|
|
60
|
+
apiKey: string;
|
|
61
|
+
fetch: FetchLike;
|
|
62
|
+
sleep: SleepLike;
|
|
63
|
+
/**
|
|
64
|
+
* Per-attempt request deadline. Without one, a stalled upstream (TCP open,
|
|
65
|
+
* no response) hangs the tool call — and therefore the model's turn —
|
|
66
|
+
* until undici's 300s default, with `boot()` awaiting the same stall
|
|
67
|
+
* before the transport exists. A fresh signal is built per attempt so the
|
|
68
|
+
* 429 retry gets a full budget rather than the remainder of the first.
|
|
69
|
+
*/
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Values are stringified and included; `undefined` values are omitted
|
|
74
|
+
* entirely rather than serialized as the literal string `"undefined"`.
|
|
75
|
+
*/
|
|
76
|
+
export type QueryParams = Record<string, string | number | boolean | undefined>;
|
|
77
|
+
export interface WorkelApiResult<T> {
|
|
78
|
+
data: T;
|
|
79
|
+
requestId: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Present ONLY on a `post()` result — `true` when the response was
|
|
82
|
+
* served from the server's idempotency store rather than freshly
|
|
83
|
+
* executed (`Idempotent-Replay: true`, PublicApiIdempotency.php:99),
|
|
84
|
+
* `false` when it was freshly executed. Left unset (never `true` or
|
|
85
|
+
* `false`) on `get()`/`patch()` results, since neither ever carries an
|
|
86
|
+
* `Idempotency-Key` and so neither can ever be a replay.
|
|
87
|
+
*/
|
|
88
|
+
replayed?: boolean;
|
|
89
|
+
}
|
|
90
|
+
export interface WorkelApiWriteOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Caller-supplied `Idempotency-Key`, sent verbatim — no trimming, no
|
|
93
|
+
* case change, no reformatting, and no validation that it looks like a
|
|
94
|
+
* UUID. Omit to have this client generate a fresh v4 UUID automatically.
|
|
95
|
+
*/
|
|
96
|
+
idempotencyKey?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface WorkelApiClient {
|
|
99
|
+
get<T = unknown>(path: string, query?: QueryParams): Promise<WorkelApiResult<T>>;
|
|
100
|
+
post<T = unknown>(path: string, body?: unknown, options?: WorkelApiWriteOptions): Promise<WorkelApiResult<T>>;
|
|
101
|
+
/** Never carries `Idempotency-Key` — see the file-level docblock. */
|
|
102
|
+
patch<T = unknown>(path: string, body?: unknown): Promise<WorkelApiResult<T>>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Thrown for every non-2xx response. Wraps `errors.ts`'s pure, network-free
|
|
106
|
+
* mapping with the one thing that module deliberately has no knowledge of:
|
|
107
|
+
* the API key. Redaction happens here, not there, because only this module
|
|
108
|
+
* knows the key.
|
|
109
|
+
*/
|
|
110
|
+
export declare class WorkelApiError extends Error {
|
|
111
|
+
readonly code: string;
|
|
112
|
+
readonly status: number;
|
|
113
|
+
readonly terminal: boolean;
|
|
114
|
+
readonly requestId: string | null;
|
|
115
|
+
constructor(mapped: MappedApiError);
|
|
116
|
+
}
|
|
117
|
+
export declare function createWorkelApiClient(deps: WorkelApiClientDeps): WorkelApiClient;
|
|
118
|
+
/**
|
|
119
|
+
* Production wiring: builds a client from `loadConfig`'s environment-driven
|
|
120
|
+
* configuration and the real global `fetch`. This is how the MCP
|
|
121
|
+
* entrypoint constructs the real client — `createWorkelApiClient` above is
|
|
122
|
+
* the seam every test injects into instead; no test in this project needs
|
|
123
|
+
* this function.
|
|
124
|
+
*/
|
|
125
|
+
export declare function createWorkelApiClientFromEnv(env?: NodeJS.ProcessEnv): WorkelApiClient;
|
|
126
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAKH,OAAO,EAAe,KAAK,cAAc,EAAoB,MAAM,UAAU,CAAC;AAE9E,MAAM,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC;AACrC,MAAM,MAAM,SAAS,GAAG,CAAC,EAAE,EAAE,MAA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vC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEtB,MAAM,EAAE,cAAc;CAQnC;AAkGD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,mBAAmB,GAAG,eAAe,CAuJhF;AAMD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,eAAe,CAQlG"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The single HTTP seam between every MCP tool and the Workel Public API v1.
|
|
4
|
+
*
|
|
5
|
+
* This is where the server's core invariant is enforced: a curl user
|
|
6
|
+
* holding the same API key has exactly the same power as any tool built on
|
|
7
|
+
* this client, no more. The key travels ONLY in the `Authorization` header
|
|
8
|
+
* — never in the URL, never in the query string, never in any other
|
|
9
|
+
* header — and tenancy/scope come entirely from what the server resolves
|
|
10
|
+
* for that key server-side. This client never adds anything to a request
|
|
11
|
+
* that widens what a curl user with the same key could already do.
|
|
12
|
+
*
|
|
13
|
+
* `fetch` and `sleep` are constructor-injected (never read from a
|
|
14
|
+
* global/module scope, never from `process.env`) so every behaviour below
|
|
15
|
+
* — retry timing, header shape, redaction — is testable with no real
|
|
16
|
+
* network call. `createWorkelApiClientFromEnv` is the only place that
|
|
17
|
+
* reaches for the real `fetch` and `src/config.ts`'s environment loading,
|
|
18
|
+
* and only for production wiring; no test needs it.
|
|
19
|
+
*
|
|
20
|
+
* Writes (T9): every POST carries an `Idempotency-Key` header — either the
|
|
21
|
+
* caller's own value, sent verbatim with no reformatting, or (when the
|
|
22
|
+
* caller supplies none) a fresh v4 UUID from `node:crypto`'s
|
|
23
|
+
* `randomUUID()`. That key is generated exactly ONCE per logical `post()`
|
|
24
|
+
* call, above `fetchWithRetry`'s own 429-retry loop, and reused unchanged
|
|
25
|
+
* on the retried attempt — a retried write is provably the same request as
|
|
26
|
+
* far as the server's idempotency store is concerned. PATCH never carries
|
|
27
|
+
* the header at all: read `PublicApiIdempotency::handle()`
|
|
28
|
+
* (`backend/services/laravel-backend/app/Http/Middleware/PublicApi/PublicApiIdempotency.php:65-67`)
|
|
29
|
+
* — it early-returns for any method other than POST — so sending the
|
|
30
|
+
* header on PATCH would only invite a caller to assume a guarantee the
|
|
31
|
+
* server does not provide there.
|
|
32
|
+
*
|
|
33
|
+
* Replay detection: on a cache hit, that same middleware returns the
|
|
34
|
+
* stored response WITH an added `Idempotent-Replay: true` header
|
|
35
|
+
* (PublicApiIdempotency.php:97-99); a freshly-executed response carries no
|
|
36
|
+
* such header. That is a genuinely distinguishable signal, so this client
|
|
37
|
+
* reads it directly rather than keeping any idempotency bookkeeping of its
|
|
38
|
+
* own — the middleware is the sole source of truth for whether a given
|
|
39
|
+
* response was served from its store. (The middleware's OTHER branch — the
|
|
40
|
+
* same key reused with a DIFFERENT body — is a 409 `idempotency_error`,
|
|
41
|
+
* handled by the ordinary error path below, not by this flag; see
|
|
42
|
+
* PublicApiIdempotency.php:86-95.)
|
|
43
|
+
*
|
|
44
|
+
* Write serialization: POST and PATCH issued through one client instance
|
|
45
|
+
* run strictly sequentially, chained on a closure-scoped promise so a
|
|
46
|
+
* second write never starts until the first has settled — success or
|
|
47
|
+
* failure; a rejected write does not block the next one. This is a
|
|
48
|
+
* PER-PROCESS guarantee only. It says nothing about two separate processes
|
|
49
|
+
* (or two separate client instances) racing the same Idempotency-Key —
|
|
50
|
+
* that residual window is exactly what the server's 24h idempotency-record
|
|
51
|
+
* cache exists to close, not this client. GET never joins this queue: a
|
|
52
|
+
* read issued while a write is in flight goes straight to `fetch`.
|
|
53
|
+
*/
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.WorkelApiError = exports.DEFAULT_REQUEST_TIMEOUT_MS = void 0;
|
|
56
|
+
exports.createWorkelApiClient = createWorkelApiClient;
|
|
57
|
+
exports.createWorkelApiClientFromEnv = createWorkelApiClientFromEnv;
|
|
58
|
+
const node_crypto_1 = require("node:crypto");
|
|
59
|
+
const config_1 = require("../config");
|
|
60
|
+
const redact_1 = require("./redact");
|
|
61
|
+
const errors_1 = require("./errors");
|
|
62
|
+
/** Default per-attempt request deadline. Generous for a JSON API, far below undici's 300s default. */
|
|
63
|
+
exports.DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
64
|
+
/** A 429 is retried at most once, and only after waiting this long — never more, regardless of what `Retry-After` asked for. */
|
|
65
|
+
const MAX_RETRY_AFTER_SECONDS = 60;
|
|
66
|
+
const REQUEST_ID_HEADER = 'x-request-id';
|
|
67
|
+
const RETRY_AFTER_HEADER = 'retry-after';
|
|
68
|
+
const REPLAY_HEADER = 'idempotent-replay';
|
|
69
|
+
/**
|
|
70
|
+
* Thrown for every non-2xx response. Wraps `errors.ts`'s pure, network-free
|
|
71
|
+
* mapping with the one thing that module deliberately has no knowledge of:
|
|
72
|
+
* the API key. Redaction happens here, not there, because only this module
|
|
73
|
+
* knows the key.
|
|
74
|
+
*/
|
|
75
|
+
class WorkelApiError extends Error {
|
|
76
|
+
constructor(mapped) {
|
|
77
|
+
super(mapped.message);
|
|
78
|
+
this.name = 'WorkelApiError';
|
|
79
|
+
this.code = mapped.code;
|
|
80
|
+
this.status = mapped.status;
|
|
81
|
+
this.terminal = mapped.terminal;
|
|
82
|
+
this.requestId = mapped.requestId;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.WorkelApiError = WorkelApiError;
|
|
86
|
+
function stripTrailingSlashes(value) {
|
|
87
|
+
return value.replace(/\/+$/, '');
|
|
88
|
+
}
|
|
89
|
+
function ensureLeadingSlash(value) {
|
|
90
|
+
return value.startsWith('/') ? value : `/${value}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* `baseUrl` with/without a trailing slash must produce an identical request
|
|
94
|
+
* URL, and `path` with/without a leading slash must too — both are
|
|
95
|
+
* normalized here, once, rather than trusted to whatever a given call site
|
|
96
|
+
* happened to pass.
|
|
97
|
+
*/
|
|
98
|
+
function buildRequestUrl(baseUrl, path, query) {
|
|
99
|
+
const url = new URL(`${stripTrailingSlashes(baseUrl)}${ensureLeadingSlash(path)}`);
|
|
100
|
+
if (query) {
|
|
101
|
+
for (const [key, value] of Object.entries(query)) {
|
|
102
|
+
if (value === undefined)
|
|
103
|
+
continue;
|
|
104
|
+
url.searchParams.set(key, String(value));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return url.toString();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Parses `Retry-After` as a finite, non-negative integer number of seconds,
|
|
111
|
+
* clamped to `MAX_RETRY_AFTER_SECONDS`. Anything else — missing, an
|
|
112
|
+
* HTTP-date, a decimal, a negative number, empty — is treated as
|
|
113
|
+
* unparseable and returns `null`; the caller must not retry (let alone
|
|
114
|
+
* sleep(0)) on unparseable input, only on a header it can actually honor.
|
|
115
|
+
*/
|
|
116
|
+
function parseRetryAfterSeconds(headerValue) {
|
|
117
|
+
if (headerValue === null)
|
|
118
|
+
return null;
|
|
119
|
+
const trimmed = headerValue.trim();
|
|
120
|
+
if (!/^\d+$/.test(trimmed))
|
|
121
|
+
return null; // rejects HTTP-dates, decimals, negatives, and blanks
|
|
122
|
+
const seconds = Number(trimmed);
|
|
123
|
+
if (!Number.isFinite(seconds))
|
|
124
|
+
return null; // guards a digit string long enough to overflow to Infinity
|
|
125
|
+
return Math.min(seconds, MAX_RETRY_AFTER_SECONDS);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Reads the body as text and attempts a JSON parse. A body that isn't valid
|
|
129
|
+
* JSON (or is empty) becomes `null` rather than throwing — `errors.ts`'s
|
|
130
|
+
* envelope check already tolerates any non-object body (it's exactly the
|
|
131
|
+
* shape an uncaught server `\Throwable`'s fallback text, or a genuinely
|
|
132
|
+
* empty body, produces), so there's nothing gained by surfacing the raw
|
|
133
|
+
* unparsed text here, and doing so is exactly the kind of "upstream body
|
|
134
|
+
* text" this module must not let leak into an error unredacted.
|
|
135
|
+
*/
|
|
136
|
+
async function readResponseBody(response) {
|
|
137
|
+
const text = await response.text();
|
|
138
|
+
if (text.length === 0)
|
|
139
|
+
return null;
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(text);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Guards the 2xx path: `readResponseBody` collapses an empty or unparseable
|
|
149
|
+
* body to `null`, which is indistinguishable from a legitimately-null field
|
|
150
|
+
* once it reaches a tool. Throwing a mapped, retryable error instead means
|
|
151
|
+
* the failure reads the same as every other API failure.
|
|
152
|
+
*/
|
|
153
|
+
function assertParsedBody(body, requestId) {
|
|
154
|
+
if (body !== null)
|
|
155
|
+
return;
|
|
156
|
+
const suffix = requestId === null ? '' : ` (request_id: ${requestId})`;
|
|
157
|
+
throw new WorkelApiError({
|
|
158
|
+
code: errors_1.NO_ENVELOPE_CODE,
|
|
159
|
+
status: 200,
|
|
160
|
+
// Not terminal: an empty/unreadable body from a 2xx is a transient
|
|
161
|
+
// server-side fault, so retrying this exact request is reasonable.
|
|
162
|
+
terminal: false,
|
|
163
|
+
requestId,
|
|
164
|
+
message: `The Workel API returned a successful status with an empty or unreadable body. This is a server-side problem, not a problem with your request — retrying shortly is reasonable.${suffix}`,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function extractRequestId(response) {
|
|
168
|
+
const value = response.headers.get(REQUEST_ID_HEADER);
|
|
169
|
+
return value && value.length > 0 ? value : null;
|
|
170
|
+
}
|
|
171
|
+
/** `true` only when the response carries `Idempotent-Replay: true` (PublicApiIdempotency.php:99). */
|
|
172
|
+
function isReplayedResponse(response) {
|
|
173
|
+
return response.headers.get(REPLAY_HEADER) === 'true';
|
|
174
|
+
}
|
|
175
|
+
function createWorkelApiClient(deps) {
|
|
176
|
+
const { baseUrl, apiKey, fetch: doFetch, sleep } = deps;
|
|
177
|
+
const timeoutMs = deps.timeoutMs ?? exports.DEFAULT_REQUEST_TIMEOUT_MS;
|
|
178
|
+
/** Wraps `doFetch` with a fresh per-attempt deadline (see `timeoutMs`). */
|
|
179
|
+
async function fetchWithDeadline(url, init) {
|
|
180
|
+
return doFetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
|
|
181
|
+
}
|
|
182
|
+
const requestHeaders = {
|
|
183
|
+
Authorization: `Bearer ${apiKey}`,
|
|
184
|
+
Accept: 'application/json',
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Per-instance write queue. Every `post`/`patch` call chains its work
|
|
188
|
+
* onto this promise so writes on ONE client execute strictly
|
|
189
|
+
* sequentially. The tail re-attached to `writeQueue` on every call
|
|
190
|
+
* always swallows (`() => undefined` on both branches) so a rejected
|
|
191
|
+
* write can never poison the chain for the next queued write — the
|
|
192
|
+
* caller's OWN returned promise (`result` below) still rejects
|
|
193
|
+
* normally; only the shared continuation is laundered back to settled.
|
|
194
|
+
*/
|
|
195
|
+
let writeQueue = Promise.resolve();
|
|
196
|
+
function enqueueWrite(task) {
|
|
197
|
+
const result = writeQueue.then(task, task);
|
|
198
|
+
writeQueue = result.then(() => undefined, () => undefined);
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Issues `init` against `url`, retrying exactly once on a 429 whose
|
|
203
|
+
* `Retry-After` this client can actually honor. `init` (including any
|
|
204
|
+
* `Idempotency-Key` header a write call built) is reused UNCHANGED on
|
|
205
|
+
* the retried attempt — the retry is provably the same request.
|
|
206
|
+
*/
|
|
207
|
+
async function fetchWithRetry(url, init) {
|
|
208
|
+
let response = await fetchWithDeadline(url, init);
|
|
209
|
+
if (response.status === 429) {
|
|
210
|
+
const retryAfterSeconds = parseRetryAfterSeconds(response.headers.get(RETRY_AFTER_HEADER));
|
|
211
|
+
// Retry exactly once, and only when the header gave us something we
|
|
212
|
+
// can actually honor. A second 429 (or anything else) after the
|
|
213
|
+
// retry falls straight through to the caller — there is no second
|
|
214
|
+
// retry regardless of what the second response's headers say.
|
|
215
|
+
if (retryAfterSeconds !== null) {
|
|
216
|
+
await sleep(retryAfterSeconds * 1000);
|
|
217
|
+
response = await fetchWithDeadline(url, init);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return response;
|
|
221
|
+
}
|
|
222
|
+
async function throwMappedError(response) {
|
|
223
|
+
const body = await readResponseBody(response);
|
|
224
|
+
const requestId = extractRequestId(response);
|
|
225
|
+
const mapped = (0, errors_1.mapApiError)(response.status, body, requestId);
|
|
226
|
+
// Redact BEFORE constructing the error, not after: `Error`'s `.stack`
|
|
227
|
+
// embeds `.message` as its first line at construction time, so a
|
|
228
|
+
// post-construction redaction of `.message` alone would still leave
|
|
229
|
+
// the secret sitting in `.stack`. `code` is redacted too — an
|
|
230
|
+
// unrecognized wire `code` is untrusted, attacker/record-controlled
|
|
231
|
+
// text (see errors.ts's docblock) that `mapped.message` already
|
|
232
|
+
// interpolates verbatim, so the same secret can reach both fields.
|
|
233
|
+
const safeMapped = {
|
|
234
|
+
...mapped,
|
|
235
|
+
code: (0, redact_1.redact)(mapped.code, [apiKey]),
|
|
236
|
+
message: (0, redact_1.redact)(mapped.message, [apiKey]),
|
|
237
|
+
};
|
|
238
|
+
throw new WorkelApiError(safeMapped);
|
|
239
|
+
}
|
|
240
|
+
async function get(path, query) {
|
|
241
|
+
const url = buildRequestUrl(baseUrl, path, query);
|
|
242
|
+
const response = await fetchWithRetry(url, { method: 'GET', headers: requestHeaders });
|
|
243
|
+
if (!response.ok) {
|
|
244
|
+
return throwMappedError(response);
|
|
245
|
+
}
|
|
246
|
+
const body = await readResponseBody(response);
|
|
247
|
+
// A 2xx whose body is empty or unparseable is a broken response, not
|
|
248
|
+
// data. Returning null here made eight tools dereference it and throw a
|
|
249
|
+
// raw TypeError at the model; failing at the seam keeps every tool's
|
|
250
|
+
// error path uniform and legible.
|
|
251
|
+
assertParsedBody(body, extractRequestId(response));
|
|
252
|
+
// `body` is returned verbatim — including a `next_cursor` field, if the
|
|
253
|
+
// endpoint's shape has one — with no decode/re-encode/validation step;
|
|
254
|
+
// it is an opaque token as far as this client is concerned.
|
|
255
|
+
return { data: body, requestId: extractRequestId(response) };
|
|
256
|
+
}
|
|
257
|
+
async function performWrite(method, path, body, idempotencyKey) {
|
|
258
|
+
const url = buildRequestUrl(baseUrl, path);
|
|
259
|
+
const hasBody = body !== undefined;
|
|
260
|
+
const headers = { ...requestHeaders };
|
|
261
|
+
if (hasBody)
|
|
262
|
+
headers['Content-Type'] = 'application/json';
|
|
263
|
+
if (idempotencyKey !== null)
|
|
264
|
+
headers['Idempotency-Key'] = idempotencyKey;
|
|
265
|
+
const response = await fetchWithRetry(url, {
|
|
266
|
+
method,
|
|
267
|
+
headers,
|
|
268
|
+
body: hasBody ? JSON.stringify(body) : undefined,
|
|
269
|
+
});
|
|
270
|
+
if (!response.ok) {
|
|
271
|
+
return throwMappedError(response);
|
|
272
|
+
}
|
|
273
|
+
const responseBody = await readResponseBody(response);
|
|
274
|
+
const result = { data: responseBody, requestId: extractRequestId(response) };
|
|
275
|
+
if (method === 'POST') {
|
|
276
|
+
result.replayed = isReplayedResponse(response);
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
async function post(path, body, options) {
|
|
281
|
+
// Generated ONCE per logical call, above fetchWithRetry's own 429-retry
|
|
282
|
+
// loop — a caller-supplied key is honored verbatim; an auto-generated
|
|
283
|
+
// one is reused unchanged on a retried attempt.
|
|
284
|
+
const idempotencyKey = options?.idempotencyKey ?? (0, node_crypto_1.randomUUID)();
|
|
285
|
+
return enqueueWrite(() => performWrite('POST', path, body, idempotencyKey));
|
|
286
|
+
}
|
|
287
|
+
async function patch(path, body) {
|
|
288
|
+
// Never carries Idempotency-Key: PublicApiIdempotency::handle() only
|
|
289
|
+
// inspects POST (PublicApiIdempotency.php:65-67).
|
|
290
|
+
return enqueueWrite(() => performWrite('PATCH', path, body, null));
|
|
291
|
+
}
|
|
292
|
+
return { get, post, patch };
|
|
293
|
+
}
|
|
294
|
+
function defaultSleep(ms) {
|
|
295
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Production wiring: builds a client from `loadConfig`'s environment-driven
|
|
299
|
+
* configuration and the real global `fetch`. This is how the MCP
|
|
300
|
+
* entrypoint constructs the real client — `createWorkelApiClient` above is
|
|
301
|
+
* the seam every test injects into instead; no test in this project needs
|
|
302
|
+
* this function.
|
|
303
|
+
*/
|
|
304
|
+
function createWorkelApiClientFromEnv(env = process.env) {
|
|
305
|
+
const config = (0, config_1.loadConfig)(env);
|
|
306
|
+
return createWorkelApiClient({
|
|
307
|
+
baseUrl: config.baseUrl,
|
|
308
|
+
apiKey: config.apiKey,
|
|
309
|
+
fetch,
|
|
310
|
+
sleep: defaultSleep,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;;;AA6LH,sDAuJC;AAaD,oEAQC;AAvWD,6CAAyC;AACzC,sCAAuC;AACvC,qCAAkC;AAClC,qCAA8E;AAK9E,sGAAsG;AACzF,QAAA,0BAA0B,GAAG,KAAM,CAAC;AAqDjD,gIAAgI;AAChI,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAE1C;;;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