@dudko.dev/agent-web 0.0.43 → 0.0.44

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.
Files changed (34) hide show
  1. package/README.md +55 -2
  2. package/dist/agent-web.js +158 -158
  3. package/dist/agent-web.js.map +1 -1
  4. package/dist/{chunk-DAREMCXF.js → chunk-236RCVAZ.js} +40 -8
  5. package/dist/chunk-236RCVAZ.js.map +1 -0
  6. package/dist/{chunk-2MLHZ6LQ.js → chunk-Y4MIIBPB.js} +2 -2
  7. package/dist/{chunk-ZSZSSJS4.js → chunk-Y6CD3WOK.js} +176 -10
  8. package/dist/chunk-Y6CD3WOK.js.map +1 -0
  9. package/dist/{chunk-YPCHD6DV.js → chunk-YGWIOO27.js} +31 -12
  10. package/dist/chunk-YGWIOO27.js.map +1 -0
  11. package/dist/index.cjs +1052 -93
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +1724 -1464
  14. package/dist/index.d.ts +1724 -1464
  15. package/dist/index.js +806 -74
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp.cjs +136 -5
  18. package/dist/mcp.cjs.map +1 -1
  19. package/dist/mcp.d.cts +5 -2
  20. package/dist/mcp.d.ts +5 -2
  21. package/dist/mcp.js +19 -8
  22. package/dist/mcp.js.map +1 -1
  23. package/dist/{sandbox-3VRX47UY.js → sandbox-7CGSIIIZ.js} +4 -4
  24. package/dist/sandbox-worker.cjs +30 -11
  25. package/dist/sandbox-worker.cjs.map +1 -1
  26. package/dist/sandbox-worker.js +1 -1
  27. package/dist/{elicitation-DS-84_bF.d.cts → vault-Mar2CY0J.d.cts} +526 -526
  28. package/dist/{elicitation-DS-84_bF.d.ts → vault-Mar2CY0J.d.ts} +526 -526
  29. package/package.json +1 -1
  30. package/dist/chunk-DAREMCXF.js.map +0 -1
  31. package/dist/chunk-YPCHD6DV.js.map +0 -1
  32. package/dist/chunk-ZSZSSJS4.js.map +0 -1
  33. /package/dist/{chunk-2MLHZ6LQ.js.map → chunk-Y4MIIBPB.js.map} +0 -0
  34. /package/dist/{sandbox-3VRX47UY.js.map → sandbox-7CGSIIIZ.js.map} +0 -0
package/README.md CHANGED
@@ -794,7 +794,7 @@ const agent = await createAgent({
794
794
  },
795
795
  })
796
796
  agent.setToolApprovalMode('autopilot') // flip the switch at any time
797
- await agent.compact() // summarise the stored transcript now
797
+ await agent.compact() // summarise the stored transcript now (waits for a run of the session; { wait: false } throws instead)
798
798
  ```
799
799
 
800
800
  With more than 40 tools (several MCP servers) the executor switches to **tool
@@ -963,6 +963,57 @@ sibling's `@dudko.dev/agent/pipeline-engine` is the same file. It is a copy of t
963
963
  entry carries, not the same objects: an error thrown by one is not `instanceof` the other's class -
964
964
  compare `error.name`. More: [docs/capabilities.md](docs/capabilities.md#pipelines-a-graph-of-agents).
965
965
 
966
+ ## Several tabs
967
+
968
+ An installed PWA window and a browser tab of the same site share IndexedDB - the vault, the files,
969
+ the memory. The library keeps them from working against each other (browser APIs only; a no-op
970
+ where the browser lacks them, and nothing for a store in memory):
971
+
972
+ ```ts
973
+ import {
974
+ createAgent,
975
+ createRunControl,
976
+ IndexedDBStore,
977
+ onStorageChange,
978
+ watchSession,
979
+ } from '@dudko.dev/agent-web'
980
+
981
+ // 1. After a write COMMITS, the other tabs hear which thing changed - never its value.
982
+ onStorageChange('agent-web', (c) => console.log(c)) // { kind: 'files', op: 'put', key: '/a.md', namespace: 'default' }
983
+
984
+ // 2. One session, one runner: a second run of `chat-1` (in any tab) waits for this one.
985
+ const agent = await createAgent({ model, memory: new IndexedDBStore(), sessionId: 'chat-1' })
986
+ // Holds the session's Web Lock; with a `control` it also takes messages from the other tabs.
987
+ void agent.run('Summarise the report', { control: createRunControl() })
988
+
989
+ // 3. In another tab: follow that run live, write to it, stop it.
990
+ const watch = watchSession({ sessionId: 'chat-1', onEvent: console.log, onState: console.log })
991
+ await watch.send('only the first chapter')
992
+ await watch.stop()
993
+ ```
994
+
995
+ - **Change notices** (`credentials`, `oauth`, `files`, `session`, `runs`, `skills`, and the React
996
+ package's `chats`): one channel per database name, sent after the transaction completed, never for
997
+ a failed write, never heard by the tab that wrote. A store of your own posts with
998
+ `postStorageChange`. `agent.reloadLearnedSkills()` re-reads the notebook after a `skills` notice.
999
+ - **`sessionLock`** (`'wait'` default, `'fail'`, `'off'`): the session's Web Lock for the run's whole
1000
+ duration, released however it ends (and by the browser when the tab closes). Subagents that share
1001
+ the session run under the parent's hold; helpers and pipeline nodes have sessions of their own.
1002
+ - **A behaviour change** for a host that ran one session in several tabs: the second run now waits
1003
+ for the first (one `logger.warn` the first time, "this run waits for it"). `sessionLock: 'off'`
1004
+ keeps the old behaviour; the wait has no timeout of its own (pass a `signal`);
1005
+ `agent.compact({ wait: false })` throws `SessionBusyError` instead of waiting.
1006
+ - **`sessionRelay`** (`{ control: true }` default, `{ control: false }`, `false`): what the running
1007
+ tab offers the others - events (posted only once a tab asks), and with `control` a message
1008
+ (marked `origin: 'another-tab'`) or a stop.
1009
+ - **`watchSession`**: the run's events (clipped), its state (`running`, `ended: 'done' | 'stopped' |
1010
+ 'gone'`), a replay for a tab that joins late, `send` and `stop`. Tool approvals never cross: they
1011
+ are answered in the tab that runs the tool.
1012
+
1013
+ Details: [Several tabs](docs/capabilities.md#several-tabs) ·
1014
+ [what crosses, and who can post](docs/security.md#several-tabs-what-crosses-and-who-can-post) ·
1015
+ [why not a SharedWorker](docs/design.md#several-tabs-broadcastchannel-and-web-locks-not-a-sharedworker).
1016
+
966
1017
  ## Configuration (highlights)
967
1018
 
968
1019
  | Option | Default | Purpose |
@@ -999,6 +1050,8 @@ compare `error.name`. More: [docs/capabilities.md](docs/capabilities.md#pipeline
999
1050
  | `describeState` | — | serialize world state into prompt context |
1000
1051
  | `memory` | — | `ContextStore` (`IndexedDBStore` / `MemoryStore`); recent turns are read back into the planner prompt |
1001
1052
  | `sessionId` | — | names the stored conversation in `memory`, and the bucket `agent.sessionUsage()` counts into |
1053
+ | `sessionRelay` | `{ control: true }` | what the session's running tab offers the site's other tabs: its events (posted once a tab asks) and, with `control`, a message (`origin: 'another-tab'`) or a stop. `{ control: false }`: watchable only; `false`: nothing relayed — see [security](docs/security.md#several-tabs-what-crosses-and-who-can-post) |
1054
+ | `sessionLock` | `'wait'` | one run per session across the site's tabs, when `memory` is shared (`IndexedDBStore`): a second run of the session waits for the first (`session.busy` / `session.acquired`), `'fail'` throws `SessionBusyError`, `'off'` = no lock and no relay (the last write wins). The running tab relays the run to the others (`watchSession`) — see [Several tabs](#several-tabs) |
1002
1055
  | `persistence` | — | checkpoint runs (`IndexedDBRunStore` / `MemoryRunStore`) so `run(goal, { resumeFromRunId })` continues after a reload; hooks `onRunStart` / `onStepComplete` / `onRunComplete` / `onRunResume` (a resume's new `attempt`, before any event) / `loadRun` — see [Resuming](docs/capabilities.md#resuming-an-interrupted-run) |
1003
1056
  | `maxIterations` / `maxStepsPerTask` / `maxRevisions` | 8 / 4 / 2 | loop caps |
1004
1057
  | `chatTimeoutMs` | 120000 | per-call watchdog; for the executor, the whole step (its tool calls included). Stopped while a tool call waits for a person (an approval, an MCP question): the step goes on with the time it had left - see [Tool consent](docs/capabilities.md#tool-consent-and-autopilot) |
@@ -1069,7 +1122,7 @@ If you do import it:
1069
1122
  - [docs/design.md](docs/design.md) — architecture & rationale.
1070
1123
  - [docs/capabilities.md](docs/capabilities.md) — thinking, limits, compaction,
1071
1124
  caching, skills, tool consent / autopilot, large MCP catalogues, subagents,
1072
- steering a running agent, learning, egress, pipelines, usage, resuming, autonomy, event reference.steering a running agent, learning, egress, usage, resuming, autonomy, event reference.
1125
+ steering a running agent, several tabs, learning, egress, pipelines, usage, resuming, autonomy, event reference.steering a running agent, learning, egress, usage, resuming, autonomy, event reference.
1073
1126
  - [docs/providers.md](docs/providers.md) — every provider, CORS & direct-vs-proxy.
1074
1127
  - [docs/security.md](docs/security.md) — the token vault, egress, learning and pipelines: threat models.— the token vault, egress and learning: threat models.
1075
1128
  - [docs/tasks.md](docs/tasks.md) — status & roadmap.