artifactr.workspace¶
Tenant-scoped workspaces over pluggable storage.
Open a Workspace with Workspaces.open; every read and write goes through it,
and every write runs core's rules in one storage transaction.
Workspaces¶
Tenant-scoped handles. See Workspaces, commits and the log.
Workspaces
¶
Opens scoped Workspace handles over one storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage
|
Storage
|
Where workspaces are kept. |
required |
types
|
Iterable[type[Artifact]] | None
|
The artifact types this application accepts. Others are rejected even if they
are registered, so clients cannot create arbitrary types. |
None
|
open
async
¶
open(
tenant_id: TenantId,
workspace_id: WorkspaceId,
*,
actor: Actor,
) -> Workspace
Return a handle on a tenant's workspace, acting as actor.
This is the only place a tenant id enters; nothing on the handle can reach another tenant.
Workspace
¶
A handle on one tenant's workspace, bound to the actor it acts as.
Create handles with Workspaces.open, and derive handles for other actors (such as
the agent) with as_actor.
as_actor
¶
Return a handle on the same workspace that acts as actor.
commit
async
¶
commit(
command: CreateArtifact
| EditArtifact
| ArchiveArtifact,
) -> Applied | Proposed
commit(command: ProposeChange) -> Proposed
commit(command: RespondToProposal) -> Resolved
commit(
command: CreateThread
| PostMessage
| SetFocus
| SetThreadMode
| AnswerDeferred,
) -> Recorded
record
async
¶
create
async
¶
create(
artifact: Artifact,
*,
artifact_id: ArtifactId | None = None,
thread_id: ThreadId | None = None,
) -> Applied | Proposed
Create an artifact from an instance of its type.
post_message
async
¶
Post a message in a thread as this handle's actor.
get
async
¶
get(
artifact_type: type[A], artifact_id: ArtifactId
) -> Versioned[A]
Return an artifact's current version, checked to be of artifact_type.
Raises:
| Type | Description |
|---|---|
NotFound
|
If there is no such artifact of that type. |
artifact
async
¶
artifact(artifact_id: ArtifactId) -> Versioned[Artifact]
Return an artifact's current version, whatever its type.
Raises:
| Type | Description |
|---|---|
NotFound
|
If there is no such artifact. |
artifacts
async
¶
artifacts(
artifact_type: type[A] = Artifact,
*,
include_archived: bool = False,
) -> list[Versioned[A]]
Return current artifacts that are instances of artifact_type, oldest first.
revisions
async
¶
revisions(artifact_id: ArtifactId) -> list[Revision]
Return an artifact's revisions, oldest first.
thread
async
¶
proposal
async
¶
proposal(proposal_id: ProposalId) -> Proposal
proposals
async
¶
proposals(
*,
status: Literal["pending", "accepted", "rejected"]
| None = "pending",
) -> list[Proposal]
Return proposals with a status (pending by default; None for all), oldest first.
run
async
¶
runs
async
¶
Return runs, optionally of one thread and with one status, oldest first.
history
async
¶
history(thread_id: ThreadId) -> Sequence[HistoryChunk]
Return a thread's history: serialized model messages, one chunk per run segment.
read
async
¶
read(
*,
after_seq: int = 0,
threads: Collection[ThreadId] | None = None,
limit: int | None = None,
) -> list[Envelope]
Return logged envelopes after after_seq, in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
after_seq
|
int
|
Return envelopes with a greater |
0
|
threads
|
Collection[ThreadId] | None
|
Only thread-scoped events from these threads; workspace-scoped events
(artifacts, proposals) are always included. |
None
|
limit
|
int | None
|
The most envelopes to return. |
None
|
subscribe
async
¶
subscribe(
*,
after_seq: int = 0,
threads: Collection[ThreadId] | None = None,
) -> AsyncIterator[Envelope]
Yield envelopes after after_seq: the stored ones, then new ones as they commit.
Replay and live delivery are the same stream, so nothing falls between them.
change_notes
async
¶
change_notes(
*,
after_seq: int,
focus: Collection[ArtifactId] | None = None,
viewer: Actor | None = None,
) -> list[Note]
Return notes about what others did since after_seq.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
after_seq
|
int
|
Only consider envelopes with a greater |
required |
focus
|
Collection[ArtifactId] | None
|
The artifacts the viewer follows; |
None
|
viewer
|
Actor | None
|
Who the notes are for; defaults to this handle's actor. |
None
|
claim_thread
async
¶
claim_thread(
thread_id: ThreadId,
*,
holder: str,
ttl: timedelta = timedelta(seconds=30),
) -> AsyncGenerator[None]
Hold a thread exclusively, renewing the claim until the block exits.
One run is active per thread. The claim is a lease in storage, so it holds across processes and lapses by itself if the holder dies.
Raises:
| Type | Description |
|---|---|
ThreadBusy
|
If another holder has the thread. |
Storage¶
The storage protocol, and the in-memory implementation. See Storage.
Storage
¶
Bases: Protocol
Persistence for workspaces. Every method is scoped to one tenant's workspace.
transaction
¶
transaction(
scope: Scope,
) -> AbstractAsyncContextManager[Transaction]
Begin a transaction that commits when the block exits normally.
artifact
async
¶
artifact(
scope: Scope, artifact_id: ArtifactId
) -> Versioned[Artifact] | None
Return an artifact's current version, or None.
artifacts
async
¶
artifacts(
scope: Scope,
*,
kind: str | None = None,
include_archived: bool = False,
) -> list[Versioned[Artifact]]
Return current artifacts, optionally of one kind, oldest first.
revisions
async
¶
revisions(
scope: Scope, artifact_id: ArtifactId
) -> list[Revision]
Return an artifact's revisions, oldest first.
proposal
async
¶
proposal(
scope: Scope, proposal_id: ProposalId
) -> Proposal | None
Return a proposal, or None.
proposals
async
¶
proposals(
scope: Scope,
*,
status: Literal["pending", "accepted", "rejected"]
| None = None,
) -> list[Proposal]
Return proposals, optionally with one status, oldest first.
runs
async
¶
runs(
scope: Scope,
*,
thread_id: ThreadId | None = None,
status: RunStatus | None = None,
) -> list[Run]
Return runs, optionally of one thread and with one status, oldest first.
read
async
¶
Return logged envelopes with seq greater than after_seq, in order.
subscribe
¶
subscribe(
scope: Scope, *, after_seq: int = 0
) -> AsyncIterator[Envelope]
Yield envelopes with seq greater than after_seq.
First the stored ones, then each new one as it is committed. The iterator runs until it is closed.
history
async
¶
history(
scope: Scope, thread_id: ThreadId
) -> Sequence[HistoryChunk]
Return a thread's history chunks, in the order they were appended.
acquire_lease
async
¶
Take or renew an exclusive lease. Return False if another holder has it.
Transaction
¶
Bases: Protocol
One atomic unit of work on a workspace.
A transaction must be serialized with respect to every other transaction on the same scope from the moment it begins, so what it loads cannot change before it saves. The in-memory storage holds a per-workspace lock; SQL storage locks the workspace row.
Scope
dataclass
¶
Scope(tenant_id: TenantId, workspace_id: WorkspaceId)
A tenant's workspace: the unit of isolation, ordering and locking.
HistoryChunk
dataclass
¶
InMemoryStorage
¶
Storage that keeps every workspace in process memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clock
|
Clock
|
Returns the current time. Defaults to the system clock in UTC. |
_utc_now
|
transaction
async
¶
transaction(scope: Scope) -> AsyncGenerator[_Transaction]
Begin a transaction; it holds the workspace's lock until it ends.
artifact
async
¶
artifact(
scope: Scope, artifact_id: ArtifactId
) -> Versioned[Artifact] | None
Return an artifact's current version, or None.
artifacts
async
¶
artifacts(
scope: Scope,
*,
kind: str | None = None,
include_archived: bool = False,
) -> list[Versioned[Artifact]]
Return current artifacts, optionally of one kind, oldest first.
revisions
async
¶
revisions(
scope: Scope, artifact_id: ArtifactId
) -> list[Revision]
Return an artifact's revisions, oldest first.
proposal
async
¶
proposal(
scope: Scope, proposal_id: ProposalId
) -> Proposal | None
Return a proposal, or None.
proposals
async
¶
proposals(
scope: Scope,
*,
status: Literal["pending", "accepted", "rejected"]
| None = None,
) -> list[Proposal]
Return proposals, optionally with one status, oldest first.
runs
async
¶
runs(
scope: Scope,
*,
thread_id: ThreadId | None = None,
status: RunStatus | None = None,
) -> list[Run]
Return runs, optionally of one thread and with one status, oldest first.
read
async
¶
Return logged envelopes with seq greater than after_seq, in order.
subscribe
async
¶
subscribe(
scope: Scope, *, after_seq: int = 0
) -> AsyncIterator[Envelope]
Yield stored envelopes after after_seq, then each new one as it commits.
history
async
¶
history(
scope: Scope, thread_id: ThreadId
) -> Sequence[HistoryChunk]
Return a thread's history chunks, in the order they were appended.
acquire_lease
async
¶
Take or renew an exclusive lease. Return False if another holder has it.