Unreleased
Generated from the docstrings of Tau 0.16.0-dev (commit c439c401) by scripts/api_docs.py in the Tau repository. Not the 0.15 API.
The step machine¶
The sans-IO core: a Session hands out jobs and a program performs them. For a program that is its own driver.
Names: Answer, Ending, Hook, Job, Next, RunCall, SampleEnd, Session
Answer¶
class Answer
What the driver answers a Job with. Session.answer accepts one only while the job it
answers is out; any other raises WrongAnswer.
Answer.Hooks¶
class Hooks(Answer)
The hooks ran.
Answer.Hooks.new¶
def __new__(cls, stop: str | None = None, draft: Draft | None = None) -> Answer.Hooks
Answer.Hooks.stop¶
property stop: str | None
A halt reason if a hook halted the step, else None.
Answer.Hooks.draft¶
property draft: Draft | None
The draft after the hooks edited it; None commits nothing. At pre_sample, a
reply here stands in for the sample.
Answer.HookFailed¶
class HookFailed(Answer)
A hook raised.
Answer.HookFailed.new¶
def __new__(cls, error: str) -> Answer.HookFailed
Answer.HookFailed.error¶
property error: str
What went wrong.
Answer.Sampled¶
class Sampled(Answer)
The sample ended.
Answer.Sampled.new¶
def __new__(cls, parts: Sequence[Part], end: SampleEnd) -> Answer.Sampled
Answer.Sampled.parts¶
property parts: list[Part]
What streamed before it ended.
Answer.Sampled.end¶
property end: SampleEnd
How it ended.
Answer.CallDone¶
class CallDone(Answer)
One call of the batch ended.
Answer.CallDone.new¶
def __new__(cls, call: str, outcome: Outcome, by: Author) -> Answer.CallDone
Answer.CallDone.call¶
property call: str
The call's id.
Answer.CallDone.outcome¶
property outcome: Outcome
How it ended.
Answer.CallDone.by¶
property by: Author
Tools if the tool ran unedited, else the extension that answered or last edited it.
Ending¶
class Ending
How a step ended; the subject of the post_step hook.
Ending.Done¶
class Done(Ending)
The step ran to its end.
Ending.Done.new¶
def __new__(cls) -> Ending.Done
Ending.Halted¶
class Halted(Ending)
A cursor hook halted it.
Ending.Halted.new¶
def __new__(cls, reason: str) -> Ending.Halted
Ending.Halted.reason¶
property reason: str
The reason the hook gave.
Ending.Failed¶
class Failed(Ending)
A hook or the sample failed.
Ending.Failed.new¶
def __new__(cls, error: str) -> Ending.Failed
Ending.Failed.error¶
property error: str
What went wrong.
Ending.Aborted¶
class Aborted(Ending)
An abort ended it.
Ending.Aborted.new¶
def __new__(cls) -> Ending.Aborted
Hook¶
class Hook
PreStep: ClassVar[Hook]
PreInput: ClassVar[Hook]
PreSample: ClassVar[Hook]
PreReply: ClassVar[Hook]
PostReply: ClassVar[Hook]
PostResult: ClassVar[Hook]
PostStep: ClassVar[Hook]
The seven cursor hook points, in the order a step reaches them. It is not an integer.
Hook.name¶
property name: str
The name an extension defines the hook by.
Job¶
class Job
What a step asks the driver to do next, from Session.next_job. Answer it with Session.answer.
Job.Hooks¶
class Hooks(Job)
Run the extensions' hooks for one hook point.
Job.Hooks.new¶
def __new__(
cls,
point: Hook,
draft: Draft | None,
node: int | None,
ending: Ending | None,
) -> Job.Hooks
Job.Hooks.point¶
property point: Hook
The hook point.
Job.Hooks.draft¶
property draft: Draft | None
The subject at pre_input, pre_sample and pre_reply; otherwise None.
Job.Hooks.node¶
property node: int | None
The subject at post_reply and post_result: the node just committed; otherwise None.
Job.Hooks.ending¶
property ending: Ending | None
The subject at post_step; otherwise None.
Job.Sample¶
class Sample(Job)
Ask the provider for a reply to the cursor's walk.
Job.Sample.new¶
def __new__(cls) -> Job.Sample
Job.RunCalls¶
class RunCalls(Job)
Run a batch of calls and answer each with Answer.CallDone.
Job.RunCalls.new¶
def __new__(cls, node: int, calls: Sequence[RunCall]) -> Job.RunCalls
Job.RunCalls.node¶
property node: int
The Assistant node holding the batch.
Job.RunCalls.calls¶
property calls: list[RunCall]
The calls, in call order.
Job.Pending¶
class Pending(Job)
Calls are still out; nothing to do until they are answered.
Job.Pending.new¶
def __new__(cls) -> Job.Pending
Job.Rest¶
class Rest(Job)
The step is over and the cursor is at rest.
Job.Rest.new¶
def __new__(cls) -> Job.Rest
Next¶
class Next
Wait: ClassVar[Next]
Sample: ClassVar[Next]
RunTools: ClassVar[Next]
What a cursor's walk needs next.
RunCall¶
class RunCall
One call of a batch, handed out in Job.RunCalls to be run.
RunCall.id¶
property id: str
The call's id, as in the reply.
RunCall.tool¶
property tool: str
The name of the tool to run.
RunCall.args_raw¶
property args_raw: str
The arguments exactly as the model produced them.
SampleEnd¶
class SampleEnd
How a sample ended, as the driver saw it. Core decides what the tree records.
SampleEnd.Finished¶
class Finished(SampleEnd)
The provider finished the reply.
SampleEnd.Finished.new¶
def __new__(
cls,
stop: Stop,
reason: str | None = None,
meta: str | None = None,
) -> SampleEnd.Finished
SampleEnd.Finished.stop¶
property stop: Stop
Why the reply ended.
SampleEnd.Finished.reason¶
property reason: str | None
The provider's own finish string, or None.
SampleEnd.Finished.meta¶
property meta: str | None
What the response carried besides its parts, as JSON object text, or None.
SampleEnd.Failed¶
class Failed(SampleEnd)
The sample failed.
SampleEnd.Failed.new¶
def __new__(cls, error: str, meta: str | None = None) -> SampleEnd.Failed
SampleEnd.Failed.error¶
property error: str
What went wrong.
SampleEnd.Failed.meta¶
property meta: str | None
The failure's details as JSON object text, or None.
SampleEnd.Cancelled¶
class Cancelled(SampleEnd)
The cursor was aborted before the sample finished.
SampleEnd.Cancelled.new¶
def __new__(cls) -> SampleEnd.Cancelled
Session¶
class Session
One session: its tree, cursors, scratchpad, and every cursor's step. It does no IO of its
own: a program asks it for each cursor's next Job and gives back an Answer.
A call that changes the session hands its records to the store (when there is one) before
it returns, so a program never saves. Every call takes the session's one lock, so a
session may be shared across threads. A closed session raises Closed.
Session.create¶
@staticmethod
def create(
config: Config,
system: str,
now: int,
directory: str | PathLike[str] | None = None,
) -> Session
A new session with a Config root, a System node, and cursor 0 on
it. In directory (created if missing) when given, else in memory.
Session.load¶
@staticmethod
def load(directory: str | PathLike[str]) -> Session
Open the session in directory, taking its lease. Every cursor loads
with auto-step off, woken (load is a wake).
Session.read¶
@staticmethod
def read(directory: str | PathLike[str]) -> Session
The session in directory as a copy in memory, as of its last sync, taking no lease
and writing nothing (D18 section 7). It accepts changes and never saves them.
Session.fork¶
def fork(self, node: int, now: int, directory: str | PathLike[str] | None = None) -> Session
A new session holding a copy of walk(node) (D18 section 6): node i of the copy is
node i of the walk, with cursor 0 on its tip. In directory (created if missing)
when given, else in memory, written with one sync. NoSuchNode if node is absent.
Session.close¶
def close(self) -> None
Drop the store and release the lease without writing what is not yet
synced, as a crash would. Every later call raises Closed. A second
close is Closed too.
Session.tree¶
property tree: Tree
The session's nodes.
Session.input¶
def input(self, cursor: int, by: Author, text: str) -> int
Add an Input item for cursor, written by the author, and wake the cursor.
Returns the item's id. NoSuchCursor or CursorClosed if the cursor is not open.
Session.step¶
def step(self, cursor: int) -> None
Run one step of cursor whether or not auto-step is on, and leave auto-step as it is.
Busy if a step is already running.
Session.go_to¶
def go_to(self, cursor: int, to: int, client: str, now: int) -> bool
Move cursor to node to for the frontend named client, turn auto-step off and wake
the cursor. On a busy cursor the step is aborted and the move applies when it rests.
Returns whether the driver must cancel the effect in flight. NoSuchNode if to
is absent.
Session.set_auto¶
def set_auto(self, cursor: int, on: bool) -> None
Turn auto-step on or off for cursor; on wakes it.
Session.abort¶
def abort(self, cursor: int) -> bool
Stop cursor's step: auto-step goes off and no later phase runs. A running hook finishes.
Returns whether the driver must cancel the effect in flight.
Session.close_cursor¶
def close_cursor(self, cursor: int) -> None
Close a cursor at rest (Busy otherwise): the driver aborts and waits first.
Session.open¶
def open(self, at: int, by: Author, now: int) -> int
Open a new cursor at node at and wake it. Returns its id. NoSuchNode if at is absent.
Session.add_item¶
def add_item(self, to: int, data: ItemData) -> int
Add an item to cursor to's scratchpad and wake it. Returns the item's id.
Session.remove_item¶
def remove_item(self, id: int) -> None
Remove an item from the scratchpad. NoSuchItem if it is not there.
Session.append¶
def append(
self,
parent: int,
body: Body,
by: Author,
now: int,
copied_from: int | None = None,
derived_from: int | None = None,
) -> int
Append a node under parent without moving any cursor. copied_from names the node it
repeats verbatim, derived_from the node whose walk its content was computed from;
NoSuchNode if either is not a node.
Session.append_root¶
def append_root(self, config: Config, by: Author, now: int) -> int
Append a root Config (a detached tree) without moving any cursor.
Session.set_label¶
def set_label(self, label: str, cursor: int) -> None
Put label on cursor; a label already on another cursor moves. CursorClosed if the
cursor is closed.
Session.remove_label¶
def remove_label(self, label: str) -> None
Remove label. NoSuchLabel if it is not set.
Session.hook_move¶
def hook_move(self, cursor: int, to: int, by: Author, now: int) -> None
A cursor hook's move of its own cursor to node to. NotInHook unless a cursor hook
job is out for cursor.
Session.hook_write¶
def hook_write(
self,
cursor: int,
body: Body,
delivers: Sequence[int],
by: Author,
now: int,
copied_from: int | None = None,
derived_from: int | None = None,
) -> int
A cursor hook's write: append a node under the cursor's node, move onto it and consume
the delivers items. Returns the new node's id. NotInHook unless a cursor hook job is
out for cursor; NotPending if an item is not pending for it. copied_from and
derived_from as for append.
Session.hook_set_auto¶
def hook_set_auto(self, cursor: int, on: bool) -> None
A cursor hook's change of its own cursor's auto-step. NotInHook unless a cursor hook
job is out for cursor.
Session.next_job¶
def next_job(self, cursor: int) -> Job
The cursor's next job; Job.Rest when it has no step.
Session.answer¶
def answer(self, cursor: int, answer: Answer, now: int) -> None
Answer the job last handed out for cursor.
Session.cursors¶
def cursors(self) -> list[int]
Every open cursor, by id.
Session.closed¶
def closed(self) -> list[tuple[int, int]]
Each closed cursor with its last node, in id order.
Session.cursor¶
def cursor(self, cursor: int) -> CursorState
One cursor as it stands, all read under one lock.
Session.labels¶
def labels(self) -> list[tuple[str, int]]
Every label with its cursor, in string order.
Session.label¶
def label(self, label: str) -> int
The cursor label is on.
Session.take_notices¶
def take_notices(self) -> list[tuple[str, str]]
Drain the (client, text) messages to clients, oldest first.