pi-roundtable 0.44.1 → 0.45.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/CHANGELOG.md +31 -0
- package/docs/plugins.md +36 -2
- package/package.json +2 -2
- package/src/core/agents/agent-claim.ts +15 -21
- package/src/core/agents/agent-messages.ts +10 -10
- package/src/core/agents/agent-prompt.ts +7 -8
- package/src/core/agents/agent-rules.ts +9 -2
- package/src/core/agents/agent-store.ts +16 -0
- package/src/core/agents/agent-team-fake-channels.ts +105 -0
- package/src/core/agents/agent-team-fixture.ts +30 -105
- package/src/core/agents/agent-team.ts +20 -21
- package/src/core/agents/group-turns.ts +8 -15
- package/src/core/agents/helper-modes.ts +7 -13
- package/src/core/agents/helper-work.ts +7 -6
- package/src/core/agents/message-target.ts +24 -12
- package/src/core/agents/room-progress.ts +8 -6
- package/src/core/agents/routes.ts +24 -47
- package/src/core/agents/team-editing.ts +5 -8
- package/src/core/agents/team-keys.ts +5 -190
- package/src/core/agents/team-lifecycle.ts +23 -39
- package/src/core/agents/team-options.ts +1 -1
- package/src/core/agents/team-places.ts +335 -0
- package/src/core/agents/team-posts.ts +157 -0
- package/src/core/agents/team-prompt.ts +3 -3
- package/src/core/agents/team-status.ts +18 -10
- package/src/core/agents/team-turn-types.ts +5 -8
- package/src/core/agents/team-turns.ts +26 -169
- package/src/core/builtin/agent-server-test-kit.ts +29 -0
- package/src/core/builtin/agent-server.ts +19 -12
- package/src/core/builtin/discord.ts +6 -0
- package/src/core/contract/places.ts +141 -0
- package/src/core/discord/agent-places.ts +215 -0
- package/src/core/discord/discord-surface.ts +13 -0
- package/src/core/host/define-roundtable.ts +1 -0
- package/src/core/plugin-api/agent-assets.ts +36 -0
- package/src/core/plugin-api/plugin-context.ts +30 -0
- package/src/core/plugin-api/plugin.ts +10 -28
- package/src/core/plugin-api/services.ts +20 -39
- package/src/core/registry/claims.ts +120 -0
- package/src/core/registry/contributions.ts +36 -118
- package/src/core/registry/place-port.ts +94 -0
- package/src/core/registry/places.ts +43 -0
- package/src/core/testing/fake-pager-places.ts +120 -0
- package/src/core/testing/fake-room-surface.ts +60 -0
- package/src/core/testing/modules.ts +5 -5
- package/src/core/testing/place-contract.ts +481 -0
- package/src/core/testing/team-places.ts +121 -0
- package/src/core/testing/test-host.ts +36 -10
- package/src/discord/index.ts +2 -0
- package/src/index.ts +12 -0
- package/src/testing.ts +15 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,37 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.45.1] - 2026-11-10
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- pi-roundtable-web: The chat home no longer pins Home (the coordinator's room) in the dock or on top: it is the first row of the All list, whatever spoke last, and its unread shows among the other unread under a folder tab. The pins are only the rooms the owner pinned.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- pi-roundtable-web: A group's stacked figures no longer draw over the chat home's bottom bar as the list scrolls under it.
|
|
17
|
+
|
|
18
|
+
## [0.45.0] - 2026-11-10
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- pi-roundtable-web: The web console can open on a chat list: set `appearance.home: "chats"` and the app opens on the pinned rooms as big figures, folder chips that filter one list of the other rooms by latest activity, and one row for the hidden and archived rooms. The tab bar and the rail are gone; a grid button opens every other pane, a back bar leads home, and from 1024 px the home is a 380 px column beside the open room. The default `"rooms"` keeps the arranged room list.
|
|
23
|
+
- pi-roundtable-web: Rooms can be hidden (`PUT api/rooms/<key>/hidden`, owner only, shared by every owner): a hidden room keeps answering, running schedules and pushing and leaves only the home and the switcher. `GET api/rooms` and the layout answers carry `hidden`; the migration `web-room-hidden` adds its table.
|
|
24
|
+
- `PlaceProvider`, the contract for where an agent or group is spoken to on a chat surface, with `PlaceRef`, `PlacePost`, `PlaceSpec`, `PlaceCheck`, `PlaceAuthor`, `PlaceKind`, `ToolArgument` and `PlacePort`. A plugin contributes providers with the new `places` part, one per surface, and reads them through `context.places` once every plugin is set up (`of(surface or key)`, `stored()`, `all()`). Two providers for one surface, or one for a surface no plugin registers, stop the boot with a `PluginError` naming the plugins.
|
|
25
|
+
- A surface that declares `agentRooms: true` and has no provider gets a derived one from the host, so the web app and any plugin written before this change keep working untouched. The Discord plugin contributes its own, over the agent guild's channels and threads, when `discord.guild` is set; its `check` tells a channel of another server (`foreign`) from a deleted one (`gone`). The agent team does not use providers yet.
|
|
26
|
+
- `placeProviderContract` in `pi-roundtable/testing` runs the provider contract against any provider, with `checkPlaceProviderContract` for the failures as data, and `PlaceContractSubject`, `PlaceContractFailure` and `PlaceSeen` for what it takes and returns.
|
|
27
|
+
- The agent team reads where its agents and groups are through the place providers: an agent's keys, who owns a key, the routing table, a group's seats and log names, a message the outbox replays, and the agent server's claim of a space. A provider that keeps its places in `agent_places` (a chat network the core has never heard of) now gets its places as keys, owners, routes and reply targets with no change to the core. Every key a Discord team has stays what it was, so sessions, schedules and held actions carry over. A row of a surface no provider serves on the host is ignored, which replaces the old "no Discord channels" switch.
|
|
28
|
+
- `AgentTeam.placesOf(name)`, `AgentTeam.teamId`, `AgentDirectory.placeOwner(key)` and the `places` of the `TeamStatus` views (`TeamPlace`) are new, all optional on their interfaces. `roomsOf` lists every place, the stored ones first.
|
|
29
|
+
- `Agent.channelId`, `AgentGroup.channelId`, `AgentSeed.channelId`, `AgentDirectory.agentByChannel` and `groupByChannel`, `AgentTeam.guildId` and `discordGuild`, and the `channelId` of the `TeamStatus` views are deprecated and removed in 1.0; read `placesOf` and `placeOwner`. The team still keeps them up to date.
|
|
30
|
+
- The web console reads the team's `places` for its channel links and its `teamId` for the team's name.
|
|
31
|
+
- The stand-in Discord of `testHost` contributes Discord's place provider when the test host has an agent guild, as the built-in plugin does. A plugin that replaces `DISCORD` with a Discord of its own, in a host with an agent guild, must contribute that provider too: `discordPlaceProvider` from `pi-roundtable/discord`, given the `guild`, the `connection` and a `logger` (`DiscordPlaceProviderOptions`), is the built-in one, with the keys, group seats and log names Discord's teams have always had, so contribute it with `places`. A host with an agent guild and a Discord that has no such provider now refuses to start, naming it, instead of leaving the agents unanswered.
|
|
32
|
+
- A key of a surface no provider serves is no room: a message kept for one is dropped on the next start without a model turn, as before, and a group seat whose home is such a key posts there.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- `pi-better-show` is pinned to 0.5.0. An interactive block (`options`, `suggest`, `form`, `checklist`, `review`) now has an "Other comments" box: the web app sends its text as the reserved field `pi-note`, keeps it in the block's recorded answer, and the owner's message to the agent ends with `Other comments: …`.
|
|
37
|
+
- On Discord and LINE, a block read as text now says other comments are welcome (for example "Reply with a number. Other comments are welcome.").
|
|
38
|
+
|
|
8
39
|
## [0.44.1] - 2026-11-09
|
|
9
40
|
|
|
10
41
|
### Added
|
package/docs/plugins.md
CHANGED
|
@@ -180,12 +180,13 @@ A plugin that replaces `IDENTITY` replaces this too: the declarations are the bu
|
|
|
180
180
|
| `services` | The services plugins provide to each other, read by key: `services.get(SCHEDULES)`; see [services](#services-what-plugins-provide-to-each-other) |
|
|
181
181
|
| `attachments` | Files a plugin takes from a person outside a turn, such as an upload, kept for a conversation until a turn uses them: [`attachments`](#contextattachments-files-from-outside-a-turn) |
|
|
182
182
|
| `surfaces` | Every contributed [chat surface](#surfaces-a-chat-network-of-your-own), chosen by the prefix of a channel key: `of`, `sendReply`, `startTyping`, `showStop`, `react`, `unreact`, `prompts` |
|
|
183
|
+
| `places` | The agent team's [place providers](#places-where-the-agents-are-spoken-to-on-a-surface), chosen by surface or by a channel key: `of`, `stored()`, `all()` |
|
|
183
184
|
| `turns` | Runs one turn of a conversation your claim owns, over the runtime and the surfaces: [`turns.run`](#personas-and-contextturns-conversations-of-a-kind-of-your-own) |
|
|
184
185
|
| `observe(filter, observer)` | Hears inbound messages without owning or admitting them: [`observe`](#observe-hearing-messages-without-owning-them). Returns a function that stops it; may be called during `setup` |
|
|
185
186
|
| `directChannels` | Every plugin's [direct channels](#directchannels-reaching-a-person-on-their-own): `providers()`, `reach(origin, principalId)`, `known(origin, principalId)`, and `notify(origin, principalId, text)`, each through the [delivery router](#where-things-are-delivered) |
|
|
186
|
-
| `sessions()`, `conversations`, `surfaces`, `directChannels`, `turns`, `dashboard()`, `chatCommands()` | Linked once every plugin has been set up; calling them during `setup` throws `NotLinkedError` |
|
|
187
|
+
| `sessions()`, `conversations`, `surfaces`, `places`, `directChannels`, `turns`, `dashboard()`, `chatCommands()` | Linked once every plugin has been set up; calling them during `setup` throws `NotLinkedError` |
|
|
187
188
|
|
|
188
|
-
`sessions()`, `conversations`, `surfaces`, `directChannels`, `turns`, `dashboard()`, and `chatCommands()` are available from a service's `start`, an event handler, a session tool, or a claim's turn.
|
|
189
|
+
`sessions()`, `conversations`, `surfaces`, `places`, `directChannels`, `turns`, `dashboard()`, and `chatCommands()` are available from a service's `start`, an event handler, a session tool, or a claim's turn.
|
|
189
190
|
|
|
190
191
|
Use `QueuePort` from the main entry for `context.queue`; the kit's `ChannelQueue` is also type-only.
|
|
191
192
|
|
|
@@ -3239,6 +3240,22 @@ The built-in values: Discord says that Markdown renders except tables, which sho
|
|
|
3239
3240
|
A host overrides or removes a built-in value through that surface's options (`discord.formatting`, `line({ formatting })`, `webChat({ formatting })`): a text replaces it, and `false` tells the model nothing.
|
|
3240
3241
|
A custom runtime provider reads the same lookup as `RuntimeDeps.formatting(channel)`.
|
|
3241
3242
|
|
|
3243
|
+
### `places`: where the agents are spoken to on a surface
|
|
3244
|
+
|
|
3245
|
+
A `PlaceProvider` tells the agent team where an agent or group lives on one surface and how to post there.
|
|
3246
|
+
A plugin contributes one per surface with `places: [provider]`, and reads them through `context.places` once every plugin is set up: `of(surface)` or `of(key)` for one, `stored()` for those that keep ids of their own, and `all()` in the order "auto" routing prefers (the stored ones in contribution order, then the derived ones in surface order).
|
|
3247
|
+
Two providers for one surface, or one for a surface no plugin registers, stop the boot with a `PluginError` naming the plugins.
|
|
3248
|
+
|
|
3249
|
+
A provider is `derived` when the place exists with the name (a room, `<surface>:agent.<name>`) and `stored` when the surface makes the places and the team keeps their ids.
|
|
3250
|
+
The members a minimal provider needs are `surface`, `storage`, `key`, `placeOf` and `post`; `ensure`, `remove`, `check` (`ok`, `gone` or `foreign`), `describe`, `onRemoved`, `interim`, `space`, `mention`, `conversations`, `coordinatorPlace`, `createArguments` and `layoutText` are optional capabilities.
|
|
3251
|
+
A surface with `agentRooms: true` and no provider gets a derived one from the host, so a surface written before places needs no change.
|
|
3252
|
+
The Discord plugin contributes its own when `discord.guild` is set.
|
|
3253
|
+
A plugin that replaces `DISCORD` with a Discord of its own, on a host with `discord.guild`, contributes `discordPlaceProvider({ guild, connection, logger })` from `pi-roundtable/discord` with `places`: it gives the guild's channels the keys, group seats and log names the built-in Discord gives them (pass `client` too to have the team check its stored channels at start). Without a provider for the `discord` surface the host refuses to start, since the team would make channels it cannot read.
|
|
3254
|
+
|
|
3255
|
+
The agent team reads its places through the providers: the keys of an agent or group (`AGENTS.team.roomsOf(name)`, and `placesOf(name)` with each key's surface), who owns a key (`AGENTS.team.owns(key)`, and `AGENTS.directory.placeOwner(key)` for an archived owner too), the routing table, the conversation keys of a group's seats and log, and the outbox replay. A stored provider's places are the rows of `agent_places`; a derived provider's are rooms. "Auto" order puts every stored place before the rooms, so with Discord configured the Discord channel is still an agent's primary place. A row of a surface no provider serves on this host is kept and ignored. `TeamStatus` views carry `places` (`TeamPlace`: `{ surface, key }`). `Agent.channelId`, `AgentGroup.channelId`, `AgentDirectory.agentByChannel` and `groupByChannel`, `AgentTeam.guildId` and `discordGuild`, and the status views' `channelId` are deprecated and removed in 1.0; the team still writes them. Writes (making, archiving and posting in places) still go through Discord's channels directly.
|
|
3256
|
+
|
|
3257
|
+
`placeProviderContract(name, make)` from `pi-roundtable/testing` registers the provider contract as tests for any provider; `make` returns a `PlaceContractSubject` with the provider and a view of what a person on the surface sees.
|
|
3258
|
+
|
|
3242
3259
|
### Display blocks in a reply
|
|
3243
3260
|
|
|
3244
3261
|
An agent may write a *display block* in a reply: a fenced block whose first word is a kind (`cards`, `table`, `steps`, `stats`, `mindmap`, `mermaid`, `diff`, `options`, `form`, ...) or a GitHub alert (`> [!NOTE]`), as `pi-better-show` defines. A block is YAML or source that only a surface that draws it should show, so the host cuts agent text with `chunksFor(surface, text)` (from `pi-roundtable/kit`), never `splitReply` alone: a block whose kind the surface does not list in `blocks` becomes text first (Discord's flavor by default, `blockText: "line"` for plain text; a diagram is drawn as Unicode boxes, unless its source is over 3 KB or the drawing, which runs in a worker the host waits on for at most 500 ms, is not done by then, and then the source is shown), and the result is split into messages within Discord's limit. A surface that lists any kind in `blocks` gets the text whole in one chunk, because cutting a fence breaks the block. `textFor(surface, text)` does the conversion alone, for a surface that shows a message of any length in one piece (the web chat's replies and inbox notices) and so needs no cutting. A block that is not closed at the end of the reply is still a block: a text surface gets it as text, and a surface that draws it gets it as written. A block that does not parse becomes a plain code block. The same applies to interim posts: the host's surface port copies the surface's `blocks` and `blockText` onto the `InterimPosts` it returns, so the poster cuts for the right surface. A surface whose channels differ (a host's room, read on a page that does not draw blocks) answers `support(channel)` with what is different, and `supportOf(surface, channel)` (from `pi-roundtable/kit`) reads the result; the formatting guidance a turn gets follows it too. A surface that does not draw every interactive kind (`options`, `suggest`, `form`, `checklist`, `review`) gets one more line, closing its `formatting`, which tells the model the chat cannot show forms, option buttons or checklists, to ask in plain text, and that such a block is shown as text for the user to answer by typing; `blockNote: false` leaves it out. A block that reads as text asks in the host's language: `supportOf(surface, channel, surfaces.lang)` carries the locale the host was defined with, and the surface's own `lang` wins. Host notices and error reports are the host's own text and keep `splitReply`.
|
|
@@ -4653,6 +4670,14 @@ Import from the entries listed below; source area files are internal.
|
|
|
4653
4670
|
| `PersonDisplay` | `pi-roundtable` | type |
|
|
4654
4671
|
| `PersonProfiles` | `pi-roundtable` | type |
|
|
4655
4672
|
| `Persona` | `pi-roundtable` | type |
|
|
4673
|
+
| `PlaceAuthor` | `pi-roundtable` | type |
|
|
4674
|
+
| `PlaceCheck` | `pi-roundtable` | type |
|
|
4675
|
+
| `PlaceKind` | `pi-roundtable` | type |
|
|
4676
|
+
| `PlacePort` | `pi-roundtable` | type |
|
|
4677
|
+
| `PlacePost` | `pi-roundtable` | type |
|
|
4678
|
+
| `PlaceProvider` | `pi-roundtable` | type |
|
|
4679
|
+
| `PlaceRef` | `pi-roundtable` | type |
|
|
4680
|
+
| `PlaceSpec` | `pi-roundtable` | type |
|
|
4656
4681
|
| `PlaceTarget` | `pi-roundtable` | type |
|
|
4657
4682
|
| `PluginContext` | `pi-roundtable` | type |
|
|
4658
4683
|
| `PluginIdentity` | `pi-roundtable` | type |
|
|
@@ -4771,6 +4796,7 @@ Import from the entries listed below; source area files are internal.
|
|
|
4771
4796
|
| `THREADS` | `pi-roundtable` | value |
|
|
4772
4797
|
| `TIERS` | `pi-roundtable` | value |
|
|
4773
4798
|
| `TeamAgentStatus` | `pi-roundtable` | type |
|
|
4799
|
+
| `TeamPlace` | `pi-roundtable` | type |
|
|
4774
4800
|
| `TeamStatus` | `pi-roundtable` | type |
|
|
4775
4801
|
| `ThinkingLevel` | `pi-roundtable` | type |
|
|
4776
4802
|
| `ThinkingSetting` | `pi-roundtable` | type |
|
|
@@ -4778,6 +4804,7 @@ Import from the entries listed below; source area files are internal.
|
|
|
4778
4804
|
| `TierConfig` | `pi-roundtable` | type |
|
|
4779
4805
|
| `ToolAttachment` | `pi-roundtable` | type |
|
|
4780
4806
|
| `ToolAttachmentInfo` | `pi-roundtable` | type |
|
|
4807
|
+
| `ToolArgument` | `pi-roundtable` | type |
|
|
4781
4808
|
| `ToolContribution` | `pi-roundtable` | type |
|
|
4782
4809
|
| `ToolOutput` | `pi-roundtable` | type |
|
|
4783
4810
|
| `ToolRefusal` | `pi-roundtable` | value |
|
|
@@ -4849,6 +4876,11 @@ Import from the entries listed below; source area files are internal.
|
|
|
4849
4876
|
| `describeBlocksContract` | `pi-roundtable/testing` | value |
|
|
4850
4877
|
| `describeSurfaceContract` | `pi-roundtable/testing` | value |
|
|
4851
4878
|
| `checkSurfaceContract` | `pi-roundtable/testing` | value |
|
|
4879
|
+
| `checkPlaceProviderContract` | `pi-roundtable/testing` | value |
|
|
4880
|
+
| `placeProviderContract` | `pi-roundtable/testing` | value |
|
|
4881
|
+
| `PlaceContractFailure` | `pi-roundtable/testing` | type |
|
|
4882
|
+
| `PlaceContractSubject` | `pi-roundtable/testing` | type |
|
|
4883
|
+
| `PlaceSeen` | `pi-roundtable/testing` | type |
|
|
4852
4884
|
| `SurfaceContractFailure` | `pi-roundtable/testing` | type |
|
|
4853
4885
|
| `SurfaceContractSubject` | `pi-roundtable/testing` | type |
|
|
4854
4886
|
| `SurfaceObservation` | `pi-roundtable/testing` | type |
|
|
@@ -5104,6 +5136,7 @@ Import from the entries listed below; source area files are internal.
|
|
|
5104
5136
|
| `DiscordCard` | `pi-roundtable/discord` | type |
|
|
5105
5137
|
| `DiscordFailure` | `pi-roundtable/discord` | type |
|
|
5106
5138
|
| `DiscordMessage` | `pi-roundtable/discord` | type |
|
|
5139
|
+
| `DiscordPlaceProviderOptions` | `pi-roundtable/discord` | type |
|
|
5107
5140
|
| `DiscordPoster` | `pi-roundtable/discord` | type |
|
|
5108
5141
|
| `DiscordReason` | `pi-roundtable/discord` | type |
|
|
5109
5142
|
| `ForumPost` | `pi-roundtable/discord` | type |
|
|
@@ -5131,6 +5164,7 @@ Import from the entries listed below; source area files are internal.
|
|
|
5131
5164
|
| `commandGuard` | `pi-roundtable/discord` | value |
|
|
5132
5165
|
| `composeCommands` | `pi-roundtable/discord` | value |
|
|
5133
5166
|
| `discord` | `pi-roundtable/discord` | value |
|
|
5167
|
+
| `discordPlaceProvider` | `pi-roundtable/discord` | value |
|
|
5134
5168
|
| `ephemeralPanel` | `pi-roundtable/discord` | value |
|
|
5135
5169
|
| `fetchManagedChannel` | `pi-roundtable/discord` | value |
|
|
5136
5170
|
| `groupOption` | `pi-roundtable/discord` | value |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-roundtable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.1",
|
|
4
4
|
"description": "A plugin-driven Pi agent server for one owner, reached through Discord or the web",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"canvas": "3.2.3",
|
|
74
74
|
"discord.js": "14.27.0",
|
|
75
75
|
"pi-jev-compaction": "1.0.0",
|
|
76
|
-
"pi-better-show": "0.
|
|
76
|
+
"pi-better-show": "0.5.0",
|
|
77
77
|
"pi-mcp-adapter": "5.3.0",
|
|
78
78
|
"pino": "10.4.0",
|
|
79
79
|
"typebox": "1.3.37",
|
|
@@ -23,14 +23,13 @@ import { outcome } from "../routing/settle-turn.ts";
|
|
|
23
23
|
import { systemTurn } from "../routing/system-turns.ts";
|
|
24
24
|
import { PERSONAL_TARGET } from "../shared/personal-target.ts";
|
|
25
25
|
import type { DiscordAgentTeam } from "./agent-team.ts";
|
|
26
|
-
import { discordIdOf, roomOf } from "./team-keys.ts";
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
|
-
* The agent server outranks every other claim on the
|
|
30
|
-
*
|
|
31
|
-
* plugin
|
|
32
|
-
* the
|
|
33
|
-
* another of
|
|
28
|
+
* The agent server outranks every other claim on the places it owns, and the other channels of a
|
|
29
|
+
* space a place provider names (the Discord guild of the agents) stay silent even when another
|
|
30
|
+
* plugin's mode or a mention would answer there; a claim of a plugin must use a higher priority to
|
|
31
|
+
* answer in that space. It owns the places of an agent or group of the team, and the rooms on a
|
|
32
|
+
* surface that declares `agentRooms`, never another of a surface's keys. It becomes the core's reserved branch once the team moves into the core
|
|
34
33
|
* (pi-roundtable batch 7).
|
|
35
34
|
*/
|
|
36
35
|
export const AGENT_SERVER_PRIORITY = 100;
|
|
@@ -51,10 +50,11 @@ export interface AgentClaimOptions {
|
|
|
51
50
|
*/
|
|
52
51
|
speakers?: "everyone" | "owners";
|
|
53
52
|
/**
|
|
54
|
-
* The
|
|
55
|
-
*
|
|
53
|
+
* The space of the place provider that serves a channel's surface, such as the Discord guild the
|
|
54
|
+
* agents' channels live in: a message from that space is the agent server's even outside the
|
|
55
|
+
* places it knows. Absent, or undefined for a surface whose provider names none, there is none.
|
|
56
56
|
*/
|
|
57
|
-
|
|
57
|
+
spaceOf?: (channel: ChannelKey) => string | undefined;
|
|
58
58
|
team: Pick<
|
|
59
59
|
DiscordAgentTeam,
|
|
60
60
|
| "owns"
|
|
@@ -65,12 +65,9 @@ export interface AgentClaimOptions {
|
|
|
65
65
|
| "startFresh"
|
|
66
66
|
>;
|
|
67
67
|
runtime: Pick<AgentRuntime, "steer" | "stop">;
|
|
68
|
-
/**
|
|
69
|
-
* `roomSurfaces` names the surfaces whose agent and group rooms the claim may own, and `of`
|
|
70
|
-
* finds the surface that reads a message's attachments; without them the claim is Discord's alone.
|
|
71
|
-
*/
|
|
68
|
+
/** `of` finds the surface that reads a message's attachments; without it every message's are fetched. */
|
|
72
69
|
surface: Pick<SurfacePort, "react" | "unreact"> &
|
|
73
|
-
Partial<Pick<SurfacePort, "
|
|
70
|
+
Partial<Pick<SurfacePort, "of">>;
|
|
74
71
|
/**
|
|
75
72
|
* Where the report turn of a webhook's post in an agent's channel runs, given the channel it was
|
|
76
73
|
* posted in: the routing table's `integration` rule. Without it, in that channel.
|
|
@@ -182,14 +179,11 @@ export function agentClaim(options: AgentClaimOptions): ChannelClaim {
|
|
|
182
179
|
return {
|
|
183
180
|
name: "agent-server",
|
|
184
181
|
priority: AGENT_SERVER_PRIORITY,
|
|
185
|
-
//
|
|
186
|
-
//
|
|
182
|
+
// The place of an agent or group, or any channel of a provider's space: another surface's
|
|
183
|
+
// key is never the agent server's, whatever its id, and a room needs a known name.
|
|
187
184
|
owns: (channel, space) =>
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
(space !== undefined && space === options.discordGuild)
|
|
191
|
-
: roomOf(channel, surface.roomSurfaces?.() ?? []) !== undefined &&
|
|
192
|
-
team.owns(channel) !== undefined,
|
|
185
|
+
team.owns(channel) !== undefined ||
|
|
186
|
+
(space !== undefined && options.spaceOf?.(channel) === space),
|
|
193
187
|
admit: (message) => {
|
|
194
188
|
const owned = team.owns(message.channel);
|
|
195
189
|
// The agent server's other channels are the owner's notes: nothing there is answered.
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
import { answersTo } from "./agent-rules.ts";
|
|
18
18
|
import type { Agent } from "./agent-store.ts";
|
|
19
19
|
import { conversationLabel, messageTarget } from "./message-target.ts";
|
|
20
|
-
import { discordIdOf, discordKey, scopeOf } from "./team-keys.ts";
|
|
21
20
|
import {
|
|
22
21
|
type Chain,
|
|
23
22
|
MAX_CHAIN_MESSAGES,
|
|
@@ -47,7 +46,7 @@ export class AgentMessages {
|
|
|
47
46
|
text: string,
|
|
48
47
|
conversation?: string,
|
|
49
48
|
): string {
|
|
50
|
-
const { store, queue, logger,
|
|
49
|
+
const { store, queue, logger, places } = this.#host.options;
|
|
51
50
|
if (to === caller.name)
|
|
52
51
|
throw new AgentError("message_agent is for other agents, not yourself.");
|
|
53
52
|
const target = store.activeAgent(to);
|
|
@@ -57,7 +56,7 @@ export class AgentMessages {
|
|
|
57
56
|
const targetChannel = messageTarget(
|
|
58
57
|
{
|
|
59
58
|
store,
|
|
60
|
-
|
|
59
|
+
places,
|
|
61
60
|
latest: store.conversations.latest(target.name),
|
|
62
61
|
from: parent,
|
|
63
62
|
routes: this.#host.routes,
|
|
@@ -169,7 +168,7 @@ export class AgentMessages {
|
|
|
169
168
|
});
|
|
170
169
|
const result = await this.#host.turn(
|
|
171
170
|
target,
|
|
172
|
-
scopeOf(target, targetChannel),
|
|
171
|
+
this.#host.options.places.scopeOf(target, targetChannel),
|
|
173
172
|
targetChannel,
|
|
174
173
|
agentMessageText(
|
|
175
174
|
this.#host.current(sender),
|
|
@@ -233,7 +232,7 @@ export class AgentMessages {
|
|
|
233
232
|
#followUp(sender: Agent, channel: ChannelKey, text: string, chain: Chain) {
|
|
234
233
|
return this.#host.turn(
|
|
235
234
|
sender,
|
|
236
|
-
scopeOf(sender, channel),
|
|
235
|
+
this.#host.options.places.scopeOf(sender, channel),
|
|
237
236
|
channel,
|
|
238
237
|
text,
|
|
239
238
|
chain,
|
|
@@ -314,16 +313,17 @@ export class AgentMessages {
|
|
|
314
313
|
}
|
|
315
314
|
|
|
316
315
|
async #replayOne(entry: StoredOutboxEntry): Promise<void> {
|
|
317
|
-
const { store, logger } = this.#host.options;
|
|
316
|
+
const { store, logger, places } = this.#host.options;
|
|
318
317
|
if (!(await store.outbox.claim(entry.id))) return;
|
|
319
318
|
const sender = store.agent(entry.sender);
|
|
320
319
|
const target = store.agent(entry.target);
|
|
321
|
-
// An agent archived or moved to another
|
|
320
|
+
// An agent archived or moved to another place since has no turn to give the entry; nor has a
|
|
321
|
+
// key of a surface no provider serves, which is no room.
|
|
322
322
|
const has = (agent: Agent | undefined, channel: ChannelKey) =>
|
|
323
323
|
agent?.status === "active" &&
|
|
324
|
-
(
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
places.serves(channel) &&
|
|
325
|
+
(!places.isStored(channel) ||
|
|
326
|
+
places.agentOf(channel)?.name === agent.name);
|
|
327
327
|
const origin = entry.origin ?? entry.channel;
|
|
328
328
|
const intact =
|
|
329
329
|
entry.kind === "message"
|
|
@@ -191,21 +191,20 @@ export function chainLimitReason(who: OwnerIdentity): string {
|
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
193
|
* Where a turn's conversation is: the surface of the turn's conversation (`home`: the agent's own
|
|
194
|
-
* channel or room, or the group's in a group round), named by its `label`, and the other surfaces the agents have places on
|
|
195
|
-
*
|
|
194
|
+
* channel or room, or the group's in a group round), named by its `label`, and the other surfaces the agents have places on:
|
|
195
|
+
* `holders`, every surface with a place provider.
|
|
196
196
|
*/
|
|
197
197
|
export function placeOf(
|
|
198
198
|
home: ChannelKey,
|
|
199
|
-
surfaces: Pick<SurfacePort, "of"
|
|
200
|
-
|
|
199
|
+
surfaces: Pick<SurfacePort, "of"> | undefined,
|
|
200
|
+
holders: readonly string[],
|
|
201
201
|
): { surface: { label: string; key: string; others: readonly string[] } } {
|
|
202
202
|
const prefix = parseChannelKey(home).surface;
|
|
203
203
|
const label = (name: string) =>
|
|
204
204
|
surfaces?.of(`${name}:`)?.label ?? (name === "discord" ? "Discord" : name);
|
|
205
|
-
const names =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
].filter((n, i, all) => n !== prefix && all.indexOf(n) === i);
|
|
205
|
+
const names = holders.filter(
|
|
206
|
+
(n, i, all) => n !== prefix && all.indexOf(n) === i,
|
|
207
|
+
);
|
|
209
208
|
return {
|
|
210
209
|
surface: { label: label(prefix), key: prefix, others: names.map(label) },
|
|
211
210
|
};
|
|
@@ -23,7 +23,10 @@ export interface Agent {
|
|
|
23
23
|
character?: CharacterSpec;
|
|
24
24
|
/** The rendered picture's content hash, when one exists. */
|
|
25
25
|
avatarHash?: string;
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Its Discord channel only; read `AgentTeam.placesOf`, which names its place on every
|
|
28
|
+
* surface. Removed in 1.0. A seed agent has none until one is created.
|
|
29
|
+
*/
|
|
27
30
|
channelId?: string;
|
|
28
31
|
/** `<provider>/<id>`; unset follows the assistant's model. */
|
|
29
32
|
model?: string;
|
|
@@ -74,7 +77,10 @@ export const helperSurface = (
|
|
|
74
77
|
export interface AgentGroup {
|
|
75
78
|
name: string;
|
|
76
79
|
displayName: string;
|
|
77
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Its Discord channel only; read `AgentTeam.placesOf`, which names its place on
|
|
82
|
+
* every surface. Removed in 1.0. Absent in a team without Discord, whose groups live in rooms only.
|
|
83
|
+
*/
|
|
78
84
|
channelId?: string;
|
|
79
85
|
/** Agent names in the group's order. */
|
|
80
86
|
members: string[];
|
|
@@ -90,6 +96,7 @@ export interface AgentSeed {
|
|
|
90
96
|
character?: CharacterInput;
|
|
91
97
|
/** @deprecated Agents are composed characters; this is ignored and removed in 1.0. */
|
|
92
98
|
avatarPrompt?: string;
|
|
99
|
+
/** @deprecated The seed's Discord channel only; removed in 1.0. */
|
|
93
100
|
channelId?: string;
|
|
94
101
|
}
|
|
95
102
|
|
|
@@ -2,6 +2,7 @@ import type { SQL } from "bun";
|
|
|
2
2
|
import type { CharacterSpec } from "../../characters/index.ts";
|
|
3
3
|
import { isCheckDatabase } from "../db/check-database.ts";
|
|
4
4
|
import type { Migration } from "../db/migrations.ts";
|
|
5
|
+
import type { ChannelKey } from "../domain/conversation.ts";
|
|
5
6
|
import { AgentError } from "../domain/errors.ts";
|
|
6
7
|
import type { ThinkingLevel } from "../domain/models.ts";
|
|
7
8
|
import {
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
toGroup,
|
|
35
36
|
} from "./agent-schema.ts";
|
|
36
37
|
import { HelperPresets } from "./helper-presets.ts";
|
|
38
|
+
import type { TeamPlaces } from "./team-places.ts";
|
|
37
39
|
|
|
38
40
|
export {
|
|
39
41
|
type Agent,
|
|
@@ -66,6 +68,8 @@ export class PgAgentStore extends AgentGroupStore implements AgentDirectory {
|
|
|
66
68
|
readonly conversations: AgentConversations;
|
|
67
69
|
/** The temp-knight presets each agent saved. */
|
|
68
70
|
readonly presets: HelperPresets;
|
|
71
|
+
/** How the team reads a key as a place, once the agent server has linked; until then no key is anyone's. */
|
|
72
|
+
#reading: Pick<TeamPlaces, "ownerOf"> | undefined;
|
|
69
73
|
|
|
70
74
|
private constructor(
|
|
71
75
|
sql: SQL,
|
|
@@ -123,6 +127,18 @@ export class PgAgentStore extends AgentGroupStore implements AgentDirectory {
|
|
|
123
127
|
for (const row of groups) this.groupMap.set(row.name, toGroup(row));
|
|
124
128
|
}
|
|
125
129
|
|
|
130
|
+
/** Lets `placeOwner` read keys the way the team does: through the host's place providers. */
|
|
131
|
+
readPlacesWith(places: Pick<TeamPlaces, "ownerOf">): void {
|
|
132
|
+
this.#reading = places;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
placeOwner(
|
|
136
|
+
key: ChannelKey,
|
|
137
|
+
): { kind: "agent" | "group"; name: string } | undefined {
|
|
138
|
+
const owner = this.#reading?.ownerOf(key);
|
|
139
|
+
return owner && { kind: owner.kind, name: owner.name };
|
|
140
|
+
}
|
|
141
|
+
|
|
126
142
|
/** Inserts seed agents that do not exist yet; existing rows, edited or not, are left alone. */
|
|
127
143
|
async seed(seeds: readonly AgentSeed[]): Promise<string[]> {
|
|
128
144
|
return this.serial(async () => {
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentCategory,
|
|
3
|
+
AgentChannels,
|
|
4
|
+
AgentPost,
|
|
5
|
+
CategoryLayout,
|
|
6
|
+
ChannelMessage,
|
|
7
|
+
} from "./agent-ports.ts";
|
|
8
|
+
|
|
9
|
+
/** The Discord channels of a team, recorded: what was posted, made, moved and read. */
|
|
10
|
+
export class FakeChannels implements AgentChannels {
|
|
11
|
+
posts: { channelId: string; post: AgentPost }[] = [];
|
|
12
|
+
created: string[] = [];
|
|
13
|
+
deleted = new Set<string>();
|
|
14
|
+
#next = 2000;
|
|
15
|
+
async post(channelId: string, post: AgentPost) {
|
|
16
|
+
this.posts.push({ channelId, post });
|
|
17
|
+
}
|
|
18
|
+
/** The server's categories in order, each with its channels in order. */
|
|
19
|
+
categories: CategoryLayout[] = [];
|
|
20
|
+
#nextCategory = 9000;
|
|
21
|
+
arranged: { layout: CategoryLayout[]; remove: string[] }[] = [];
|
|
22
|
+
categoryOf(channelId: string) {
|
|
23
|
+
return this.categories.find((c) => c.channelIds.includes(channelId))?.name;
|
|
24
|
+
}
|
|
25
|
+
/** Moves a channel to the end of the category, made when missing. */
|
|
26
|
+
put(channelId: string, category: AgentCategory) {
|
|
27
|
+
for (const c of this.categories)
|
|
28
|
+
c.channelIds = c.channelIds.filter((id) => id !== channelId);
|
|
29
|
+
let found = this.categories.find((c) => c.name === category);
|
|
30
|
+
if (!found) {
|
|
31
|
+
found = {
|
|
32
|
+
id: String(this.#nextCategory++),
|
|
33
|
+
name: category,
|
|
34
|
+
channelIds: [],
|
|
35
|
+
};
|
|
36
|
+
this.categories.push(found);
|
|
37
|
+
}
|
|
38
|
+
found.channelIds.push(channelId);
|
|
39
|
+
}
|
|
40
|
+
async createChannel(name: string, topic: string, category: AgentCategory) {
|
|
41
|
+
this.created.push(name);
|
|
42
|
+
const id = String(this.#next++);
|
|
43
|
+
this.topics.set(id, topic);
|
|
44
|
+
this.put(id, category);
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
/** The threads made under a channel for temp knights, by id; `archived` once closed. */
|
|
48
|
+
threads = new Map<
|
|
49
|
+
string,
|
|
50
|
+
{ parent: string; name: string; archived: boolean }
|
|
51
|
+
>();
|
|
52
|
+
async createThread(parentChannelId: string, name: string) {
|
|
53
|
+
const id = String(this.#next++);
|
|
54
|
+
this.threads.set(id, { parent: parentChannelId, name, archived: false });
|
|
55
|
+
return id;
|
|
56
|
+
}
|
|
57
|
+
async closeThread(threadId: string) {
|
|
58
|
+
const thread = this.threads.get(threadId);
|
|
59
|
+
if (thread) thread.archived = true;
|
|
60
|
+
}
|
|
61
|
+
async openThread(threadId: string) {
|
|
62
|
+
const thread = this.threads.get(threadId);
|
|
63
|
+
if (thread) thread.archived = false;
|
|
64
|
+
}
|
|
65
|
+
async placeIn(channelId: string, category: AgentCategory) {
|
|
66
|
+
if (this.categoryOf(channelId) === category) return false;
|
|
67
|
+
this.put(channelId, category);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
async layout() {
|
|
71
|
+
return structuredClone(this.categories);
|
|
72
|
+
}
|
|
73
|
+
async arrange(layout: CategoryLayout[], remove: string[]) {
|
|
74
|
+
this.arranged.push({ layout: structuredClone(layout), remove });
|
|
75
|
+
this.categories = layout.map((c) => ({
|
|
76
|
+
id: c.id ?? String(this.#nextCategory++),
|
|
77
|
+
name: c.name,
|
|
78
|
+
channelIds: [...c.channelIds],
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
history: ChannelMessage[] = [];
|
|
82
|
+
reads: { channelId: string; limit: number; around?: string }[] = [];
|
|
83
|
+
async read(channelId: string, options: { limit: number; around?: string }) {
|
|
84
|
+
this.reads.push({ channelId, ...options });
|
|
85
|
+
return this.history;
|
|
86
|
+
}
|
|
87
|
+
topics = new Map<string, string>();
|
|
88
|
+
async setTopic(channelId: string, topic: string) {
|
|
89
|
+
this.topics.set(channelId, topic);
|
|
90
|
+
}
|
|
91
|
+
async exists(channelId: string) {
|
|
92
|
+
return !this.deleted.has(channelId);
|
|
93
|
+
}
|
|
94
|
+
webhooksRemoved: string[] = [];
|
|
95
|
+
async removeWebhook(channelId: string) {
|
|
96
|
+
this.webhooksRemoved.push(channelId);
|
|
97
|
+
}
|
|
98
|
+
texts(channelId: string) {
|
|
99
|
+
return this.posts.flatMap((p) =>
|
|
100
|
+
p.channelId === channelId
|
|
101
|
+
? [`${p.post.name}: ${p.post.chunks.join("")}`]
|
|
102
|
+
: [],
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|