interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-switchboard / src / runner.rs

73 lines · 2311 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Runners start one job on one account. This cut ships only the scripted
17//! fake; adapters for the real programs come later and must keep this shape.
18
19use crate::account::{Account, AccountId};
20use crate::job::Job;
21use std::collections::{BTreeMap, VecDeque};
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24#[non_exhaustive]
25pub enum RunResult {
26 Output(String),
27 /// The account hit its usage limit. `resets_at` is Unix seconds when the
28 /// program said when it refills, else `None`.
29 LimitHit {
30 resets_at: Option<u64>,
31 },
32}
33
34pub trait Runner {
35 fn run(&mut self, account: &Account, job: &Job, prompt: &str) -> RunResult;
36}
37
38/// Scripted runner for tests: answers per account from a queue, then falls
39/// back to a canned output. Records every call.
40#[derive(Debug, Default)]
41pub struct FakeRunner {
42 scripts: BTreeMap<AccountId, VecDeque<RunResult>>,
43 pub calls: Vec<AccountId>,
44}
45
46impl FakeRunner {
47 pub fn new() -> Self {
48 FakeRunner::default()
49 }
50
51 /// Queue the next answer for `id`.
52 pub fn push(&mut self, id: &AccountId, result: RunResult) -> &mut Self {
53 self.scripts
54 .entry(id.clone())
55 .or_default()
56 .push_back(result);
57 self
58 }
59}
60
61impl Runner for FakeRunner {
62 fn run(&mut self, account: &Account, _job: &Job, prompt: &str) -> RunResult {
63 self.calls.push(account.id.clone());
64 match self
65 .scripts
66 .get_mut(&account.id)
67 .and_then(|q| q.pop_front())
68 {
69 Some(r) => r,
70 None => RunResult::Output(format!("fake output from {}: {prompt}", account.id)),
71 }
72 }
73}