This reference is generated by reading the code, not an earlier specification.
The platform is pre-1.0: contracts here are what an extension may depend on,
and they may still gain members before 1.0.
fapost/foundation is the public surface. Everything here is what an extension may
depend on; nothing under App\… is. See
Stability policy.
Extension registration
Console
Experimental since 0.15; see Console UI.Flow engine
DTOs:
NodeExecutionContext, NodeExecutionResult, NodeExecutionStatus,
ExpressionContext, ResolvedTrigger, TriggerContext, CallContext,
CallRequest, CallResult. Enums: KeyboardMode, HistoryEventType.
Credentials
Experimental. A read-only view of the tenant’s saved credentials, for a call transport that authorizes requests with them. Core owns writing them.Flow\Call\CallRequest::$credential carries the credential the call node chose, already resolved,
and is null when there is none. A transport that supports credentials applies it, and keeps its values out of
the parameters, the options and the result. A request that holds
a credential cannot be serialized.
One-time codes
Experimental, since foundation 0.45. How the one-time codes of theauth_request node reach a contact.
Core generates the code, keeps only its keyed hash, counts the attempts, limits the sends and calls the
sender from an encrypted queued job inside the tenant.
Channels and ingress
DTOs:
InboundWebhookPayload, IncomingMessage, IncomingMessageType,
IncomingMedia.
Messaging
DTOs:
OutboundMessage, MessagePayload, DeliveryResult, OutgoingMessage,
OutgoingMessageType, SendResult.
Media
DTOs:
UploadContext, UploadResult, DownloadResult. Enum: MediaKind.
Tenancy
provision(ProvisionTenant): ProvisionedTenant creates the tenant record, its database schema,
runs the migrations and creates the first admin.
ProvisionTenantcarriesslug,adminEmail,adminNameandadminPasswordHash. The hash is made by the caller with the application’s hasher (Hash::make), never a plain password, so the request can wait in a queued job or a pending row. An emptyadminNamebecomesAdministrator.ProvisionedTenantreturnsid(the tenant ULID),slugandloginUrl(the admin panel login on the tenant’s own host).- Failures are
Exceptions\TenantProvisioningFailedExceptionwith areason(Enums\ProvisioningFailure):SlugInvalid,SlugReserved,SlugTaken,AdminCredentialsMissing,AdminPasswordHashInvalidandFailed; the reservation contract below addsTenantNotFound,TenantNotPending,ConflictandInProgress.isInputError()is true for every reason exceptFailed,ConflictandInProgress, andisRetryable()is true forFailedandInProgressonly. The top-level message never contains credentials; messages in thepreviouschain come from Core and are not redacted.
Failed the slug is held by a
Pending tenant, whose id is on the exception (tenantId), so a retry of this method gets
SlugTaken. To continue, call TenantReservationInterface::provision() with that id.
Tenancy\Contracts\TenantReservationInterface splits creation in two. A tenant is first
reserved: a Pending tenant holds the slug and has no schema, takes no traffic and shows in the
directory with status Pending. It is completed later, by id.
check(string $slug): SlugCheckwrites nothing and is advisory; onlyreserve()decides.SlugCheckcarriesavailability(Enums\SlugAvailability:Available,Invalid,Reserved,Taken) and, forInvalidonly,problem(Enums\SlugProblem:Malformed,TooLong,PunycodePrefix,ConsecutiveHyphens). The problem is a code: the text a person reads is the caller’s, in the caller’s language. A slug held by any tenant,Pendingones included, or given up by a renamed tenant (see below), isTaken.reserve(string $slug, string $reservationKey): ReservedTenantcreates thePendingtenant and returns itsidandslug. The key is a stable string of 1 to 64 characters that the caller stores before calling, such as the id of its own sign-up record. Reserving again with the same key returns the same tenant in any status, so a caller that crashed after the call can find its tenant. A key stays bound to its slug: the same key with another slug throwsInvalidArgumentException, as does an empty or over-long key. A refusal is aTenantProvisioningFailedExceptionwithSlugInvalid,SlugReservedorSlugTaken; a slug whose schema name is already used by a schema without a tenant isSlugTaken.release(string $tenantId): voiddeletes aPendingtenant that never started provisioning. An unknown id does nothing. A tenant that is notPending, has claimed its schema or is being provisioned right now throwsTenantReleaseRefusedExceptionand is left as it is; a tenant that has claimed a schema is removed only by an operator.provision(string $tenantId, TenantAdmin $admin): ProvisionedTenantcompletes aPendingtenant.TenantAdmincarriesemail,nameandpasswordHashunder the same rules asProvisionTenant. Repeating the call is safe: after a failure or a killed worker it continues where it stopped, and on anActivetenant it returns at once. A failure leaves the tenantPendingand throwsFailedwithtenantId. Another run holding the tenant throwsInProgress; repeat later. A crashed run frees the tenant for a repeat after the lease runs out (15 minutes by default,tenancy.provisioning.lease_seconds). The reasonsTenantNotFoundandTenantNotPending(inactive or suspended) will not go away on a repeat, and neither willConflict: a schema of the tenant’s name that the tenant never claimed, or a user already in the tenant besides the first administrator. The tenant staysPendinguntil an operator resolves it; do not queue a retry.
Tenancy\Contracts\TenantRenamerInterface changes the slug of an existing tenant, which is the
host <slug>.<base domain> it is served on. Nothing else moves: the tenant’s schema, data, channel
webhooks and tokens stay as they are.
rename(string $tenantId, string $newSlug): RenamedTenantruns in one landlord transaction and is fast enough for an HTTP request.RenamedTenantcarriesid,slug,previousSlug,changed,urlandloginUrl(on the new host, as inTenantSummary) andredirectUntil. Renaming to the slug the tenant already has succeeds withchangedfalse and writes nothing, so a caller that crashed after the call can repeat it.Active,InactiveandSuspendedtenants can be renamed.- The slug is checked as at creation. A refusal is a
TenantRenameFailedExceptionwith areason(Enums\RenameFailure):SlugInvalid(withproblem, the sameSlugProblemascheck()),SlugReserved,SlugTaken(also a lost race with another claim),TenantNotFound,TenantPending(an unfinished registration holds the slug),Unavailable(the installation does not resolve tenants by host, so a slug is not an address) andFailed.isInputError()is true for every reason exceptFailed, and onlyFailedis worth repeating. - The old host redirects
GETandHEADrequests to the same path and query on the new host with HTTP 302 untilredirectUntil, and only while the tenant isActive: the old host of anInactiveorSuspendedtenant, which can be renamed, answers 404 (the platform settingtenancy.rename.redirect_days, 30 days unlessTENANCY_RENAME_REDIRECT_DAYSor a stored value says otherwise;nullwhen the redirect is switched off). Any other method gets 404 at once, so a link issued before the rename, such as a staff activation or a password reset, still works through the redirect during that period; a support-access grant does not and must be issued again. - A slug a tenant gave up stays reserved for that tenant for good, redirect or not:
check()andreserve()answerTakenfor it, and no other tenant can be renamed to it. The tenant itself can take it back. - Staff are signed out, because the session cookie belongs to the old host (host mode requires
SESSION_DOMAINto be empty, so it is host-only). Core notifies nobody and keeps no history of renames: telling the tenant’s staff the new address and recording the change are the caller’s job. ReadurlandloginUrlagain from the directory instead of keeping old copies, and address the tenant by id, never by slug.
Tenancy\Contracts\TenantDecommissionerInterface (experimental) removes a tenant completely and
irreversibly. No backup or dump is made: ask the owner or the operator to confirm before calling it.
decommission(string $tenantId, DecommissionReason $reason): DecommissionedTenantis slow (provider calls, file deletion, dropping a schema): call it from a queued job, never from an HTTP request.DecommissionReasonisOwnerRequestorRetention; it is carried to the event.- In order, each step safe to repeat: the tenant stops being served (its status becomes
Inactive, so a run that fails half way leaves it unserved and retriable); the provider-side channel webhooks are removed while the bot tokens still exist (a provider that refuses is logged and never stops the removal) and the tenant’s cache entries are forgotten; the webhook routing and the support access tokens are deleted; the media objects undertenants/{id}/on the installation’s media disk are deleted; the tenant’s schema is dropped; the event is dispatched and the log line written; and last the landlord row is deleted, so the slug is free at once. A tenant that keeps its media in storage of its own (a client bucket) loses nothing there:mediaKeptInClientStorageis true. DecommissionedTenantcarriestenantId,slug,alreadyGoneandmediaKeptInClientStorage. An unknown tenant is reported asalreadyGone(no slug, no event), so a job that crashed after the call can repeat it.Active,InactiveandSuspendedtenants can be removed; aPendingone is refused.- A refusal or failure is a
TenantDecommissionFailedExceptionwith areason(Enums\DecommissionFailure):Pending(nothing was deleted; do not retry until provisioning is resolved) andFailed(the cause is inprevious). Repeating afterFailedis safe: the removal picks up what is left. - When the schema is gone Core dispatches
Events\TenantDecommissioned(tenantId,slug,reason) through Laravel’s event dispatcher, and only then deletes the landlord row. An operator package listens to erase its own data about the tenant. The tenant’s data no longer exists when the event arrives, so a listener works from these values alone. Delivery is at least once: if a listener throws, the call fails withFailed, the row stays, and the next call finds the tenant again and dispatches the event again, so a listener must be idempotent. Once the row is gone the tenant isalreadyGoneand nothing is dispatched. Core also writes atenant.decommissionedinfo line (tenant_id,slug,reason) each time it dispatches the event and the row is about to go. - Run it from a job that is unique per tenant. Core’s own job (
DecommissionTenantJob) runs on thetenancy.decommissionqueue, on a connection whoseretry_afteris above the job’s timeout (see Queues).
Tenancy\Contracts\TenantSelfDeletionPolicyInterface (experimental) is implemented by an operator package.
allows(string $tenantId): boolis asked while the tenant’s settings page is rendered and again when an administrator confirms, so answer quickly. It is asked only where the installation resolves tenants by host; insinglemode nobody can delete the workspace whatever the policy says. When it says yes, an administrator of the tenant (never the platform support user) sees a “Delete workspace” section in the settings and confirms by typing the workspace’s slug.- Core records the request and starts the removal 24 hours later (
tenants:start-deletions, every minute). Every administrator is told by email at once, the workspace works as usual until then, and any administrator can cancel in the settings (the other administrators are told by email who did). When the time comes Core queues the removal with the reasonOwnerRequest, after checking that the request was not cancelled. A stopped tenant’s administrators can ask and cancel too. - Core binds a default that answers false, so an installation without an operator package never offers it. Bind your own before Core’s providers register, as for the other defaults.
Tenancy\Contracts\TenantOnboardingInterface (experimental) controls a tenant’s first-run setup wizard.
A tenant whose onboarding is pending has its console held in the wizard until the required steps are done.
restart(string $tenantId): voidputs the tenant back into the wizard; restarting one already pending succeeds and starts over. Steps the tenant’s data satisfies stay done, the language confirmation is asked again. It closes the console of a working tenant’s staff, so ask the operator to confirm first. It is one write in the tenant’s schema, fast enough for an HTTP request.isPending(string $tenantId): booltells whether the wizard is pending.- Both throw
Exceptions\TenantOnboardingExceptionwhen the tenant does not exist or is notActive.
Enums\TenantStatus gains Pending. New statuses and reasons may appear in a minor release, so
branch on them with a default arm.
Tenancy\Contracts\TenantDirectoryInterface is the read side: list(TenantListQuery): TenantList,
find(string $id): ?TenantSummary and findMany(array $ids): array (keyed by id). Implemented by
Core; a package only calls it.
TenantListQueryfilters bysearch(case-insensitive slug substring),status,onlyIdsandexceptIds, and sorts bySlugorCreatedAt(rows without a creation time come last), ascending or descending.perPageis 1 to 100 and each id list holds at most 1000 ids.onlyIds: []matches nothing;nullmeans no restriction.TenantListcarriesitems, thetotalacross all pages,pageandperPage.TenantSummarycarriesid,slug,status(Pending,Active,Inactive,Suspended),createdAt(UTC, may be null),url(the tenant host root, with a trailing slash) andloginUrl(the admin login). With a single tenant per installation every tenant shares the application URL, sourladdresses a tenant only when the platform resolves tenants by host.- Ids are lowercase RFC 4122 ULIDs. Any other form names no tenant:
findreturnsnull, andfindManyand the id filters ignore it.
Operator\Contracts\OperatorAccessInterface answers one question for every operator screen: may this
request look at it. canView(Request $request, OperatorSurface $surface): bool, where OperatorSurface is
Horizon, Pulse, Telescope, Logs or Health (new surfaces may be added in a minor release; an
implementation answers no for one it does not know). Core’s own Horizon gate and packages that bring operator
screens only ask it and have no sign-in of their own. Core binds a default: on a single installation, a
signed-in, active staff member who holds the view_operator_screens permission, the tenant’s platform support
user excluded; in host mode, nobody. An operator layer rebinds the contract with its own answer, reading the
sign-in it owns from the request. If your package registers a Gate ability for a screen, ask the contract from it and note that Core’s administrator bypass skips only viewHorizon, viewPulse and viewTelescope. Answer no when you cannot tell, and do not throw to say no.
Experimental since 0.34. Health\Contracts\InstallationHealthInterface gives a package that renders it (an
operator panel, a monitoring package) the health of the whole installation. report(): InstallationHealthReport
holds one ServiceHealth per service the installation probes (service() finds one; null means “not monitored”,
never healthy) and generatedAt. Each ServiceHealth carries the MonitoredService (reverb, gateway,
webhook_registry, queues), a HealthState, a one-sentence reason, checkedAt, an optional endpoint and a
list of HealthMetric (name, value, unit, subject; metric() finds one).
upmeans the service answered and is healthy;downonly that it answered and is not;unknownthat it could not be read (unreachable, timed out, misconfigured, the probe failed);disabledthat it is switched off on purpose. Showunknownas unknown, never as healthy or down. New services, states and units may be added in a minor release, so branch on them with a default arm.- The metrics:
reverbreportsconnectionsandchannels;gatewayreportsspec_status(matches,missing,differs) anddrifted_channelsper platform;webhook_registryreportsmissing,staleandorphaned;queuesreportswait_secondsandthroughput(jobs per minute) per queue andfailed_jobs. A value of null was not measured; it is never a zero in disguise. - Nothing in it is a secret or names a tenant: an endpoint and a reason carry no user name, password or query of a URL, and Reverb is reported by counts, not channel names.
- It does not decide who may see it. Ask
OperatorAccessInterface::canView()forOperatorSurface::Healthfirst. It needs no request and no tenant context. - Core binds a default over its own health service; an operator layer may rebind it. A Core older than 0.34 of
Foundation leaves it unbound: check
app()->bound()and say the figures are unavailable. It never throws. Resolve it where you use it rather than keeping it in a singleton of your own. - Each probe’s answer is cached for 5 to 30 seconds, and a slow source waits for its timeout (a few seconds), so a call with a cold cache can block for several seconds. Call it when a screen renders or polls, not on every request, and poll no more often than every 5 seconds.
Tenancy\Contracts\TenantAccessModeInterface lets an operator package stop a tenant without removing it.
Core asks it, and a package implements it; Core’s default answers “active” for every tenant.
stateFor(string $tenantId): TenantAccessState. Core calls it on every request to a tenant host and before every unit of runtime work, so answer quickly from a cache. Implementations should not throw: ifstateForthrows, Core reports the exception and treats the tenant as active (an outage of the operator must not stop every tenant). The mode is computed: nothing schedules a change of it.TenantAccessStatecarries anAccessMode(ActiveorStopped; new modes may be added in a minor release, so keep a default arm) and an optionalAccessNotice(title,message,actionLabel,actionUrl, the last two together and http or https). The notice is shown as a banner in the admin panels and given to the builder as the shared propaccessState; it may accompanyActivetoo.- While a tenant is
Stopped: inbound messages, event triggers and notifications sent from a flow are dropped with a log line; delayed wake-ups, send-message timeouts and the broadcast run wait (re-checked every hour, so work resumes up to an hour after the tenant is active again) and a broadcast’s recipients stay pending and are sent once it is; the console, builder, media library and mini app refuse changes with423 Lockedand the notice, while reading stays open; the platform support user may still change things. The console shows the notice as a banner. The conversation record, delivery statuses, webhook sync and the console commands run as usual. The tenant staysActiveas a status, so its host keeps answering.
Tenancy\Contracts\SupportAccessInterface lets an operator package send its staff into a tenant’s
admin panel. Implemented by Core; a package only calls it.
issue(SupportAccessRequest): SupportAccessGrant.SupportAccessRequestcarriestenantId,operatorRef,operatorNameandoperatorEmail: who is asking, as the package knows them. Core does not check them and records the name and email in the tenant’s support access log.SupportAccessGrantcarriesenterUrl(absolute, on the tenant’s own host),token()andexpiresAt(UTC). The token is single use and valid for 60 seconds. Send the operator’s browser toenterUrlwith an auto-submitting formPOSTwhose body has atokenfield; never put the token in a URL, a log or a queue. A grant is not a session: the browser must arrive within the minute.- Entering signs the browser in as the tenant’s platform support user: an administrator account with no password that Core creates on the first entry. Its session lasts 60 minutes, shows a banner naming the operator and is recorded in the tenant’s support access log, which the tenant’s administrators read on the Support access page of the new admin interface. The platform support user is also listed, marked “Platform support”, in the tenant’s users list.
- Support access works only where tenants are resolved by host, and is off unless the platform
enables it (
SUPPORT_ACCESS_ENABLED, configtenancy.support_access.enabled). Off,issue()throwsExceptions\SupportAccessUnavailableException::disabled(); an unknown or inactive tenant throwstenantNotFound()ortenantNotActive(). Branch on the exception’sreason(SupportAccessFailure:Disabled,TenantNotFound,TenantNotActive), not on its message.
saas.<base_domain>, adds that label to the config tenancy.platform_subdomains while it
registers (in the service provider’s register()). Core then serves that host with no tenant,
like the base domain, answers 404 for the tenant panels there, and reserves the label as a tenant
slug. Only first-level labels count. Such a host has no tenant schema, so sessions there cannot
use the database driver: the sessions table lives in tenant schemas. A tenant that already holds
the label as its slug stops being served once the label is declared.
Solution entitlement
Solution\Contracts\SolutionEntitlementInterface::entitlementFor(string $tenantId): SolutionEntitlement lets an
operator package say which installed Solutions a tenant may run, for example a plan’s bundle plus the add-ons the
tenant pays for. Core asks it, a package implements it; Core’s default allows every Solution (available from
Foundation 0.20; grants from 0.25).
- A Solution is either granted or allowed. Granted: Core runs it without the tenant turning it on, and the tenant cannot turn it off — use it for a plan’s bundle and a running add-on. Allowed: the tenant turns it on and off itself.
- Return
SolutionEntitlement::grants($grants, $allowed)with aSolutionGrantper granted Solution (its id, aSolutionGrantSourceofPlanorAddon, and optionally an end and a note for display),SolutionEntitlement::all()when everything is allowed and nothing restricted, orSolutionEntitlement::only($ids)to allow only these (only([])for none, and for a tenant you do not know). Ids this image does not install are fine; Core intersects the answer with what is installed. Each takes an optional button for the tenant’s admins,actionLabelandactionUrltogether (absolute http or https), shown as is on a Solution the answer does not include, for example “See plans”. - Grant only what must run without the tenant’s action. A Core older than 0.25 sees a grant as allowed: the tenant turns it on by hand.
- Losing a grant or the entitlement is an answer, not an action: the Solution stops running (its flow actions answer
solution_inactive, its console interface disappears) with its data kept, nothing is written, and it runs again as soon as your answer includes it. Do not turn Solutions on or off through Core. - Core refuses to turn on a Solution the answer does not include, and to turn off one it grants, from the admin panel
and from
solutions:activateandsolutions:deactivate. - Core asks at most once per tenant per request or job, whenever a Solution is installed (a grant needs nothing stored). Answer from a cache and invalidate it when a plan, an add-on or a request changes.
- Do not throw for “nothing entitled”. If
entitlementForthrows, Core reports it, keeps running what the tenant turned on and what your last answer granted (Core keeps those grants per tenant for at most a day), and refuses to turn any on or connect any until it can ask again.
Solution storefront
Experimental.Solution\Contracts\SolutionStorefrontInterface lets an operator package offer a tenant the Solutions
it can connect, on the Solutions page of the admin panel. Core asks it only from that page and its Connect
button, never from a job; Core’s default offers nothing.
offersFor(string $tenantId): list<SolutionOffer>— at most one offer per Solution, with its name, description,trialDays, a display-onlySolutionPrice(amount in minor units, ISO currency, period) and whether a request is already pending. Offer nothing for a Solution you already grant or allow; Core hides such an offer anyway.connect(string $tenantId, string $solutionId, string $requestedBy): SolutionConnectResult— start a trial (trialStarted(): grant it in your next entitlement answer), record a request for your operators (requested()), say one is already waiting (alreadyPending()), or refuse with a reason (refused($message)). Make it idempotent, write only your own tables, and do not throw for “not allowed”.- Core calls
connectonly for a staff user who may manage the tenant’s Solutions, and refuses while it cannot read your entitlement answer. It writes nothing of its own and asks your entitlement again right after.
Quota
LimitRegistryInterface has register(LimitDefinition), find(string $key) and all() (ordered by
key). Registering an already known key, or registering after boot has finished, throws a
LogicException: register while the application boots, from a service provider.
LimitDefinitioncarrieskey(snake_case, such asassistants; plans store limits under it),labelandunit(English, what an operator reads),kindand an optionaldescription.Enums\LimitKindsays what a limit counts:Records(exist at a time, deleting one frees a slot),PerPeriod(used within a billing period) andBytes(stored bytes). Callers matching on it keep a default arm, because kinds may be added in a minor release.
TenantLimitsInterface::limitFor(string $tenantId, string $key): ?int returns the limit (at least 0)
or null for no limit. The implementation only answers “how much”; Core counts what the tenant uses,
because the records live in the tenant’s own schema, and refuses creation over the limit. It is called
on creation paths, so answer quickly and cache what you read. Bind it in your package’s service
provider: Core binds its default only when nothing is bound yet, so your binding wins whatever the
provider order.
RecordQuotaInterface has canCreate(string $key, int $current): bool and
assertCanCreate(string $key, int $current): void. You count the tenant’s existing records and pass
the number; Core reads the limit for the tenant of the current request or job. assertCanCreate
throws Quota\Exceptions\RecordLimitReachedException (key, label, limit, current; the
message is meant for people, such as “Assistants limit reached: 1 of 1.”), and a LogicException
when the key is not registered, so a typo never means “no limit”.
Core registers four keys of kind Records:
Existing records are never removed when a limit drops
below the current count: only creating more is refused.
Stored bytes
Core registers one key of kindBytes:
The limit is a number of bytes (a 64-bit integer;
limitFor returns a PHP int). Core compares what
the tenant stores plus the new file with it before a byte is written, and refuses a file that does not
fit; a file the tenant already stores adds nothing and is always accepted. Existing files stay when the
limit drops below what is stored: only new bytes are refused. Nothing counts when limitFor answers
null, and Core then runs no query for the check.
Your limitFor is called on every upload of new content, so it follows the same rules as for records.
When it throws, a staff upload fails (the person retries), while an inbound file, such as a contact’s
attachment, is stored and the exception is reported, because nobody is there to retry. Concurrent
uploads can overshoot the limit by at most the files in flight.
Reading the usage
TenantUsageInterface::current(string $tenantId, string $key): ?int returns how much of a Records
or Bytes key the tenant uses now, counted by Core in the tenant’s own schema: bytes for
media_storage. It is for showing “used of limit”, never for enforcing one. Core counts with the same
code that enforces the limit, so a refusal and the figure you show cannot disagree.
- It answers for every
Recordskey Core registers (assistants,flows,channels,staff) and formedia_storage. It answersnullfor a key Core does not count (PerPeriodkeys are alwaysnull, you count those, and so is a key a Solution registers without a counter), for a tenant that does not exist, and for one still being provisioned. Treatnullas “not reported”, not as zero. - Call it outside a tenant context. Core switches to the tenant, counts and restores the context you had, also when counting fails.
- Each call switches to the tenant’s schema and runs a query: cache the answer, and do not call it for every row of a list.
Reporting use to the tenant
The tenant’s admins see “used of limit” on the Usage and limits page. Core countsRecords and
Bytes keys itself; for PerPeriod keys it asks you, through
PeriodUsageInterface::reportFor(string $tenantId, string $locale): ?PeriodUsageReport.
Quota\DTO\PeriodUsageReport carries usage, a list of Quota\DTO\PeriodUsage (one per key you
report), and an optional action, an actionLabel and an absolute http(s) actionUrl given together,
for example “Upgrade plan”. A PeriodUsage carries the key, used (at least 0, it may exceed the
limit by the parallel workers), limit (null for no limit), and the period as periodStartsAt
(inclusive) and periodEndsAt (exclusive). A key you do not list is shown as “no data”, never as
zero; Core ignores entries whose key is not a registered PerPeriod key. Both classes throw
InvalidArgumentException on a negative number, a period that does not end after it starts, a
duplicate key, or an action with only a label or only a URL.
null, or a
key missing from the report, reads “No data” instead. The limit shown for a reported key is
the one in your report, so a plan change that your TenantLimitsInterface has cached for an hour does
not make the row disagree with its own count. Core marks a row “almost used up” from 80% of the limit;
that is a fixed display threshold, not your notification threshold.
Bind it in your package’s service provider; Core binds its default only when nothing is bound yet.
Counting use over a period
UsageMeterInterface::consume(UsageUnit $unit): UsageDecision serves keys of kind PerPeriod. Core
calls it before the work is done, once per unit, and does the work only when the answer is allowed.
The period belongs to the operator’s subscription: Core never computes it and only says when the
unit was used.
Quota\DTO\UsageUnitcarriestenantId,key,unitKey(the unit’s natural key, at most 191 characters) andoccurredAt(aDateTimeImmutablethat picks the period). Each unit counts as 1.Quota\DTO\UsageDecisioncarriesallowed, thelimitfor the period (nullfor no limit),used(units counted after this call,nullwhen unknown) and an optional Englishmessagefor people. A refusal or an allowed decision can also carryperiodEndsAt(aDateTimeImmutable), when the period the decision belongs to ends; Core reads it from a refusal and from a warning, and ignores it on a plain allowed decision.approachingisfalseunless you build the decision withUsageDecision::approaching(). Build it withUsageDecision::allowed($limit, $used, $periodEndsAt),UsageDecision::refused($limit, $used, $message, $periodEndsAt)orUsageDecision::approaching($limit, $used, $periodEndsAt); the trailing arguments are optional.approaching()needs a limit of at least one.Quota\Exceptions\VolumeLimitReachedException(key,limit,used) is thrown byMessageSenderInterface::send()when the tenant’s outbound volume is used up. Nothing was sent; do not retry.
- May read and write its own tables, cache “already counted this period” per tenant, and
overshoot the limit by at most the number of parallel workers. It may return
UsageDecision::approaching()for the unit that brings the period’s use to its own warning threshold, to have Core warn the tenant’s admins (see below); the unit is allowed like any other. - Must be idempotent by tenant, key,
unitKeyand the period containingoccurredAt, so a retried unit is counted once; never record a refused unit, so asking again succeeds once the limit is raised or a new period starts; answer allowed for a key it has no limit for; derive the period itself; and stay cheap, because Core calls it on every inbound message. When it flags a decision as approaching, it must flag at most once per tenant, key and period and passperiodEndsAtwith the flag: Core also sends at most one warning per limit and period, but a meter that flags every unit above its threshold makes every such unit cost a cache write. - Must not flag a refused unit, or one it has already counted (a retry), as approaching; send the warning to the tenant’s admins itself, because Core owns the recipients and their language; throw to refuse, because a refusal is a result; call Core’s classes or write Core’s tables or a tenant schema; dispatch jobs, send mail or call external services while it answers; or keep one tenant’s data in object properties between calls, because workers are long-lived and serve many tenants.
unitKey and occurredAt that are the same on every retry of the same unit where they
have a stable time, and otherwise the current time (a retry that crosses a period boundary then
counts one extra unit). They pass only registered PerPeriod keys, never put personal identifiers in
unitKey (hash them), and never ask twice with different keys for one unit.
Bind it in your package’s service provider: Core binds its default only when nothing is bound yet.
Core fails open: if your implementation throws, Core reports the exception and lets the work
through, because an outage of the operator must not stop every tenant’s bots at once. A key that is
unregistered or not PerPeriod is a LogicException.
Core registers six keys of kind PerPeriod:
Core asks before the message is delivered, the call is made or the run starts, so a refusal means nothing was sent or started.
Outbound messages go through
MessageSenderInterface::send(), which throws
VolumeLimitReachedException for a refusal; if you send messages from your own code, treat it as
“not sent, do not retry”. A flow follows the node’s error exit with error_type limit_reached, or
stops the session when the node has none; a broadcast stops at the first refusal and is cancelled
with the reason limit_reached.
A caller that has a stable time for a message, such as a broadcast recipient’s creation, puts it in
the message’s metadata as volume_occurred_at (ISO 8601). Core’s gate is the only reader: it uses it
as occurredAt so a retry lands in the same period, and otherwise uses the moment of sending. The
key is passed on to the provider sender and the transcript capture untouched, and is not a field of
OutboundMessage yet.
For an inbound refusal the message is dropped before anything is stored: no contact, no
transcript entry, no flow, and no reply to the sender. A contact who is already counted in the period
keeps working until the period ends. Core keeps a count of refused messages per person (a pseudonymous hash), bot and
day for 90 days and shows it to people who may see contacts on the assistant’s overview.
Telling the tenant’s admins
When a limit uses up, Core tells the tenant’s admins once per limit and period: one notification in the panel’snotifications table and one email each, in the language each admin chose. It names the
limit, writes “used of limit”, says what was turned away and what happens next. A notification is sent
when work is refused under any limit, and, for a Records limit, also when a saved record takes the
last place, and, for a PerPeriod limit, before it is used up when your meter asks for it; the notice for a filled Records limit is sent only for records created by Core’s own five creation paths (assistants, flows, channels, new staff and reactivated staff), while a Solution’s own record keys get refusal notices only. Two creates running at the same time may both count the same number of existing records and so miss it. The platform support user and deactivated or suspended accounts are not told.
“Once per limit and period” means:
- a
PerPeriodlimit: once for the period your refusal reports inUsageDecision::$periodEndsAt, or once per calendar month in UTC when it does not; - a warning that a
PerPeriodlimit is close (UsageDecision::approaching()): once for the period your decision reports inUsageDecision::$periodEndsAt, or once per calendar month in UTC when it does not. It counts apart from the notice that the limit is used up, so a warning never silences that notice in the same period. Core sets no warning threshold of its own, and none forRecordsorByteslimits: only aPerPeriodmeter can ask for one; - a
RecordsorByteslimit: once per limit value, and again at most every 7 days while work keeps being refused. Raising the limit and reaching the new one speaks at once.
LimitNoticeInterface::noticeFor(string $tenantId, string $key, string $locale, LimitNoticeReason $reason): ?LimitNotice lets
your package replace the “to raise the limit, contact the platform administrator” block with its own:
an upgrade offer and a button. Quota\DTO\LimitNotice carries a message and an optional action, an
actionLabel and an absolute http(s) actionUrl given together. Core calls it from a worker, once per
language of the recipients, never on the path that refuses the work. Quota\Enums\LimitNoticeReason says why you are asked: Refused (work was turned away), Reached (a Records limit was just filled and nothing was refused yet) or Approaching (a PerPeriod limit is close to being used up and nothing was refused), so you can word an offer differently; keep a default arm, reasons may be added in a minor release. Return null to let Core write
its text.
Your implementation:
- May read its own tables (plan, subscription), answer in the requested locale or in English when
it has no translation, word the notice by the reason, and return
null. - Must return text that replaces only the “what to do next” block, and an absolute http(s) action URL.
- Must not repeat the limit’s name or the numbers, which Core writes; send mail, dispatch jobs or call external services; call Core’s classes or write Core’s tables or a tenant schema; or keep one tenant’s data in object properties between calls.
null and reports it: a faulty operator never stops the notification.
Bind it in your package’s service provider; Core binds its default only when nothing is bound yet.
Platform settings
Experimental: may change in a minor release.
Settings\Contracts\PlatformSettingsInterface reads and changes Core’s platform-wide settings — values for the
whole installation, not one tenant, such as flow.execution.max_iterations. Implemented by Core; an operator
package calls it to show the settings in its own panel.
-
definitions(): list<PlatformSettingDefinition>, ordered by group then key. A definition carrieskey,type(Enums\PlatformSettingType:Integer,Boolean,Text,Choice; more may come in a minor release),default(the installation’s default,.envincluded; it may lie outside the bounds), Englishlabel,descriptionandgroup,unit,min,max,choices, andhostModeOnlyfor a setting that only has an effect when tenants are resolved by host.violation($value)says in English why a value would be refused, ornull: the same check Core applies. -
values(): list<PlatformSettingValue>:key, thevaluein effect, itsdefault, andstored— whether a value was stored or the default applies. -
update(array $changes, string $actor): key ⇒ value;nullremoves the stored value so the default applies again, and keys left out are not changed. Every change is recorded with the actor (for exampleoperator:<id>). A refusal isExceptions\InvalidPlatformSettingsException, whoseviolationsname each refused key; nothing is written then. -
Must render fields from
definitions(), never from a list of keys of its own. -
Must not read or write Core’s
platform_settingstables or read Core’s config for these values; keepvalues()beyond one request.
Retrieval
Contracts\RagAdapterInterface with RagQueryContext, StructuredRagResult, and
RagConfidence.
Analytics
Analytics\Contracts\AnalyticsWriterInterface, with AnalyticsEvent and
AnalyticsEventType.
Builder mode usage (experimental)
Since foundation 0.47 an operator package can see which layout of the flow builder, the tree or the graph, a tenant’s staff work in.Analytics\Contracts\BuilderModeUsageInterface::usageFor(string $tenantId): ?BuilderModeUsage returns how
many staff users of the tenant have each mode now: tree, graph and their total. Core implements it.
- It counts the staff users the
stafflimit counts: every account not deactivated, invited ones included, without the platform’s support user.totaltherefore equals whatTenantUsageInterfacereports forstaff. Someone who never chose a mode works in the tree and is counted there. - It answers
nullfor a tenant that does not exist and for one still being provisioned. Treatnullas “not reported”, not as zero. - Call it outside a tenant context, and cache the answer: Core switches to the tenant’s schema and runs a query on each call.
Analytics\Events\BuilderModeChanged is dispatched after a staff user switched the builder to the other
mode and the choice was saved, except the platform’s support user’s, which usageFor() does not count either. It carries tenantId, mode and previousMode ('tree' or 'graph') and
occurredAt, and names no user. Choosing the mode one already has dispatches nothing. Listen to it to follow
the switches over time; do not rebuild the current counts from it, because deactivating or removing a user
dispatches nothing — read usageFor() for those.
Other
Contracts\ModelAttributeResolverInterface, Contracts\ModelUtilityInterface,
Action\ActionHandlerInterface, Support\Version.
Generated PHP API documentation is produced separately with
composer run docs:build, which writes Doctum output to public/core. That
covers every class in the repository; this page covers the ones you are allowed
to depend on.