Skip to content

Commit 22eeae9

Browse files
committed
build: generate agentos actor action types
1 parent 08c3935 commit 22eeae9

7 files changed

Lines changed: 234 additions & 256 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ target/
1515
# TypeScript
1616
*.tsbuildinfo
1717
dist/
18+
packages/agentos/src/generated/
1819

1920
# IDE
2021
.vscode/

crates/agentos-actor-plugin/src/actions/mod.rs

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ pub mod contract {
237237
pub ts_signature: &'static str,
238238
}
239239

240+
pub const GENERATED_ACTOR_ACTIONS_PATH: &str =
241+
"packages/agentos/src/generated/actor-actions.generated.ts";
242+
240243
pub const ACTION_CONTRACTS: &[ActionContract] = &[
241244
ActionContract {
242245
name: "readFile",
@@ -517,6 +520,141 @@ pub mod contract {
517520
},
518521
];
519522

523+
pub fn render_actor_actions_ts() -> String {
524+
use std::fmt::Write as _;
525+
526+
let mut out = String::from(ACTOR_ACTIONS_TS_PREAMBLE);
527+
for action in ACTION_CONTRACTS {
528+
writeln!(&mut out, "\t{}", action.ts_signature)
529+
.expect("writing generated actor actions to string");
530+
}
531+
out.push_str("};\n");
532+
out
533+
}
534+
535+
const ACTOR_ACTIONS_TS_PREAMBLE: &str = r#"// @generated by agentos-actor-plugin. Do not edit.
536+
// This file is generated locally and is intentionally not committed to Git.
537+
// Run `pnpm --dir packages/agentos generate:actions` to regenerate it.
538+
import type {
539+
ExecResult,
540+
PermissionReply,
541+
ProcessInfo,
542+
ProcessTreeNode,
543+
SpawnedProcessInfo,
544+
VirtualStat,
545+
} from "@rivet-dev/agentos-core";
546+
import type {
547+
PersistedSessionEvent,
548+
PersistedSessionRecord,
549+
PromptResult,
550+
SerializableCronJobInfo,
551+
SerializableCronJobOptions,
552+
} from "../types.js";
553+
554+
// The leading actor context arg; stripped from the client-facing method.
555+
// biome-ignore lint/suspicious/noExplicitAny: ctx is server-side only and never reaches the typed client surface.
556+
type Ctx = any;
557+
558+
export interface DirEntry {
559+
path: string;
560+
type: "file" | "directory" | "symlink";
561+
size: number;
562+
}
563+
564+
export interface ReaddirEntry {
565+
name: string;
566+
isDirectory: boolean;
567+
isSymbolicLink: boolean;
568+
}
569+
570+
export interface SpawnedProcess {
571+
pid: number;
572+
}
573+
574+
export interface ExecActionOptions {
575+
env?: Record<string, string>;
576+
cwd?: string;
577+
}
578+
579+
export interface SpawnActionOptions {
580+
env?: Record<string, string>;
581+
cwd?: string;
582+
streamStdin?: boolean;
583+
}
584+
585+
export interface ScheduledCronJob {
586+
id: string;
587+
}
588+
589+
export interface VmFetchOptions {
590+
method?: string;
591+
headers?: Record<string, string>;
592+
body?: string | Uint8Array;
593+
}
594+
595+
export interface VmFetchResponse {
596+
status: number;
597+
statusText: string;
598+
headers: Record<string, string>;
599+
body: Uint8Array;
600+
}
601+
602+
export interface CreateSessionOptions {
603+
cwd?: string;
604+
env?: Record<string, string>;
605+
skipOsInstructions?: boolean;
606+
additionalInstructions?: string;
607+
}
608+
609+
export interface SignedPreviewUrl {
610+
path: string;
611+
token: string;
612+
port: number;
613+
expiresAt: number;
614+
}
615+
616+
export interface OpenShellActionOptions {
617+
command?: string;
618+
args?: string[];
619+
env?: Record<string, string>;
620+
cwd?: string;
621+
cols?: number;
622+
rows?: number;
623+
}
624+
625+
export interface OpenShellResult {
626+
shellId: string;
627+
}
628+
629+
export interface WriteFileResult {
630+
path: string;
631+
success: boolean;
632+
error?: string;
633+
}
634+
635+
export interface ReadFileResult {
636+
path: string;
637+
content?: Uint8Array;
638+
error?: string;
639+
}
640+
641+
export interface MountInfo {
642+
path: string;
643+
kind: "host_dir" | "s3" | "google_drive" | "sandbox_agent";
644+
config: unknown;
645+
readOnly: boolean;
646+
}
647+
648+
export interface SoftwareInfo {
649+
package: string;
650+
kind: "wasm-commands" | "agent" | "tool";
651+
version: string | null;
652+
commands: string[];
653+
}
654+
655+
export type AgentOsActions = {
656+
"#;
657+
520658
pub fn decode_action_args(name: &str, args: &[u8]) -> Result<()> {
521659
match name {
522660
"readFile" => super::decode_as::<(String,)>(args).map(|_| ()),
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use std::path::PathBuf;
2+
3+
use agentos_actor_plugin::actions::contract;
4+
use anyhow::{bail, Context as _, Result};
5+
6+
fn main() -> Result<()> {
7+
let mut args = std::env::args().skip(1);
8+
let command = args.next();
9+
if args.next().is_some() {
10+
bail!("usage: generate-ts-actions [--write|--check]");
11+
}
12+
13+
let rendered = contract::render_actor_actions_ts();
14+
match command.as_deref() {
15+
Some("--write") => {
16+
let path = generated_path();
17+
let parent = path
18+
.parent()
19+
.context("generated actor actions path must have a parent")?;
20+
std::fs::create_dir_all(parent)
21+
.with_context(|| format!("create {}", parent.display()))?;
22+
std::fs::write(&path, rendered).with_context(|| format!("write {}", path.display()))?;
23+
}
24+
Some("--check") => {
25+
let path = generated_path();
26+
let current = std::fs::read_to_string(&path)
27+
.with_context(|| format!("read {}", path.display()))?;
28+
if current != rendered {
29+
bail!(
30+
"{} is stale; run `pnpm --dir packages/agentos generate:actions`",
31+
contract::GENERATED_ACTOR_ACTIONS_PATH
32+
);
33+
}
34+
}
35+
None => {
36+
print!("{rendered}");
37+
}
38+
Some(other) => {
39+
bail!("unknown argument {other}; usage: generate-ts-actions [--write|--check]")
40+
}
41+
}
42+
43+
Ok(())
44+
}
45+
46+
fn generated_path() -> PathBuf {
47+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
48+
manifest_dir
49+
.join("../..")
50+
.join(contract::GENERATED_ACTOR_ACTIONS_PATH)
51+
}

crates/agentos-actor-plugin/tests/action_contract.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ fn create_session_reply_is_bare_string_regression() {
165165

166166
#[test]
167167
fn ts_action_interface_matches_rust_contract_fixture() {
168-
let ts = include_str!("../../../packages/agentos/src/actor-actions.ts");
169-
let normalized_ts = normalize_ws(ts);
168+
let ts = contract::render_actor_actions_ts();
169+
let normalized_ts = normalize_ws(&ts);
170170

171171
for action in ACTION_CONTRACTS {
172172
let signature = normalize_ws(action.ts_signature);
173173
assert!(
174174
normalized_ts.contains(&signature),
175-
"packages/agentos/src/actor-actions.ts signature drifted for {}.\nexpected snippet: {}",
175+
"generated actor-actions signature drifted for {}.\nexpected snippet: {}",
176176
action.name,
177177
action.ts_signature
178178
);
@@ -197,7 +197,7 @@ fn ts_event_interface_matches_rust_contract_fixture() {
197197

198198
#[test]
199199
fn ts_dto_field_names_match_rust_contract_fixture() {
200-
let actor_actions = include_str!("../../../packages/agentos/src/actor-actions.ts");
200+
let actor_actions = contract::render_actor_actions_ts();
201201
let actor_types = include_str!("../../../packages/agentos/src/types.ts");
202202
let core_agent_os = include_str!("../../../packages/core/src/agent-os.ts");
203203
let core_runtime = include_str!("../../../packages/core/src/runtime.ts");
@@ -260,20 +260,20 @@ fn ts_dto_field_names_match_rust_contract_fixture() {
260260
),
261261
(
262262
"VmFetchResponse",
263-
"packages/agentos/src/actor-actions.ts",
264-
actor_actions,
263+
"generated actor-actions",
264+
&actor_actions,
265265
"export interface VmFetchResponse { status: number; statusText: string; headers: Record<string, string>; body: Uint8Array; }",
266266
),
267267
(
268268
"WriteFileResult",
269-
"packages/agentos/src/actor-actions.ts",
270-
actor_actions,
269+
"generated actor-actions",
270+
&actor_actions,
271271
"export interface WriteFileResult { path: string; success: boolean; error?: string; }",
272272
),
273273
(
274274
"ReadFileResult",
275-
"packages/agentos/src/actor-actions.ts",
276-
actor_actions,
275+
"generated actor-actions",
276+
&actor_actions,
277277
"export interface ReadFileResult { path: string; content?: Uint8Array; error?: string; }",
278278
),
279279
(

packages/agentos/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@
4747
"node": ">=22.0.0"
4848
},
4949
"scripts": {
50-
"build": "pnpm build:actor && pnpm build:tabs",
50+
"generate:actions": "cargo run --quiet -p agentos-actor-plugin --bin generate-ts-actions -- --write",
51+
"build": "pnpm generate:actions && pnpm build:actor && pnpm build:tabs",
5152
"build:actor": "tsup src/index.ts src/client.ts src/react.ts",
5253
"build:tabs": "vite build --config vite.tabs.config.ts",
53-
"check-types": "tsc --noEmit",
54-
"test": "vitest run"
54+
"check-types": "pnpm generate:actions && tsc --noEmit",
55+
"test": "pnpm generate:actions && vitest run"
5556
},
5657
"dependencies": {
5758
"@agentos-software/common": "workspace:*",

0 commit comments

Comments
 (0)