@dudko.dev/agent-web 0.0.36 → 0.0.38
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 +156 -4
- package/dist/agent-web.js +270 -110
- package/dist/agent-web.js.map +1 -1
- package/dist/chunk-AY2BZYZY.js +573 -0
- package/dist/chunk-AY2BZYZY.js.map +1 -0
- package/dist/chunk-CTXDKSDD.js +39 -0
- package/dist/chunk-CTXDKSDD.js.map +1 -0
- package/dist/{chunk-CPSDKXO6.js → chunk-T6LZW7ML.js} +27 -35
- package/dist/chunk-T6LZW7ML.js.map +1 -0
- package/dist/chunk-V3JOK7EW.js +929 -0
- package/dist/chunk-V3JOK7EW.js.map +1 -0
- package/dist/index.cjs +5980 -3627
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +363 -3
- package/dist/index.d.ts +363 -3
- package/dist/index.js +1183 -583
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +879 -13
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +372 -13
- package/dist/mcp.d.ts +372 -13
- package/dist/mcp.js +857 -15
- package/dist/mcp.js.map +1 -1
- package/dist/sandbox-AMO2SA4X.js +269 -0
- package/dist/sandbox-AMO2SA4X.js.map +1 -0
- package/dist/sandbox-worker.cjs +745 -0
- package/dist/sandbox-worker.cjs.map +1 -0
- package/dist/sandbox-worker.d.cts +37 -0
- package/dist/sandbox-worker.d.ts +37 -0
- package/dist/sandbox-worker.js +27 -0
- package/dist/sandbox-worker.js.map +1 -0
- package/package.json +30 -11
- package/dist/chunk-CPSDKXO6.js.map +0 -1
package/README.md
CHANGED
|
@@ -253,13 +253,108 @@ if (mcp.results[0]?.needsAuthorization) {
|
|
|
253
253
|
}
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
Tokens, the
|
|
256
|
+
Tokens, the registration, the PKCE verifier and what discovery found are stored in the same
|
|
257
257
|
**encrypted IndexedDB vault** as provider API keys (`VaultOAuthStorage`; swap in
|
|
258
258
|
`MemoryOAuthStorage` or your own via `storage`). `redirectToAuthorization` never
|
|
259
259
|
navigates on its own — the SDK can demand authorization from inside a running
|
|
260
260
|
tool call, and evicting the user then would discard the run. The URL is recorded
|
|
261
261
|
on `provider.authorizationUrl` and the app decides when to use it.
|
|
262
262
|
|
|
263
|
+
- **`iss` (RFC 9207).** `readOAuthCallback` reads the `iss` parameter of the
|
|
264
|
+
redirect and `finishMcpOAuth` checks it against the authorization server the
|
|
265
|
+
flow was started with, after `state` and before the code is exchanged. A
|
|
266
|
+
different issuer is refused (a mix-up attack), and so is a missing `iss` when
|
|
267
|
+
the server's metadata says `authorization_response_iss_parameter_supported:
|
|
268
|
+
true`. The comparison is exact. If you parse the callback yourself, pass `iss`
|
|
269
|
+
along; `checkAuthorizationResponseIssuer` is the rule on its own.
|
|
270
|
+
- **`clientMetadataUrl` (CIMD).** Host a client ID metadata document and pass
|
|
271
|
+
its URL: an authorization server that advertises
|
|
272
|
+
`client_id_metadata_document_supported` takes the URL as the `client_id` and
|
|
273
|
+
no registration request is made. Other servers get dynamic registration as
|
|
274
|
+
before, and a registration already in storage wins over both. The URL must be
|
|
275
|
+
https with a path (anything else throws in the constructor), and the document
|
|
276
|
+
must list the same `redirect_uris` as `redirectUrl`.
|
|
277
|
+
- **Registration** describes a public PKCE client. `application_type` follows
|
|
278
|
+
the redirect URL: `'web'` for an https page, `'native'` for a loopback one
|
|
279
|
+
(local development). Change any field through `clientMetadata`.
|
|
280
|
+
- `provider.reset()` forgets tokens, registration and discovery - use it when a
|
|
281
|
+
server moved to another authorization server.
|
|
282
|
+
|
|
283
|
+
### Enterprise-managed authorization (ID-JAG)
|
|
284
|
+
|
|
285
|
+
When the company's identity provider decides who may use which MCP server (the
|
|
286
|
+
MCP extension `io.modelcontextprotocol/enterprise-managed-authorization`, also
|
|
287
|
+
called Cross App Access), there is no consent page and no redirect. Your app
|
|
288
|
+
already holds the user's OpenID Connect ID token from single sign-on; the
|
|
289
|
+
provider turns it into an access token in two POSTs: a token exchange at the IdP
|
|
290
|
+
(ID token in, an **ID-JAG** out), then a `jwt-bearer` grant at the MCP server's
|
|
291
|
+
authorization server (ID-JAG in, access token out).
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import { connectMcpHttp, createEnterpriseOAuthProvider } from '@dudko.dev/agent-web/mcp'
|
|
295
|
+
|
|
296
|
+
const provider = createEnterpriseOAuthProvider({
|
|
297
|
+
serverUrl: 'https://mcp.example.com/mcp',
|
|
298
|
+
clientId: 'agent-web', // at the MCP authorization server, a public client
|
|
299
|
+
expectedIssuer: 'https://auth.example.com', // required with a clientSecret, wise without
|
|
300
|
+
idp: { tokenEndpoint: 'https://acme.idp.example/oauth2/token', clientId: 'agent-web-at-idp' },
|
|
301
|
+
getIdToken: () => session.idToken, // yours: called for every new ID-JAG
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
const mcp = await connectMcpHttp({ docs: { url: 'https://mcp.example.com/mcp', authProvider: provider } })
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
- It runs before the first request when there is no usable token, and again
|
|
308
|
+
when the token expires or the server answers 401 - a fresh ID token and a
|
|
309
|
+
fresh exchange each time. No refresh token is used.
|
|
310
|
+
- Only the access token (and what discovery found) is stored, in the vault by
|
|
311
|
+
default (`storage`). The ID token and the ID-JAG are never stored, logged or
|
|
312
|
+
put in an error.
|
|
313
|
+
- Errors are `EnterpriseOAuthError` with `hop`: `'idp'`, `'authorization-server'`
|
|
314
|
+
or `'discovery'`. A refusal by the authorization server reads `MCP
|
|
315
|
+
authorization server refused the ID-JAG grant: invalid_grant (HTTP 400)` - the
|
|
316
|
+
code and the status, never the server's own text - at connect
|
|
317
|
+
(`results[].error`, `needsAuthorization` unset) and in the middle of a session
|
|
318
|
+
(the tool call fails with it). What the server said goes to `onLog` at `warn`
|
|
319
|
+
(to the package logger when there is none), with every token, assertion,
|
|
320
|
+
secret and key cut out first.
|
|
321
|
+
- **`expectedIssuer` is required with `clientSecret` and with `private_key_jwt`**
|
|
322
|
+
(the constructor throws otherwise): without it the MCP server's metadata would
|
|
323
|
+
choose who receives the secret, or which audience a signed assertion is made
|
|
324
|
+
for. A client with no credential at the authorization server may omit it: the
|
|
325
|
+
only thing sent there is then the ID-JAG, which the IdP addressed to that one
|
|
326
|
+
server.
|
|
327
|
+
- **`private_key_jwt`** (`clientAuthMethod` / `idp.clientAuthMethod`) signs a
|
|
328
|
+
client assertion with WebCrypto instead of sending a secret: `privateKey` (a
|
|
329
|
+
`CryptoKey` - make it non-extractable - or a JWK), `algorithm` (`ES256`,
|
|
330
|
+
`RS256`, ...), optional `keyId`, and `idp.issuer` for the IdP. The assertion's
|
|
331
|
+
only audience is the issuer of the server it is for, it lives 60 seconds and
|
|
332
|
+
carries a new `jti` each time.
|
|
333
|
+
- **`assertionAudience` / `assertionType`** (and the same two inside `idp`), for
|
|
334
|
+
a server built to RFC 7523 rather than to `draft-ietf-oauth-rfc7523bis`:
|
|
335
|
+
|
|
336
|
+
| Option | Values | Default |
|
|
337
|
+
| --- | --- | --- |
|
|
338
|
+
| `assertionAudience`, `idp.assertionAudience` | `'issuer'` or `'token-endpoint'`: what the assertion's `aud` is | `'issuer'` |
|
|
339
|
+
| `assertionType`, `idp.assertionType` | `'client-authentication+jwt'` or `'JWT'`: its `typ` header | `'client-authentication+jwt'` |
|
|
340
|
+
|
|
341
|
+
`'token-endpoint'` addresses the assertion to `idp.tokenEndpoint` (then
|
|
342
|
+
`idp.issuer` is not required) or, for the authorization server, to the token
|
|
343
|
+
endpoint of the discovered metadata once it matched `expectedIssuer`. It is
|
|
344
|
+
the weaker form - see
|
|
345
|
+
[docs/security.md](docs/security.md#mcp-enterprise-managed-authorization-id-jag) - so
|
|
346
|
+
use it only for a server that refuses the default.
|
|
347
|
+
- **`clientId` may be the https URL of a client ID metadata document** (CIMD),
|
|
348
|
+
with `private_key_jwt` or no credential, never with a `clientSecret`.
|
|
349
|
+
- **In a browser:** the IdP's token endpoint must allow your origin (CORS), and
|
|
350
|
+
a `clientSecret` (yours or `idp.clientSecret`) in a page is readable by anyone
|
|
351
|
+
who can open the page. So this provider is for public clients, or for a
|
|
352
|
+
`fetch` that routes the IdP call through your backend, which holds the
|
|
353
|
+
secret. See
|
|
354
|
+
[docs/security.md](docs/security.md#mcp-enterprise-managed-authorization-id-jag).
|
|
355
|
+
- Verified against a test identity provider, not a commercial one. Options,
|
|
356
|
+
checks and limits: [docs/capabilities.md](docs/capabilities.md#mcp-servers-behind-oauth).
|
|
357
|
+
|
|
263
358
|
### CORS: what the server must send
|
|
264
359
|
|
|
265
360
|
A browser tells JavaScript nothing about why it blocked a request — a CORS
|
|
@@ -362,9 +457,65 @@ thinking level, limits or system prompt. Give `persistence` a store
|
|
|
362
457
|
last checkpoint with `run('', { resumeFromRunId })` — the planner does not run again and
|
|
363
458
|
no finished step is repeated. `createRunControl()` steers a run that is going: `send()`
|
|
364
459
|
puts a message in front of the model at the next boundary (the replanner re-checks the plan
|
|
365
|
-
against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gives the model one safe `web_fetch` tool with allow / deny lists. `learning` (off by default) lets the agent write down what it figured out as skills of its own — in memory, or in the file system across sessions. Details, defaults and events:
|
|
460
|
+
against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gives the model one safe `web_fetch` tool with allow / deny lists. `sandbox` (off by default) gives the model `run_js`: the code it wrote runs in QuickJS-in-WebAssembly inside a Web Worker that is killed at the deadline, so "I ran it" is a tool call you can see. `learning` (off by default) lets the agent write down what it figured out as skills of its own — in memory, or in the file system across sessions. Details, defaults and events:
|
|
366
461
|
**[docs/capabilities.md](docs/capabilities.md)**.
|
|
367
462
|
|
|
463
|
+
## Pipelines: a graph of agents
|
|
464
|
+
|
|
465
|
+
A pipeline is a graph of agents - each node an agent with its own role, model and tools, each edge
|
|
466
|
+
passing one node's output to the next, optionally on a condition, loops allowed - described in
|
|
467
|
+
plain JSON, so it can be stored, shared and drawn by an editor.
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
import { createPipeline, nodeResolver } from '@dudko.dev/agent-web'
|
|
471
|
+
|
|
472
|
+
const definition = {
|
|
473
|
+
version: 1,
|
|
474
|
+
entry: 'writer',
|
|
475
|
+
nodes: [
|
|
476
|
+
{ id: 'writer', name: 'Writer', instructions: 'Write the text the request asks for.', model: 'smart' },
|
|
477
|
+
{
|
|
478
|
+
id: 'reviewer',
|
|
479
|
+
name: 'Reviewer',
|
|
480
|
+
instructions: 'Review the text. Be strict.',
|
|
481
|
+
routes: [{ label: 'approve', description: 'ready to publish' }, { label: 'revise' }],
|
|
482
|
+
},
|
|
483
|
+
{ id: 'publisher', instructions: 'Format the approved text for publication.', tools: ['files'] },
|
|
484
|
+
],
|
|
485
|
+
edges: [
|
|
486
|
+
{ from: 'writer', to: 'reviewer' },
|
|
487
|
+
{ from: 'reviewer', to: 'publisher', when: { kind: 'route', label: 'approve' } },
|
|
488
|
+
{ from: 'reviewer', to: 'writer', when: { kind: 'otherwise' } }, // the loop
|
|
489
|
+
],
|
|
490
|
+
limits: { maxNodeVisits: 3, maxRuns: 25 }, // the defaults
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const pipeline = createPipeline(definition, {
|
|
494
|
+
// What the names in the definition stand for. A name that is not here fails its node.
|
|
495
|
+
resolveNode: nodeResolver({
|
|
496
|
+
base: { model, credentials }, // a BrowserAgentConfig: every node starts from it
|
|
497
|
+
models: { smart: { providerType: 'openai', model: 'gpt-4o-mini', credentialRef: 'openai' } },
|
|
498
|
+
tools: { files: createFileTools(vfs) },
|
|
499
|
+
// skills: { ... }, mcpServers: { docs: mcp }, configure: (config, node) => config
|
|
500
|
+
}),
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
const result = await pipeline.run({
|
|
504
|
+
input: 'A release note for v2',
|
|
505
|
+
onEvent: (e) => {
|
|
506
|
+
if (e.type === 'pipeline.node.started') highlightNode(e.nodeId)
|
|
507
|
+
if (e.type === 'pipeline.edge') highlightEdge(e.from, e.to, e.fired)
|
|
508
|
+
},
|
|
509
|
+
})
|
|
510
|
+
result.text // the last node's answer; result.outputs, result.trace, result.usage, result.stoppedBy
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
**Abort:** `signal` aborts every running node and `run` resolves with what it has and `stoppedBy: 'aborted'`, as `agent.run` resolves with `stopped` (the Node sibling rejects with an `AbortError`, as its `agent.run` does). **Memory:** with `memory` in `base`, every node keeps a conversation of its own (`<sessionId>:<node id>`).
|
|
514
|
+
|
|
515
|
+
Conditions (`always`, `contains`, `matches`, `route`, `otherwise`), the scheduling rules (waves,
|
|
516
|
+
join, the loop caps), validation and the events: **[docs/capabilities.md](docs/capabilities.md#pipelines-a-graph-of-agents)**.
|
|
517
|
+
Loading a definition someone else wrote: [docs/security.md](docs/security.md#pipelines-a-definition-is-data).
|
|
518
|
+
|
|
368
519
|
## Configuration (highlights)
|
|
369
520
|
|
|
370
521
|
| Option | Default | Purpose |
|
|
@@ -379,6 +530,7 @@ against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gi
|
|
|
379
530
|
| `toolApproval` | autopilot | consent policy: `{ mode, rules, onRequest, timeoutMs }`; `agent.setToolApprovalMode()` |
|
|
380
531
|
| `skills` | — | SKILL.md bundles (`defineSkill` / `parseSkillMarkdown` / `loadSkillFromUrl`) |
|
|
381
532
|
| `egress` | off | what the **model** may fetch (`web_fetch`): `true` = any public host over https, or `{ allow, deny, protocols, allowPrivateNetwork, fetch, ... }`; a browser can't pin DNS, so prefer an `allow` list — see [Egress](docs/capabilities.md#egress-what-the-model-may-fetch) |
|
|
533
|
+
| `sandbox` | off | the model may **run JavaScript it wrote** (`run_js`) and read the real output: `true`, or `{ worker, timeoutMs, memoryLimitBytes, maxOutputChars, maxCodeChars, files, engine }`. QuickJS in WebAssembly (optional peer `quickjs-emscripten`), in a Web Worker you supply (`@dudko.dev/agent-web/sandbox-worker`) that is killed at the deadline; with `createFileTools` the guest can import / require workspace files and use `fs` — see [Running code](docs/capabilities.md#running-code-the-sandbox) |
|
|
382
534
|
| `learning` | off | the agent writes down lessons as skills (`save_skill` / `forget_skill`): `true` = this session, `{ store: new VfsSkillStore(vfs) }` = across sessions — see [Learning](docs/capabilities.md#learning-lessons-that-outlive-the-task) |
|
|
383
535
|
| `thinking` / `stageThinking` | provider default | `true`, a level (`'low'`…`'xhigh'`, `'none'`), or `{ level, budgetTokens, includeThoughts }` |
|
|
384
536
|
| `limits` | — | run caps `maxInputTokens` / `maxOutputTokens` / `maxReasoningTokens` / `maxTotalTokens` + `perCall` output caps |
|
|
@@ -406,9 +558,9 @@ against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gi
|
|
|
406
558
|
- [docs/design.md](docs/design.md) — architecture & rationale.
|
|
407
559
|
- [docs/capabilities.md](docs/capabilities.md) — thinking, limits, compaction,
|
|
408
560
|
caching, skills, tool consent / autopilot, large MCP catalogues, subagents,
|
|
409
|
-
steering a running agent, learning, egress, usage, resuming, autonomy, event reference.
|
|
561
|
+
steering a running agent, learning, egress, pipelines, usage, resuming, autonomy, event reference.steering a running agent, learning, egress, usage, resuming, autonomy, event reference.
|
|
410
562
|
- [docs/providers.md](docs/providers.md) — every provider, CORS & direct-vs-proxy.
|
|
411
|
-
- [docs/security.md](docs/security.md) — the token vault, egress and learning: threat models.
|
|
563
|
+
- [docs/security.md](docs/security.md) — the token vault, egress, learning and pipelines: threat models.— the token vault, egress and learning: threat models.
|
|
412
564
|
- [docs/tasks.md](docs/tasks.md) — status & roadmap.
|
|
413
565
|
- [`@dudko.dev/agent-web-react`](https://www.npmjs.com/package/@dudko.dev/agent-web-react) —
|
|
414
566
|
React bindings (`useAgent`, `<AgentProvider>`, pre-styled components) ·
|