@@ -28,10 +28,13 @@ import type {
2828 ToolInvokeResult ,
2929} from "./types.js" ;
3030
31+ // High-level OpenClaw SDK client. Namespaces below translate friendly SDK calls
32+ // into current Gateway RPC methods and normalize event streams for consumers.
3133const MAX_REPLAY_RUNS = 100 ;
3234const MAX_REPLAY_EVENTS_PER_RUN = 500 ;
3335const MAX_NORMALIZED_REPLAY_EVENTS = 2000 ;
3436
37+ /** Connection and transport options for the OpenClaw SDK client. */
3538export type OpenClawOptions = {
3639 gateway ?: "auto" | ( string & { } ) ;
3740 url ?: string ;
@@ -52,6 +55,8 @@ function resolveGatewayUrl(options: OpenClawOptions): string | undefined {
5255}
5356
5457function runStatusFromWaitPayload ( payload : unknown ) : RunResult [ "status" ] {
58+ // Gateway wait payloads come from several runtime paths. Preserve timeout vs
59+ // cancellation semantics from metadata instead of trusting one status field.
5560 const record =
5661 typeof payload === "object" && payload !== null
5762 ? ( payload as Record < string , unknown > & { aborted ?: unknown ; status ?: unknown } )
@@ -300,6 +305,7 @@ function normalizeChatProjectionEvent(
300305 } ;
301306}
302307
308+ /** Root SDK client with namespaces for agents, sessions, runs, and gateway APIs. */
303309export class OpenClaw {
304310 readonly agents : AgentsNamespace ;
305311 readonly sessions : SessionsNamespace ;
@@ -541,6 +547,7 @@ export class OpenClaw {
541547 }
542548}
543549
550+ /** Agent-scoped helper for runs and identity lookups. */
544551export class Agent {
545552 constructor (
546553 private readonly client : OpenClaw ,
@@ -561,6 +568,7 @@ export class Agent {
561568 }
562569}
563570
571+ /** Run handle for streaming events, waiting, and cancellation. */
564572export class Run {
565573 constructor (
566574 private readonly client : OpenClaw ,
@@ -607,6 +615,7 @@ export class Run {
607615 }
608616}
609617
618+ /** Session handle for sending messages and session-scoped mutations. */
610619export class Session {
611620 constructor (
612621 private readonly client : OpenClaw ,
@@ -642,6 +651,7 @@ export class Session {
642651 }
643652}
644653
654+ /** Agent management namespace. */
645655export class AgentsNamespace {
646656 constructor ( private readonly client : OpenClaw ) { }
647657
@@ -666,6 +676,7 @@ export class AgentsNamespace {
666676 }
667677}
668678
679+ /** Session management namespace. */
669680export class SessionsNamespace {
670681 constructor ( private readonly client : OpenClaw ) { }
671682
@@ -698,6 +709,7 @@ export class SessionsNamespace {
698709 }
699710}
700711
712+ /** Run creation and lifecycle namespace. */
701713export class RunsNamespace {
702714 constructor ( private readonly client : OpenClaw ) { }
703715
@@ -746,6 +758,7 @@ class RpcNamespace {
746758 }
747759}
748760
761+ /** Task query and cancellation namespace. */
749762export class TasksNamespace extends RpcNamespace {
750763 constructor ( client : OpenClaw ) {
751764 super ( client , "tasks" ) ;
@@ -767,6 +780,7 @@ export class TasksNamespace extends RpcNamespace {
767780 }
768781}
769782
783+ /** Model catalog and auth status namespace. */
770784export class ModelsNamespace extends RpcNamespace {
771785 constructor ( client : OpenClaw ) {
772786 super ( client , "models" ) ;
@@ -781,6 +795,7 @@ export class ModelsNamespace extends RpcNamespace {
781795 }
782796}
783797
798+ /** Tool catalog, effective tool, and direct invocation namespace. */
784799export class ToolsNamespace extends RpcNamespace {
785800 constructor ( client : OpenClaw ) {
786801 super ( client , "tools" ) ;
@@ -806,6 +821,7 @@ export class ToolsNamespace extends RpcNamespace {
806821 }
807822}
808823
824+ /** Run/session artifact listing and download namespace. */
809825export class ArtifactsNamespace extends RpcNamespace {
810826 constructor ( client : OpenClaw ) {
811827 super ( client , "artifacts" ) ;
@@ -830,6 +846,7 @@ export class ArtifactsNamespace extends RpcNamespace {
830846 }
831847}
832848
849+ /** Approval request listing and response namespace. */
833850export class ApprovalsNamespace {
834851 constructor ( private readonly client : OpenClaw ) { }
835852
@@ -842,6 +859,7 @@ export class ApprovalsNamespace {
842859 }
843860}
844861
862+ /** Environment discovery namespace. */
845863export class EnvironmentsNamespace extends RpcNamespace {
846864 constructor ( client : OpenClaw ) {
847865 super ( client , "environments" ) ;
0 commit comments