briyah 1.4.0 → 1.4.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/README.md +160 -0
- package/docs/classes/Agent.html +20 -20
- package/docs/classes/Briyah.html +14 -14
- package/docs/classes/BriyahConfigService.html +5 -5
- package/docs/classes/NativeToolRegistry.html +6 -6
- package/docs/classes/Room.html +35 -35
- package/docs/classes/RoomMessage.html +11 -11
- package/docs/enums/MessageAction.html +3 -3
- package/docs/functions/availableToolPacks.html +2 -2
- package/docs/functions/dnd5eTools.html +2 -2
- package/docs/functions/enabledToolPacks.html +2 -2
- package/docs/functions/registerToolPacks.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +68 -2
- package/docs/interfaces/AgentInfo.html +3 -3
- package/docs/interfaces/AgentMessagesResponse.html +2 -2
- package/docs/interfaces/AppService.html +122 -122
- package/docs/interfaces/Artifact.html +4 -4
- package/docs/interfaces/ArtifactMetadata.html +3 -3
- package/docs/interfaces/ArtifactWriteOptions.html +5 -5
- package/docs/interfaces/AttachDocumentResponse.html +2 -2
- package/docs/interfaces/BriyahConfigOptions.html +9 -9
- package/docs/interfaces/ChapterInfo.html +2 -2
- package/docs/interfaces/Character.html +2 -2
- package/docs/interfaces/CreateAgentResponse.html +2 -2
- package/docs/interfaces/CreateRoomResponse.html +2 -2
- package/docs/interfaces/CreateStoryResponse.html +2 -2
- package/docs/interfaces/FileList.html +2 -2
- package/docs/interfaces/FileMetadata.html +3 -3
- package/docs/interfaces/IConfigService.html +3 -3
- package/docs/interfaces/LoggingOptions.html +6 -6
- package/docs/interfaces/Message.html +2 -2
- package/docs/interfaces/ModelInfo.html +2 -2
- package/docs/interfaces/NativeToolDefinition.html +8 -8
- package/docs/interfaces/PreparedPromptResponse.html +2 -2
- package/docs/interfaces/ProcessTextResponse.html +2 -2
- package/docs/interfaces/PromptFile.html +2 -2
- package/docs/interfaces/PromptFileContent.html +2 -2
- package/docs/interfaces/PromptFilesResponse.html +2 -2
- package/docs/interfaces/PromptFolder.html +2 -2
- package/docs/interfaces/PromptFoldersResponse.html +2 -2
- package/docs/interfaces/RoomDetails.html +4 -4
- package/docs/interfaces/RoomInfo.html +2 -2
- package/docs/interfaces/RoomMessageUpdate.html +2 -2
- package/docs/interfaces/RoomMessagesResponse.html +2 -2
- package/docs/interfaces/SendMessageResult.html +2 -2
- package/docs/interfaces/StoryErrorEvent.html +3 -3
- package/docs/interfaces/StoryIdea.html +2 -2
- package/docs/interfaces/StoryInfo.html +3 -3
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +3 -3
- package/docs/interfaces/StoryProgressChapterEvent.html +3 -3
- package/docs/interfaces/StoryState.html +5 -5
- package/docs/interfaces/StoryStateEvent.html +3 -3
- package/docs/interfaces/ToolArtifact.html +4 -4
- package/docs/interfaces/ToolCaller.html +5 -5
- package/docs/interfaces/ToolDefinition.html +2 -2
- package/docs/interfaces/ToolHelpers.html +4 -4
- package/docs/interfaces/ToolParameter.html +2 -2
- package/docs/interfaces/ToolRoomAccess.html +9 -9
- package/docs/interfaces/ToolSummary.html +2 -2
- package/docs/interfaces/ToolsResponse.html +2 -2
- package/docs/interfaces/Transaction.html +2 -2
- package/docs/interfaces/TransactionHistoryResponse.html +2 -2
- package/docs/modules.html +1 -1
- package/docs/types/PromptScope.html +1 -1
- package/docs/types/ToolContext.html +2 -2
- package/docs/types/ToolRunResult.html +1 -1
- package/package.json +3 -2
- package/src/tools/packs/dnd5e/README.md +614 -0
package/README.md
CHANGED
|
@@ -285,6 +285,87 @@ await appService.deleteAttachedFile(agentId, fileName); // by filename
|
|
|
285
285
|
await appService.deleteAttachedFileById(documentId); // by document ID
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
+
## Prompt Folders
|
|
289
|
+
|
|
290
|
+
An agent's behaviour comes from a **prompt folder**, not from its description. The folder
|
|
291
|
+
holds the templates the room renders on every turn — most importantly `perceive.prompt`, which
|
|
292
|
+
tells the agent what it is and what it may do, and `perceive.json`, the JSON schema its replies
|
|
293
|
+
must satisfy. Two agents on the same model with the same description behave completely
|
|
294
|
+
differently if they were built from different folders.
|
|
295
|
+
|
|
296
|
+
`init()` seeds the bundled folders into `{dataPath}/common/prompts/`, so they are on disk before
|
|
297
|
+
your first `createAgent` call. Existing files are preserved on upgrade, so anything you edit
|
|
298
|
+
survives.
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
const appService = briyah.getAppService('user-123');
|
|
302
|
+
console.log(appService.listPromptFolders());
|
|
303
|
+
// default, dungeon_master, dnd_player, character_creator, campaign_designer,
|
|
304
|
+
// dnd_room_moderator, narrator, character, illustrator, ...
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**The folder is the sixth argument to `createAgent`, and it defaults to `'default'`** — a
|
|
308
|
+
generic conversational agent. Passing a role folder is what makes the agent that role:
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const dm = appService.createAgent(
|
|
312
|
+
'Anthropic',
|
|
313
|
+
'Dungeon Master', // agentName — a label; used in logs and the UI
|
|
314
|
+
'DM', // agentNickname — the name the room routes by
|
|
315
|
+
'Runs the game.',
|
|
316
|
+
'claude-sonnet-5',
|
|
317
|
+
'dungeon_master', // <- the prompt folder
|
|
318
|
+
);
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
`agentNickname` is the identity: messages are addressed to it, artifact viewers are lists of
|
|
322
|
+
it, and it is what an agent writes into `targets`. `agentName` is a label. Give a character the
|
|
323
|
+
nickname you want it called by.
|
|
324
|
+
|
|
325
|
+
To write your own folder, copy a bundled one out of `{dataPath}/common/prompts/`, rename the
|
|
326
|
+
directory, and edit it — a folder in the user data directory takes precedence over the common
|
|
327
|
+
one of the same name.
|
|
328
|
+
|
|
329
|
+
## Tool Packs
|
|
330
|
+
|
|
331
|
+
A tool pack is a set of native tools that ships with Briyah and registers only when asked for.
|
|
332
|
+
`dnd5e` is the one that exists: seventeen tools for dice, character sheets, the rules engine and
|
|
333
|
+
a bestiary. Turn it on either way:
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// By name — the SDK registers the pack during construction
|
|
337
|
+
const briyah = new Briyah({ envOverrides: { BRIYAH_TOOL_PACKS: 'dnd5e' } });
|
|
338
|
+
|
|
339
|
+
// Or pass the definitions yourself, which also lets you filter or wrap them
|
|
340
|
+
import { dnd5eTools, availableToolPacks } from 'briyah';
|
|
341
|
+
const briyah = new Briyah({ tools: dnd5eTools() });
|
|
342
|
+
console.log(availableToolPacks()); // ['dnd5e']
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Registering makes the tools *grantable*, not granted. An agent may only run the ones named in
|
|
346
|
+
its `toolNames`:
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
const dm = appService.createAgent(
|
|
350
|
+
'Anthropic', 'Dungeon Master', 'DM', 'Runs the game.', 'claude-sonnet-5', 'dungeon_master',
|
|
351
|
+
undefined, null, 0, '',
|
|
352
|
+
{ toolNames: ['roll_dice', 'check', 'apply_hp', 'stat_block', 'read_sheet'] },
|
|
353
|
+
);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Packs also ship read-only **documents** — rules text an agent carries in every call. They seed
|
|
357
|
+
into `{dataPath}/common/artifacts/`, appear in `listUserArtifacts()` alongside your own, and
|
|
358
|
+
attach by id:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
await appService.attachArtifactToAgent(dm.id, 'pack:dnd5e.dungeon_master-procedure');
|
|
362
|
+
await appService.attachArtifactToAgent(player.id, 'pack:dnd5e.class-bard');
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
A document sits in that agent's cached prompt prefix on every call, so attach what it needs and
|
|
366
|
+
nothing more. `src/tools/packs/dnd5e/README.md` in this package lists all seventeen tools and
|
|
367
|
+
which agent each document belongs to.
|
|
368
|
+
|
|
288
369
|
## Usage Examples
|
|
289
370
|
|
|
290
371
|
### Example 1: Multi-User Setup
|
|
@@ -629,6 +710,85 @@ Notes:
|
|
|
629
710
|
|
|
630
711
|
**Custom workflows.** Any ComfyUI workflow can be used: build it in the ComfyUI web UI, run it once, then use Export (API format) and replace the values you want parameterized with tokens — `{{prompt}}` (may be embedded in a longer string), `{{seed}}`, `{{width}}`, `{{height}}` (replaced as numbers), and `{{ref_image}}` (edit workflows, the `LoadImage` input). Save the files as `{name}.t2i.json` (used by `generateImage`) and `{name}.edit.json` (used by `editImage`) in `{dataPath}/common/config/comfyui-workflows/`, or in `{dataPath}/user/{userId}/comfyui-workflows/` for a per-user override (checked first). The pair name becomes the model name. For multi-reference support, an edit workflow must contain exactly one `ReferenceLatent` node fed by a `VAEEncode` fed by a `LoadImage`; extra references are added at request time by cloning that chain.
|
|
631
712
|
|
|
713
|
+
### Example 10: A turn-based table with a human player
|
|
714
|
+
|
|
715
|
+
Example 5 sends one message and reads the transcript back, which suits a batch job. A game or
|
|
716
|
+
any human-in-the-loop app needs the other shape: the agents take several turns among themselves,
|
|
717
|
+
then stop and wait for the person. Three things make that work.
|
|
718
|
+
|
|
719
|
+
**`turnMode: 'directed'`** — only the agent a message names is asked to reply, and the room
|
|
720
|
+
leader answers anything it cannot place. The default, `'broadcast'`, prompts *every* agent for
|
|
721
|
+
*every* message and keeps one reply, which costs several times as much and is wrong for a table
|
|
722
|
+
where one person speaks at a time.
|
|
723
|
+
|
|
724
|
+
**A human-controlled agent** — `createAgent`'s seventh argument. The room delivers messages to
|
|
725
|
+
it and then stops rather than generating a reply, which is what yields the floor to your console.
|
|
726
|
+
|
|
727
|
+
**The room message emitter** — the only way to see the conversation as it happens. It fires on
|
|
728
|
+
every change with the newest message and the room's state.
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
import { Briyah, dnd5eTools } from 'briyah';
|
|
732
|
+
import * as readline from 'node:readline/promises';
|
|
733
|
+
|
|
734
|
+
const briyah = new Briyah({ dataPath: './briyah-data', tools: dnd5eTools() });
|
|
735
|
+
await briyah.init(); // seeds prompt folders and pack documents
|
|
736
|
+
const app = briyah.getAppService('user-123');
|
|
737
|
+
|
|
738
|
+
const dm = app.createAgent(
|
|
739
|
+
'Anthropic', 'Dungeon Master', 'DM', 'Runs the game.', 'claude-sonnet-5',
|
|
740
|
+
'dungeon_master', undefined, null, 0, '',
|
|
741
|
+
{ toolNames: ['roll_dice', 'check', 'apply_hp', 'stat_block', 'read_sheet'] },
|
|
742
|
+
);
|
|
743
|
+
const rogue = app.createAgent(
|
|
744
|
+
'Anthropic', 'Vex', 'Vex', 'A wary scout.', 'claude-haiku-4-5', 'dnd_player',
|
|
745
|
+
);
|
|
746
|
+
// The seventh argument is what makes this one wait for a person.
|
|
747
|
+
const you = app.createAgent(
|
|
748
|
+
'Anthropic', 'Homer', 'Homer', 'A hopeful bard.', 'claude-haiku-4-5', 'dnd_player',
|
|
749
|
+
true,
|
|
750
|
+
);
|
|
751
|
+
|
|
752
|
+
// createAgent builds the agent in memory; save() writes it to disk. Without this the
|
|
753
|
+
// table exists for this process only and is gone on restart.
|
|
754
|
+
[dm, rogue, you].forEach((agent) => agent.save());
|
|
755
|
+
|
|
756
|
+
await app.attachArtifactToAgent(dm.id!, 'pack:dnd5e.dungeon_master-procedure');
|
|
757
|
+
await app.attachArtifactToAgent(rogue.id!, 'pack:dnd5e.class-rogue');
|
|
758
|
+
await app.attachArtifactToAgent(you.id!, 'pack:dnd5e.class-bard');
|
|
759
|
+
|
|
760
|
+
const { roomId } = await app.createRoom(
|
|
761
|
+
'The Sunken Barrow',
|
|
762
|
+
'A three-room dungeon crawl.',
|
|
763
|
+
[dm.id!, rogue.id!, you.id!],
|
|
764
|
+
'DM', // roomLeader — answers anything the room cannot place
|
|
765
|
+
'directed', // turnMode
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
// Watch the conversation. `waitingForHuman` is the cue to prompt your player.
|
|
769
|
+
const io = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
770
|
+
app.getRoomMessageEmitter(roomId).on('update', async (state) => {
|
|
771
|
+
if (state.latestMessage && state.latestMessage.sender !== 'Homer') {
|
|
772
|
+
console.log(`${state.latestMessage.sender}: ${state.latestMessage.content}`);
|
|
773
|
+
}
|
|
774
|
+
if (state.waitingForHuman && !state.processingInProgress) {
|
|
775
|
+
const line = await io.question('> ');
|
|
776
|
+
await app.sendRoomMessage(roomId, line, 'Homer', 'speak', ['DM']);
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
await app.sendRoomMessage(roomId, 'Begin the adventure.', 'Homer', 'speak', ['DM']);
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
The emitter payload carries `latestMessage`, `messageIndex`, `totalCost`, `isPaused`,
|
|
784
|
+
`currentSpeaker`, `processingInProgress` and `waitingForHuman`. `messageIndex` counts messages
|
|
785
|
+
with thoughts and tool notices excluded, so compare it against a list you fetched the same way —
|
|
786
|
+
`getRoomMessages(roomId)` — or simply refetch when they disagree.
|
|
787
|
+
|
|
788
|
+
Two notes for a long-running process. Call `await briyah.shutdown()` before exiting or the
|
|
789
|
+
process will hang on open handles. And a room with no human-controlled agent never stops on its
|
|
790
|
+
own: the agents talk until the leader adjourns.
|
|
791
|
+
|
|
632
792
|
## Data Storage
|
|
633
793
|
|
|
634
794
|
Briyah stores data in the following structure:
|