Journal API Contract
The Pydantic models of the envelope and the error body of every journaled response, and of a journal entry. See Smarter Journal.
Pydantic models of the Smarter Journal api contract.
They describe the envelope that smarter.lib.journal.http.SmarterJournaledJsonResponse
adds to every journaled response, the error body of
smarter.lib.journal.http.SmarterJournaledJsonErrorResponse, and a journal entry, a
smarter.lib.journal.models.SAMJournal row.
These models are the contract’s single source of truth:
the journaled responses are built from them, by
smarter.lib.journal.http,the JSON Schema in
journal-contract.schema.jsonis generated from them (manage.py export_journal_contract_schema), for the clients that read journaled responses, such as thesmartercli.
The envelope and the error body allow extra fields, because each view adds its own data beside
them. The model of a journal entry (SAMJournalApiOrmModel) has exactly the row’s fields.
Adding a field is backward compatible. Removing or renaming one that is declared here is not.
- smarter.lib.journal.contract.models.CONTRACT_MODELS: tuple[type[BaseModel], ...] = (<class 'smarter.lib.journal.contract.models.SAMJournalApiEnvelope'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiErrorResponse'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiResponse'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiOrmModel'>)
The models whose JSON Schema is exported.
Their dependencies are exported with them.
( <class 'smarter.lib.journal.contract.models.SAMJournalApiEnvelope'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiErrorResponse'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiResponse'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiOrmModel'>, )
- smarter.lib.journal.contract.models.JOURNAL_API_MODELS: tuple[type[BaseModel], ...] = (<class 'smarter.lib.journal.contract.models.SAMJournalApiEntry'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiPage'>)
The models whose JSON Schemas the Smarter api’s OpenAPI document includes.
( <class 'smarter.lib.journal.contract.models.SAMJournalApiEntry'>, <class 'smarter.lib.journal.contract.models.SAMJournalApiPage'>, )
- smarter.lib.journal.contract.models.SAMJournalApiCommand
the choices of
SAMJournal.command.See
smarter.lib.journal.enum.SmarterJournalCliCommands.choices().- Type:
A journal entry’s
command
alias of
Literal[‘apply’, ‘prompt’, ‘chat_config’, ‘delete’, ‘deploy’, ‘describe’, ‘get’, ‘journal’, ‘logs’, ‘example_manifest’, ‘status’, ‘json_schema’, ‘version’, ‘undeploy’, ‘validate’, ‘whoami’, ‘resources’]
- class smarter.lib.journal.contract.models.SAMJournalApiEntry(**data)[source]
Bases:
SAMJournalApiEntrySummaryA journal entry, as the journal’s REST api returns it by its key: with its request and response documents.
It is the output of
smarter.lib.journal.serializers.SAMJournalSerializer, in camelCase. The request document holds the caller’s headers and cookies, including its api key.- classmethod from_model(journal)[source]
The REST api’s model of a journal entry.
- Parameters:
journal (
SAMJournal) – The journal entry, whoseusershould be fetched with it.- Returns:
Its model.
- Return type:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiEntrySummary(**data)[source]
Bases:
BaseModelA journal entry, as the journal’s list returns it: without its request and response documents.
It is the output of
smarter.lib.journal.serializers.SAMJournalMiniSerializer, in camelCase. UnlikeSAMJournalApiOrmModel, itsuseris the username.- classmethod from_model(journal)[source]
The REST api’s summary of a journal entry.
- Parameters:
journal (
SAMJournal) – The journal entry, whoseusershould be fetched with it.- Returns:
Its model.
- Return type:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod summary_fields(journal)[source]
The fields of a journal entry that both of the REST api’s models have.
- Parameters:
journal (
SAMJournal) – The journal entry, whoseusershould be fetched with it.- Returns:
The fields, by name.
- Return type:
- class smarter.lib.journal.contract.models.SAMJournalApiEnvelope(**data)[source]
Bases:
SAMJournalApiModelThe fields that every journaled response adds beside the view’s own data.
- classmethod build(command, thing)[source]
The envelope of a response, without a journal key.
- Parameters:
- Returns:
The envelope.
- Return type:
- dump()[source]
The envelope as the JSON keys that a journaled response adds:
apiandmetadata.The metadata’s
keyis left out until the journal entry is saved.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiErrorBody(**data)[source]
Bases:
SAMJournalApiModelThe
errorof a journaled error response: the same shape for every error of the cli and the other journaled apis.The field names are the values of
smarter.lib.journal.enum.SmarterJournalApiResponseErrorKeys.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiErrorResponse(**data)[source]
Bases:
SAMJournalApiModelThe body of a journaled error response.
SAMJournalApiEnvelope’sapiandmetadataare added besideerror.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- type smarter.lib.journal.contract.models.SAMJournalApiJson = _AllowAnyJson]
A value that is stored, and returned, as arbitrary JSON, e.g. a journal entry’s request and response documents.
- class smarter.lib.journal.contract.models.SAMJournalApiMetadata(**data)[source]
Bases:
SAMJournalApiModelThe
metadataof a journaled response: its command and thing, and, when the journal is enabled, the key of its journal entry.commandandthingare the strings of the values that the view passed, which may be"None"when it passed none, so they are not limited to the journal’s choices.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiModel(**data)[source]
Bases:
BaseModelBase class of the contract’s models of responses, which allow extra fields.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiOrmModel(**data)[source]
Bases:
BaseModelA journal entry: a
smarter.lib.journal.models.SAMJournalrow.Its fields are exactly the row’s fields, so extra fields are forbidden. It is built from the row by
from_model().- classmethod from_model(journal)[source]
The model of a journal entry.
- Parameters:
journal (
SAMJournal) – The journal entry.- Returns:
Its model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiPage(**data)[source]
Bases:
BaseModelOne page of the journal’s entries, newest first unless sorted, and a description of the page.
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.lib.journal.contract.models.SAMJournalApiResponse(**data)[source]
Bases:
SAMJournalApiEnvelopeA journaled response: the envelope, beside the view’s own data, e.g.
dataorerror.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter.lib.journal.contract.models.SAMJournalApiThing
the choices of
SAMJournal.thing.See
smarter.lib.journal.enum.SmarterJournalThings.choices().- Type:
A journal entry’s
thing
alias of
Literal[‘Account’, ‘ApiConnection’, ‘ApiPlugin’, ‘SmarterAuthToken’, ‘Budget’, ‘CustomDomain’, ‘Guardrail’, ‘ImageSearchPlugin’, ‘LLMClient’, ‘MCPClient’, ‘Orchestrator’, ‘Prompt’, ‘ChatConfig’, ‘Proxy’, ‘Provider’, ‘Secret’, ‘SkillPlugin’, ‘SqlConnection’, ‘SqlPlugin’, ‘Plugin’, ‘User’, ‘Vectorsearch’, ‘Vectorstore’, ‘WebsearchPlugin’]
The JSON Schema of the Smarter Journal api contract, generated from its Pydantic models.
manage.py export_journal_contract_schema writes it to journal-contract.schema.json, beside
this module, and a test fails if the committed file is out of date.
- smarter.lib.journal.contract.schema.journal_contract_schema()[source]
The contract’s JSON Schema (draft 2020-12): one definition, in
$defs, per model.
- smarter.lib.journal.contract.schema.journal_contract_schema_json()[source]
The contract’s JSON Schema, as the text of
journal-contract.schema.json.- Returns:
The schema, as indented JSON, with a final newline.
- Return type: