tenant

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tenant derives the isolation unit a conversation belongs to.

A tenant is coarser than a session: one Slack channel is one tenant, but that channel may hold many sessions (one per thread, or one per user). The split matters because the two answer different questions:

  • SessionID decides which conversation history a turn appends to.
  • Tenant decides which working directory that turn runs in.

Keeping them separate is what lets a channel share one workdir across all its threads while each thread keeps its own history.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirName

func DirName(key string) string

DirName maps a tenant key to a single safe path segment. Keys carry ':' and platform-chosen characters; a tenant root must never be able to reach a sibling tenant, so anything outside [A-Za-z0-9._-] becomes '_' and a run of dots can not survive.

func FromContext

func FromContext(ctx context.Context) string

FromContext reports the tenant behind the current session, or "" when the context carries no session id. Anything that needs per-tenant state — a workspace root, a client pool slot — keys off this rather than re-deriving it.

func Key

func Key(sessionID string) string

Key derives the tenant key from an opaque SessionID by a fixed rule: the platform segment plus the first routing segment.

slack:C123ABC              -> slack:C123ABC
slack:C123ABC:U456         -> slack:C123ABC
slack:C123ABC:t:171234.56  -> slack:C123ABC
cli:default                -> cli:default
                           -> "" (no session, no tenant)

Every Slack session scope therefore lands on the same tenant for a given channel, which is why session granularity and workdir granularity can be chosen independently.

This is the only place the rule lives. Platforms stay free to encode whatever they like after the second segment; nothing here parses further.

func LocalDirName added in v0.1.6

func LocalDirName(key string, omitPlatform bool) string

LocalDirName maps a tenant key to a single safe path segment under localBase. When omitPlatform is true, only the first routing segment is used:

slack:C123              -> C123
chat-api:slack_D0AK...  -> slack_D0AK...

func RoutingSegment added in v0.1.6

func RoutingSegment(key string) string

RoutingSegment returns the first routing segment of a tenant key, dropping the platform prefix.

slack:C123ABC     -> C123ABC
chat-api:slack_x  -> slack_x
cli:default       -> default
bare-id           -> bare-id

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL