Documentation
¶
Overview ¶
import_memory_repository.go holds the SQL for what AI Import keeps per campaign: the parts of a split answer, waiting in the tray or applied (ai_import_parts), and a fingerprint of each block applied (ai_import_blocks), both plugin migrations. Every statement is scoped by campaign_id.
note_access_repository.go holds the SQL for the owner's switches on which shared notes the AI may change (ai_note_access, a plugin migration).
Index ¶
- Constants
- Variables
- func RegisterAdminRoutes(admin *echo.Group, h *AdminAIHandler, reauth echo.MiddlewareFunc)
- func RegisterOwnerRoutes(cg *echo.Group, h *Handler, requireOwner echo.MiddlewareFunc)
- func RegisterPlayerRoutes(cg *echo.Group, h *Handler, requireMember echo.MiddlewareFunc)
- type ActivityRecorder
- type AdminAIHandler
- func (h *AdminAIHandler) Key(c *echo.Context) error
- func (h *AdminAIHandler) Page(c *echo.Context) error
- func (h *AdminAIHandler) SetAccess(c *echo.Context) error
- func (h *AdminAIHandler) SetActivityRecorder(r ActivityRecorder)
- func (h *AdminAIHandler) SetZone(f func(*echo.Context) *time.Location)
- func (h *AdminAIHandler) Settle(c *echo.Context) error
- type AdminAIView
- type AuditLogger
- type ChipCounts
- type ConnectView
- type DeskProvider
- type Handler
- func (h *Handler) AIActivity(c *echo.Context) error
- func (h *Handler) AIBubble(c *echo.Context) error
- func (h *Handler) AIChip(c *echo.Context) error
- func (h *Handler) AIPage(c *echo.Context) error
- func (h *Handler) AIPanel(c *echo.Context) error
- func (h *Handler) AIRequests(c *echo.Context) error
- func (h *Handler) AnswerAIAlert(c *echo.Context) error
- func (h *Handler) ChangeAIAccess(c *echo.Context) error
- func (h *Handler) ChangeNoteAccess(c *echo.Context) error
- func (h *Handler) ClearImportTray(c *echo.Context) error
- func (h *Handler) CommitImport(c *echo.Context) error
- func (h *Handler) ConnectAI(c *echo.Context) error
- func (h *Handler) ConnectorCheck(ctx context.Context, conn *connector.Connection, changes string) ([]string, error)
- func (h *Handler) ConnectorCheckDid(ctx context.Context, conn *connector.Connection, changes string) ([]string, string, error)
- func (h *Handler) ConnectorInstructions(ctx context.Context, conn *connector.Connection, campaignName string) (string, error)
- func (h *Handler) ConnectorNotes(ctx context.Context, conn *connector.Connection, changes string) []string
- func (h *Handler) CopyForAI(c *echo.Context) error
- func (h *Handler) CutOffAI(c *echo.Context) error
- func (h *Handler) DisconnectAI(c *echo.Context) error
- func (h *Handler) GenerateAIExport(c *echo.Context) error
- func (h *Handler) GeneratePrompt(c *echo.Context) error
- func (h *Handler) ImportTrayList(c *echo.Context) error
- func (h *Handler) ParseImport(c *echo.Context) error
- func (h *Handler) PauseAI(c *echo.Context) error
- func (h *Handler) PlayerApply(c *echo.Context) error
- func (h *Handler) PlayerBubble(c *echo.Context) error
- func (h *Handler) PlayerChip(c *echo.Context) error
- func (h *Handler) PlayerConnect(c *echo.Context) error
- func (h *Handler) PlayerCopy(c *echo.Context) error
- func (h *Handler) PlayerDisconnect(c *echo.Context) error
- func (h *Handler) PlayerKeyAction(c *echo.Context) error
- func (h *Handler) PlayerPanel(c *echo.Context) error
- func (h *Handler) PlayerPaste(c *echo.Context) error
- func (h *Handler) PlayerReviewRequest(c *echo.Context) error
- func (h *Handler) PlayerTurnDown(c *echo.Context) error
- func (h *Handler) PromptInstructions(c *echo.Context) error
- func (h *Handler) ResumeAI(c *echo.Context) error
- func (h *Handler) SetAuditLogger(a AuditLogger)
- func (h *Handler) SetConnector(svc *connector.Service, baseURL string)
- func (h *Handler) SetFeatureGate(g func(ctx context.Context, campaignID string) records.OffFeatures)
- func (h *Handler) SetHeroPicks(c HeroPickChecker)
- func (h *Handler) SetImportCommitter(c *importer.Committer)
- func (h *Handler) SetImportEras(l importer.EraLookup)
- func (h *Handler) SetImportFolders(f importer.FolderAccess)
- func (h *Handler) SetImportLookup(l importer.CampaignLookup)
- func (h *Handler) SetImportMemory(m ImportMemory)
- func (h *Handler) SetLookups(l *records.Lookups)
- func (h *Handler) SetNoteAccess(s NoteAccessStore)
- func (h *Handler) SetPageUndo(p PageUndo)
- func (h *Handler) SetPlayerSheets(s PlayerSheets)
- func (h *Handler) SetPlayersAI(c *echo.Context) error
- func (h *Handler) SetPromptBuilder(b *prompt.Service)
- func (h *Handler) SetRecords(r *records.Registry)
- func (h *Handler) SetZone(f func(ctx context.Context, userID string) *time.Location)
- func (h *Handler) TurnDownRequest(c *echo.Context) error
- func (h *Handler) UndoRequest(c *echo.Context) error
- type HeroPickChecker
- type ImportMemory
- type NoteAccessStore
- type NotesView
- type PageUndo
- type PlayerAIView
- type PlayerBuy
- type PlayerChange
- type PlayerChangeLine
- type PlayerReview
- type PlayerSheet
- type PlayerSheets
- type PlayersView
- type StoredPart
Constants ¶
const MemorySchemaSlug = "ai_import_memory"
MemorySchemaSlug is the migrations slug for the plugin's own tables: what AI Import applied (answer parts, block fingerprints) and the owner's switches for shared notes. Kept apart from PluginHealthKey so a failed migration leaves only those out, never the whole AI tool.
const PluginHealthKey = "ai_workspace"
PluginHealthKey is the INTERNAL identifier the database.PluginHealthRegistry uses. Underscored to match the Go package directory name.
const PluginSlug = "ai-workspace"
PluginSlug is the canonical EXTERNAL identifier for the ai_workspace plugin in the App's PluginRegistration registry. Hyphen form matches the CSS sub-layer naming convention (`@layer plugins.ai-workspace`) + the URL prefix (`/ai-workspace/…`).
Variables ¶
var MigrationsFS embed.FS
MigrationsFS holds the plugin's own migrations (what AI Import applied in a campaign). Embedded so the binary carries them whatever its working directory.
Functions ¶
func RegisterAdminRoutes ¶
func RegisterAdminRoutes(admin *echo.Group, h *AdminAIHandler, reauth echo.MiddlewareFunc)
RegisterAdminRoutes mounts Site admin ▸ AI on the admin group (already sign-in and site-admin gated). Turning AI off, changing the players switch and ending a key also ask for the admin's password again.
func RegisterOwnerRoutes ¶
func RegisterOwnerRoutes(cg *echo.Group, h *Handler, requireOwner echo.MiddlewareFunc)
RegisterOwnerRoutes mounts the per-campaign routes the AI Workspace plugin owns. Caller passes the same /campaigns/:id group + RequireRole(RoleOwner) middleware used elsewhere. /ai-export/generate's URL is preserved byte-for-byte from its original campaigns-plugin registration so operator bookmarks + external monitoring keep working. Each route's owner-gate is AST-pinned in internal/wire/ (ai_export_route_test.go, ai_workspace_prompt_route_test.go, ai_workspace_import_parse_route_test.go, ai_workspace_import_commit_route_test.go, ai_workspace_import_tray_route_test.go, ai_page_route_test.go).
func RegisterPlayerRoutes ¶
func RegisterPlayerRoutes(cg *echo.Group, h *Handler, requireMember echo.MiddlewareFunc)
RegisterPlayerRoutes mounts a player's own AI: the AI button and panel on their screen, their key and their AI's changes. requireMember admits anyone in the campaign; each handler works on the signed-in person's own key and requests only, and on their own character only.
A guest is refused on every one of them: players' AI is for players with an account, and hiding the button alone wouldn't hold that rule.
Types ¶
type ActivityRecorder ¶
type ActivityRecorder interface {
RecordAdminChange(c *echo.Context, action, targetType, targetID, label string)
}
ActivityRecorder is the slice of the admin change log Site admin ▸ AI writes to. Declared here so this plugin never imports admin; app wiring supplies an adapter that stamps the signed-in admin. Best-effort.
type AdminAIHandler ¶
type AdminAIHandler struct {
// contains filtered or unexported fields
}
AdminAIHandler is Site admin ▸ AI: every AI key on the server, what looks wrong, and the server's switches.
func NewAdminAIHandler ¶
func NewAdminAIHandler(svc *connector.Service) *AdminAIHandler
NewAdminAIHandler creates Site admin ▸ AI over the connector's service.
func (*AdminAIHandler) Key ¶
func (h *AdminAIHandler) Key(c *echo.Context) error
Key pauses, resumes or ends one key.
func (*AdminAIHandler) Page ¶
func (h *AdminAIHandler) Page(c *echo.Context) error
Page renders Site admin ▸ AI.
func (*AdminAIHandler) SetAccess ¶
func (h *AdminAIHandler) SetAccess(c *echo.Context) error
SetAccess saves the server's switches: ai_off=1 stops every key, players=1 lets owners turn on players' AI.
func (*AdminAIHandler) SetActivityRecorder ¶
func (h *AdminAIHandler) SetActivityRecorder(r ActivityRecorder)
SetActivityRecorder wires the admin change log. Optional.
type AdminAIView ¶
type AdminAIView struct {
*connector.AdminView
Now time.Time
Loc *time.Location
// Only lists only the keys with an open warning.
Only bool
Note string
}
AdminAIView is what the page renders.
type AuditLogger ¶
type AuditLogger interface {
LogCampaignEvent(ctx context.Context, campaignID, userID, action string, details map[string]any)
}
AuditLogger is the narrow contract the plugin needs for audit events. Implemented by app/routes.go via a small adapter against the existing audit service (same shape as campaigns' campaignAudit adapter). Optional — nil disables audit emission, which is the default in test fixtures.
type ChipCounts ¶
type ChipCounts struct {
Waiting int `json:"waiting"`
Warnings int `json:"warnings"`
Stopped bool `json:"stopped"`
}
ChipCounts is what the top bar's AI button shows: requests waiting for the owner, open warnings about their keys, and whether AI is stopped here.
type ConnectView ¶
type ConnectView struct {
CampaignID string
// Available is false when the connector isn't wired (its tables did
// not migrate); the page then offers copy and paste only.
Available bool
Conn *connector.Connection
// NewKey is the key just made, shown this once and never again.
NewKey string
Endpoint string
Calls []connector.Call
// Requests are what the AI asked for, waiting for the owner.
Requests []connector.Request
// Alerts is the campaign's open warnings about its keys; CutOff is set
// while the owner has stopped every AI here. Watching is false when the
// watch isn't wired, and both stay empty.
Alerts []connector.Alert
CutOff *time.Time
Watching bool
// Sittings group Calls; Shown is how many the page lists.
Sittings []connector.Sitting
Shown int
Now time.Time
// Loc is the owner's time zone for the sittings' times (UTC when unset).
Loc *time.Location
// Notes is the notes panel; nil when the switches aren't wired.
Notes *NotesView
// Players is the players panel; nil when the watch isn't wired.
Players *PlayersView
// Applied are the owner's applied requests and Undo the Undo state of
// each that has any, by request id; both stay empty when Undo isn't wired.
Applied []connector.Request
Undo map[int64]undoCell
// LevelSaved is true on the answer to a change of level, which says
// Saved beside it.
LevelSaved bool
}
ConnectView is the connect section: no connection, a key just made (shown once), or the connection and what it did.
type DeskProvider ¶
type DeskProvider struct {
// contains filtered or unexported fields
}
DeskProvider fills the desk's Your AI line.
func NewDeskProvider ¶
func NewDeskProvider(svc *connector.Service) *DeskProvider
NewDeskProvider returns the desk provider for the owner's AI connection.
func (*DeskProvider) Facts ¶
func (p *DeskProvider) Facts(ctx context.Context, req campaigns.DeskRequest) (campaigns.DeskFacts, error)
Facts reads the connection the request's owner made. It asks for the owner's own connection only, never a player's key, so no other person's AI shows on the desk.
func (*DeskProvider) Slot ¶
func (p *DeskProvider) Slot() campaigns.DeskSlot
Slot is the one desk line this provider fills.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the HTTP boundary for the AI Workspace plugin. Holds references to the cross-cutting renderer + the audit logger the campaigns handler used pre-migration. Per Chronicle's thin- handler convention: parse request, call service, render response.
func NewHandler ¶
NewHandler constructs the Handler. A nil renderer produces a "service unavailable" modal at GenerateAIExport time rather than a panic.
func (*Handler) AIActivity ¶
AIActivity re-renders "What it did", which the page refreshes while open.
func (*Handler) AIBubble ¶
AIBubble is the small bubble the AI button drops: copy and paste in one thin row, then each waiting request with Review.
func (*Handler) AIChip ¶
AIChip answers the AI button on every campaign page. It is JSON, not a fragment, so the button can tell when the count goes up and drop a notice.
func (*Handler) AIPanel ¶
AIPanel is the side sheet a review opens in: the AI's waiting requests, answered in place, and the review of a pasted answer. With tool=1 it holds the whole copy-and-paste tool instead ("Write a request…").
func (*Handler) AIRequests ¶
AIRequests re-renders the waiting requests, which the page asks for while open. seen is what the page shows now (requestsSeen); when nothing changed the answer is 204, so htmx swaps nothing.
func (*Handler) AnswerAIAlert ¶
AnswerAIAlert answers one warning about the campaign's AI key: how=mine says the owner did it, how=paused also pauses the key.
func (*Handler) ChangeAIAccess ¶
ChangeAIAccess changes what the key may see and whether it may ask, from its next call. Letting it see what the owner sees needs widen=yes, which the page sends only after the owner confirms.
func (*Handler) ChangeNoteAccess ¶
ChangeNoteAccess saves the owner's switches for which shared notes the AI may change, from its next call or paste.
func (*Handler) ClearImportTray ¶
ClearImportTray takes one answer's waiting parts out of the tray. Nothing in the campaign changes; only the waiting text goes.
POST /campaigns/:id/ai-workspace/import/tray/clear
func (*Handler) CommitImport ¶
CommitImport runs the entity-creation pass after the operator reviews the parsed pages and submits the form. Per-row autonomy: one row's failure does not abort the rest. Owner-gated at the route level.
POST /campaigns/:id/ai-workspace/import/commit
Form fields: markdown_source, bulk_default_category, bulk_default_visibility (private|dm_only|public|"" for campaign default), bulk_default_conflict (rename|skip|overwrite), and per row page_N_include/name/category/visibility/conflict. An empty visibility (bulk or per-row) means no override was made, so new pages follow the campaign's configured DefaultVisibility (#729) rather than a hardcoded choice.
Returns the import_result fragment.
func (*Handler) ConnectAI ¶
ConnectAI makes a new connection key (revoking any earlier one) and shows it once. sees is "players" or "owner"; change is "ask" or "look".
func (*Handler) ConnectorCheck ¶
func (h *Handler) ConnectorCheck(ctx context.Context, conn *connector.Connection, changes string) ([]string, error)
ConnectorCheck is what a connected AI is told about the changes it asks for before they wait for the owner: new pages filed in a folder their category doesn't have, pages to update or delete that don't exist, sheet fields their category lacks, and every other block the review screen would mark as unusable, with the review's own reason. The AI can fix its own request, where the owner would otherwise find a broken row at review.
The other blocks are planned as the owner, as the review plans them, so a reason can name what the owner can see. That is only told to a key that already reads as the owner (any privacy but Safe); a Safe key, which reads as a player, gets the folder check alone, so a refusal never tells it a hidden page exists; the page checks look pages up by name, so they are left out too.
func (*Handler) ConnectorCheckDid ¶
func (h *Handler) ConnectorCheckDid(ctx context.Context, conn *connector.Connection, changes string) ([]string, string, error)
ConnectorCheckDid is ConnectorCheck plus the line "What it did" shows for a refusal. The line names a page only when a page problem was found, which is only looked for on a key that already reads as the owner; otherwise it is "" and the log keeps its generic wording.
func (*Handler) ConnectorInstructions ¶
func (h *Handler) ConnectorInstructions(ctx context.Context, conn *connector.Connection, campaignName string) (string, error)
ConnectorInstructions answers a connected AI's how_to_write_changes: for the owner's key, the same standing instructions "Copy AI instructions" gives; for a player's, how to change their own character.
func (*Handler) ConnectorNotes ¶
func (h *Handler) ConnectorNotes(ctx context.Context, conn *connector.Connection, changes string) []string
ConnectorNotes is what a connected AI is told about a request that was kept: a new page that closely matches a page the campaign already has, by the rule the review uses (importer.FindSimilar), with the way to change that page instead. It only advises, so the owner still gets the request.
The search runs as the key's own reader: the owner for any privacy but Safe, a player for Safe, the same split every lookup the AI can make uses. So a page the key's AI could not look up is never named, and only a page's name is told, never its text, so GM-only passages stay where they are. A player's key is left out: it only changes its own character.
func (*Handler) CopyForAI ¶
CopyForAI is the text the bubble's Copy button puts on the clipboard: the standing instructions and, when the owner is on a page, that page as a lookup reads it. privacy is the owner's remembered choice; a page it hides is left out, never named.
func (*Handler) CutOffAI ¶
CutOffAI stops every AI in the campaign (on=1) or lets it back (on=0). Keys keep working once it is back on; nothing they asked for is lost.
func (*Handler) DisconnectAI ¶
DisconnectAI revokes the campaign's connection key at once.
func (*Handler) GenerateAIExport ¶
GenerateAIExport renders the AI-export markdown for the campaign owner and returns the modal fragment that displays it with a Copy button. Owner-gated at the route level (RequireRole(RoleOwner)).
GET /campaigns/:id/ai-export/generate?privacy=safe&categories=...&gm_notes=on
URL is preserved byte-for-byte so operator bookmarks and external monitoring keep working.
func (*Handler) GeneratePrompt ¶
GeneratePrompt renders the "Copy AI Prompt" markdown for the campaign owner and returns the modal fragment with a Copy button. Owner-gated at the route level. Reuses the data-widget="ai-export" JS hook the Export modal uses.
GET /campaigns/:id/ai-workspace/prompt/generate
Query params: schema_types/schema_categories/schema_front_matter ("on"), content_mode ("none"|"all"|"house-rules"|category slugs), privacy ("safe"|"permitted"|"everything"), gm_notes ("on"), instruction (free text).
A builder error surfaces in the modal's error region, not a top-level apperror, so the operator sees an in-modal failure they can correct.
func (*Handler) ImportTrayList ¶
ImportTrayList renders the tray under the paste box.
GET /campaigns/:id/ai-workspace/import/tray
func (*Handler) ParseImport ¶
ParseImport accepts multipart-or-textarea markdown input, parses it into per-page ParsedPage structs, classifies each against live campaign state (conflict / new category / etc), and returns the review fragment that the operator inspects before committing. No entity is created here — Submit in the review screen invokes CommitImport separately.
POST /campaigns/:id/ai-workspace/import/parse
Form fields (multipart/form-data):
- markdown_paste: textarea contents (single page or multi-page)
- markdown_files: zero-or-more .md file uploads
Files and paste content are concatenated with `\n\n` separators before parsing — pasted text comes first, then each file in the order the operator selected them.
func (*Handler) PlayerApply ¶
PlayerApply applies the changes the player said yes to. The blocks are read again from the request or the paste, and each is checked again as it is written, so the form can only choose among what the player may do.
func (*Handler) PlayerBubble ¶
PlayerBubble is the small bubble a player's AI button drops: copy and paste in one thin row, then their AI's waiting requests.
func (*Handler) PlayerChip ¶
PlayerChip answers the AI button on a player's screen: how many of their AI's requests wait, or off when they can't use AI here, which hides it.
func (*Handler) PlayerConnect ¶
PlayerConnect makes the player's own key, revoking their earlier one, and shows it once. A player's key always reads as them and may ask for changes to their own character.
func (*Handler) PlayerCopy ¶
PlayerCopy is the text a player copies for an AI app they paste into: their characters, what each may change, and how to write a change.
func (*Handler) PlayerDisconnect ¶
PlayerDisconnect revokes the player's own key.
func (*Handler) PlayerKeyAction ¶
PlayerKeyAction pauses, resumes or disconnects one player's key.
func (*Handler) PlayerPanel ¶
PlayerPanel is the panel a player's AI button opens.
func (*Handler) PlayerPaste ¶
PlayerPaste reviews an answer the player pasted.
func (*Handler) PlayerReviewRequest ¶
PlayerReviewRequest reviews one of the player's waiting requests.
func (*Handler) PlayerTurnDown ¶
PlayerTurnDown answers one of the player's requests No as a whole.
func (*Handler) PromptInstructions ¶
PromptInstructions returns the standing half of the prompt as plain text, for the "Copy AI instructions" button: every block format, the lookups and the rules, plus the campaign's page types, but none of its content, so an operator can save it in their AI once and paste only short requests.
GET /campaigns/:id/ai-workspace/prompt/instructions (owner only)
func (*Handler) SetAuditLogger ¶
func (h *Handler) SetAuditLogger(a AuditLogger)
SetAuditLogger wires the audit hook. Optional — see AuditLogger docstring.
func (*Handler) SetConnector ¶
SetConnector wires the connector service and the site's public address, which the page shows as the connector's address.
func (*Handler) SetFeatureGate ¶
func (h *Handler) SetFeatureGate(g func(ctx context.Context, campaignID string) records.OffFeatures)
SetFeatureGate wires the switched-off feature check the prompt and the review use.
func (*Handler) SetHeroPicks ¶
func (h *Handler) SetHeroPicks(c HeroPickChecker)
SetHeroPicks wires the hero creator's check, so the review can warn when a hero page sets a pick-list field to a name the campaign's list lacks. Optional: nil skips the warning.
func (*Handler) SetImportCommitter ¶
SetImportCommitter wires the committer that creates entities (+ categories) from the operator's confirmed review-screen decisions. Optional — nil renders an explanatory failure result instead of crashing.
func (*Handler) SetImportEras ¶
SetImportEras wires the era lookup the review uses for `era:` blocks. The committer gets its writer separately (Committer.SetEraWriter).
func (*Handler) SetImportFolders ¶
func (h *Handler) SetImportFolders(f importer.FolderAccess)
SetImportFolders wires the folder lookup the review uses for `folder:` on pages. The committer gets its own through Committer.SetFolders.
func (*Handler) SetImportLookup ¶
func (h *Handler) SetImportLookup(l importer.CampaignLookup)
SetImportLookup wires the campaign lookup the import classifier uses to detect slug conflicts + unknown entity-type categories. Optional — nil produces a "service unavailable" review fragment at parse time.
func (*Handler) SetImportMemory ¶
func (h *Handler) SetImportMemory(m ImportMemory)
SetImportMemory wires what AI Import keeps per campaign. Optional.
func (*Handler) SetLookups ¶
SetLookups wires the read-only lookups.
func (*Handler) SetNoteAccess ¶
func (h *Handler) SetNoteAccess(s NoteAccessStore)
SetNoteAccess wires the store of the owner's switches for shared notes. Optional: unwired, the page leaves the notes panel out.
func (*Handler) SetPageUndo ¶
SetPageUndo wires Undo for pages. Optional.
func (*Handler) SetPlayerSheets ¶
func (h *Handler) SetPlayerSheets(s PlayerSheets)
SetPlayerSheets wires the door for players' AI changes. Unwired, a player's AI can look things up but every change is held back.
func (*Handler) SetPlayersAI ¶
SetPlayersAI turns players' AI on or off in the campaign.
func (*Handler) SetPromptBuilder ¶
SetPromptBuilder wires the prompt service. Optional in test fixtures — nil produces a "service unavailable" modal at GeneratePrompt time rather than a panic.
func (*Handler) SetRecords ¶
SetRecords wires the record kinds.
func (*Handler) SetZone ¶
SetZone wires the owner's time zone, for the times of what their AI did. Optional: unwired, times are UTC.
func (*Handler) TurnDownRequest ¶
TurnDownRequest answers a waiting request No as a whole: nothing applies.
func (*Handler) UndoRequest ¶
UndoRequest puts back what an applied request changed.
POST /campaigns/:id/ai/requests/:rid/undo
The request is read through the owner's own key, so it can only be one of their own, and the answer is only the row's status: never the kept text.
type HeroPickChecker ¶
type HeroPickChecker interface {
HeroPickWarnings(ctx context.Context, campaignID, userID string, director bool, fields map[string]any, written []string) []string
}
HeroPickChecker is the hero creator's check of a hero's pick-list values, implemented by the composition root so this plugin never reads the entities plugin's creator or the game system's lists. director says whether the viewer may see entries kept from players.
type ImportMemory ¶
type ImportMemory interface {
// Parts lists every stored part of one answer.
Parts(ctx context.Context, campaignID, answerKey string) ([]StoredPart, error)
// Tray lists the parts waiting in the tray, of every answer.
Tray(ctx context.Context, campaignID string) ([]StoredPart, error)
// PutInTray stores a part to wait for the rest of its answer.
PutInTray(ctx context.Context, campaignID string, p StoredPart) error
// MarkApplied records a part as applied and takes it out of the tray.
MarkApplied(ctx context.Context, campaignID string, p StoredPart) error
// ClearTray takes an answer's waiting parts out of the tray.
ClearTray(ctx context.Context, campaignID, answerKey string) error
// Seen returns, for each fingerprint already applied, when it was.
Seen(ctx context.Context, campaignID string, hashes []string) (map[string]time.Time, error)
// Remember records fingerprints as applied now.
Remember(ctx context.Context, campaignID string, hashes []string) error
}
ImportMemory is what AI Import keeps per campaign.
func NewImportMemoryRepository ¶
func NewImportMemoryRepository(db *sql.DB) ImportMemory
NewImportMemoryRepository creates the import memory repository.
type NoteAccessStore ¶
type NoteAccessStore interface {
// Get is the campaign's switches; both off when never set.
Get(ctx context.Context, campaignID string) (records.NoteAccess, error)
// Set saves them, recording who changed them.
Set(ctx context.Context, campaignID, userID string, a records.NoteAccess) error
}
NoteAccessStore keeps the owner's switches per campaign.
func NewNoteAccessRepository ¶
func NewNoteAccessRepository(db *sql.DB) NoteAccessStore
NewNoteAccessRepository creates the note access store.
type NotesView ¶
type NotesView struct {
CampaignID string
Access records.NoteAccess
// PlayerNotes is false while the campaign has Player Notes switched off;
// the panel then leaves their row out.
PlayerNotes bool
// Shut is true while the connected AI sees what players see, when it
// reads no notes at all.
Shut bool
Saved bool
}
NotesView is the panel saying which notes the AI reads and changes, with the owner's switches for notes co-DMs and Scribes shared.
type PageUndo ¶
type PageUndo interface {
// Read is the live page, or nil when it is gone or in the Trash.
Read(ctx context.Context, campaignID, id string) (*entities.Entity, error)
RestoreText(ctx context.Context, id, name string, entry, entryHTML *string) error
// Inside is how many pages sit under a page, any visibility.
Inside(ctx context.Context, campaignID, id string) (int, error)
// Trash removes a page the way a delete does: to the Trash, not for good.
Trash(ctx context.Context, id string) error
RestoreFromTrash(ctx context.Context, campaignID, id string) error
}
PageUndo is how Undo reaches pages: read one as it is now, put a title and text back through the page history's restore, and move pages to and from the Trash. It is the entities service's, so a put-back is versioned and broadcast like any other save. Nil leaves pages without Undo.
type PlayerAIView ¶
type PlayerAIView struct {
CampaignID string
// Why says why the player can't use AI here now; "" when they can.
Why string
Conn *connector.Connection
// NewKey is the key just made, shown this once and never again.
NewKey string
Endpoint string
Requests []connector.Request
// Menu opens the connect menu, as it is after making a key.
Menu bool
// Done is the line after Apply saying what changed.
Done string
Now time.Time
// AboveP marks a co-DM or Scribe: their key still reads as a player, so
// the panel must not say it reads what they can.
AboveP bool
}
PlayerAIView is a player's AI panel.
type PlayerChange ¶
type PlayerChange struct {
// Block is the block's place in the request, from 1.
Block int
Page string
// SheetID is the character it changes; "" when held back.
SheetID string
Fields map[string]any
Lines []PlayerChangeLine
// Reason is the AI's own one line about the change (untrusted, shown
// in quotes).
Reason string
// Held says why the block can't be applied; "" when it can.
Held string
}
PlayerChange is one block of a player's request, and what happens to it.
type PlayerChangeLine ¶
type PlayerChangeLine struct {
Key, From, To string
}
PlayerChangeLine is one field a change sets, from its current value.
type PlayerReview ¶
type PlayerReview struct {
CampaignID string
// RequestID is the request under review; 0 for a paste, whose text
// travels with the form instead.
RequestID int64
Text string
Changes []PlayerChange
}
PlayerReview is what a player's request or paste would change.
func (PlayerReview) Kept ¶
func (r PlayerReview) Kept() []PlayerChange
Kept is the changes that can be applied.
func (PlayerReview) LeftOut ¶
func (r PlayerReview) LeftOut() []PlayerChange
LeftOut is the changes held back, with why.
type PlayerSheet ¶
type PlayerSheet struct {
ID string
Name string
// Type is the page's category, for the prompt.
Type string
// Values is the sheet's current value for each key the player may
// change, as text ("" for empty).
Values map[string]string
// Free lists the keys that take short free text (the identity fields).
Free []string
// Picks maps each hero builder step's key to the names it offers; the
// value must be one of them, unless Own says the player may also write
// their own.
Picks map[string][]string
Own map[string]bool
// Ask maps a step's key to the entries the player may pick only with
// their Director's yes. The AI can't ask for them, so the brief says to
// leave them to the player, and the server refuses a write of one.
Ask map[string][]string
// Required marks a step whose list is a short list the Director set: it
// can't be emptied. Fixed holds the one entry such a step is filled in
// with, which can't be changed either.
Required map[string]bool
Fixed map[string]string
// Story lists the keys that take the player's long text (a backstory).
Story []string
// Lists lists the keys that take a JSON list of short names (skills,
// languages, perks).
Lists []string
// Buys maps a key keeping what the hero bought from an entry
// (ancestry_choices_json) to what that entry offers.
Buys map[string]PlayerBuy
// Shown is the rest of the sheet as the player sees it, key to value,
// for the AI to recommend from; none of it can be changed.
Shown map[string]string
}
PlayerSheet is one character a player claimed, as their AI sees it. Every key listed is a field of the character's category that the player may change, each listed once, with the rule the server applies to it.
type PlayerSheets ¶
type PlayerSheets interface {
// Sheets lists the characters userID claimed in the campaign and can
// still open.
Sheets(ctx context.Context, campaignID, userID string) ([]PlayerSheet, error)
// HeldFields judges each key of patch against what userID may change on
// their own character entityID and returns, for each key they may not,
// why, in the player's terms. err is for a change they may not make at
// all (not their character, one they can't open).
HeldFields(ctx context.Context, campaignID, userID, entityID string, patch map[string]any) (map[string]string, error)
// PatchSheet checks patch against what userID may change on their own
// character entityID, and writes it when apply is true. label names
// the AI app, for the page's history. The error says, in the player's
// terms, why a change isn't allowed.
PatchSheet(ctx context.Context, campaignID, userID, entityID string, patch map[string]any, label string, apply bool) error
// GMTerm is what the campaign calls its game master.
GMTerm(ctx context.Context, campaignID string) string
}
PlayerSheets is the door a player's AI changes go through. internal/app implements it over the entities plugin and the hero builder.
type PlayersView ¶
type PlayersView struct {
CampaignID string
// Blocked is true while the site admin doesn't let players use AI; the
// switch is then not offered.
Blocked bool
Allowed bool
Keys []connector.KeyRow
}
PlayersView is the players panel on the owner's Your AI page.
type StoredPart ¶
type StoredPart struct {
AnswerKey string
AnswerName string
Number int
Of int
Needs []int
// Markdown is the part as pasted, label first; "" when not in the tray.
Markdown string
Applied bool
AddedBy string
AddedAt time.Time
}
StoredPart is one labelled part of an answer: waiting in the tray (its Markdown set), applied, or both when an applied part was pasted again.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package aiexport renders a campaign's owner-scoped content into a single markdown document for pasting into AI tools.
|
Package aiexport renders a campaign's owner-scoped content into a single markdown document for pasting into AI tools. |
|
Package connector lets an AI app (Claude, ChatGPT, Open WebUI, LM Studio) connect straight to one campaign over the Model Context Protocol, look things up and ask for changes, with nothing to copy and paste.
|
Package connector lets an AI app (Claude, ChatGPT, Open WebUI, LM Studio) connect straight to one campaign over the Model Context Protocol, look things up and ask for changes, with nothing to copy and paste. |
|
Package importer parses AI-generated markdown into per-page ParsedPage structs, classifies each (full / defaults / conflict / new category / parse error), and prepares the review-screen data the operator inspects before committing.
|
Package importer parses AI-generated markdown into per-page ParsedPage structs, classifies each (full / defaults / conflict / new category / parse error), and prepares the review-screen data the operator inspects before committing. |
|
htmlconv
Package htmlconv converts sanitized HTML to a Chronicle-shaped ProseMirror JSON document.
|
Package htmlconv converts sanitized HTML to a Chronicle-shaped ProseMirror JSON document. |
|
Package prompt builds the "Copy AI Prompt" output for the AI Workspace settings tab.
|
Package prompt builds the "Copy AI Prompt" output for the AI Workspace settings tab. |
|
Package records lets AI Import reach the campaign features that are not pages: calendar events, day weather, rolling tables, shop stock, carried items, map pins, house rules, the operator's own notes, and Chronicle's generators.
|
Package records lets AI Import reach the campaign features that are not pages: calendar events, day weather, rolling tables, shop stock, carried items, map pins, house rules, the operator's own notes, and Chronicle's generators. |