1+ //
2+ // kinode.wit, copied from https://github.com/kinode-dao/kinode-wit/tree/v0.8
3+ //
4+
5+ package kinode : process @ 0.8.0;
6+
7+ interface standard {
8+ //
9+ // System types:
10+ //
11+
12+ // JSON is passed over WASM boundary as a string.
13+ type json = string ;
14+
15+ type node-id = string ;
16+
17+ // Context, like a message body, is a protocol-defined serialized byte
18+ // array. It is used when building a Request to save information that
19+ // will not be part of a Response, in order to more easily handle
20+ // ("contextualize") that Response.
21+ type context = list <u8 >;
22+
23+ record process-id {
24+ process-name : string ,
25+ package-name : string ,
26+ publisher-node : node-id ,
27+ }
28+
29+ record package-id {
30+ package-name : string ,
31+ publisher-node : node-id ,
32+ }
33+
34+ record address {
35+ node : node-id ,
36+ process : process-id ,
37+ }
38+
39+ record lazy-load-blob {
40+ mime : option <string >,
41+ bytes : list <u8 >,
42+ }
43+
44+ record request {
45+ // set in order to inherit lazy-load-blob from parent message, and if
46+ // expects-response is none, direct response to source of parent.
47+ // also carries forward certain aspects of parent message in kernel,
48+ // see documentation for formal spec and examples.
49+ inherit : bool ,
50+ // if some, request expects a response in the given number of seconds
51+ expects-response : option <u64 >,
52+ body : list <u8 >,
53+ metadata : option <json >,
54+ capabilities : list <capability >,
55+ // to grab lazy-load-blob, use get_blob()
56+ }
57+
58+ record response {
59+ inherit : bool ,
60+ body : list <u8 >,
61+ metadata : option <json >,
62+ capabilities : list <capability >,
63+ // to grab lazy-load-blob, use get_blob()
64+ }
65+
66+ // A message can be a request or a response. within a response, there is
67+ // a result which surfaces any error that happened because of a request.
68+ // A successful response will contain the context of the request it
69+ // matches, if any was set.
70+ variant message {
71+ request (request ),
72+ response (tuple <response , option <context >>),
73+ }
74+
75+ record capability {
76+ issuer : address ,
77+ params : json ,
78+ }
79+
80+ // On-exit is a setting that determines what happens when a process
81+ // panics, completes, or otherwise "ends". NOTE: requests should have
82+ // expects-response set to false, will always be set to that by kernel.
83+ variant on-exit {
84+ none ,
85+ restart ,
86+ requests (list <tuple <address , request , option <lazy-load-blob >>>),
87+ }
88+
89+ // Network errors come from trying to send a message to another node.
90+ // A message can fail by timing out, or by the node being entirely
91+ // unreachable (offline). In either case, the message is not delivered
92+ // and the process that sent it receives that message along with any
93+ // assigned context and/or lazy-load-blob, and is free to handle it as it
94+ // sees fit.
95+ record send-error {
96+ kind : send-error-kind ,
97+ target : address ,
98+ message : message ,
99+ lazy-load-blob : option <lazy-load-blob >,
100+ }
101+
102+ enum send-error-kind {
103+ offline ,
104+ timeout ,
105+ }
106+
107+ enum spawn-error {
108+ name-taken ,
109+ no-file-at-path ,
110+ }
111+
112+ //
113+ // System utils:
114+ //
115+
116+ print-to-terminal : func (verbosity : u8 , message : string );
117+
118+ //
119+ // Process management:
120+ //
121+
122+ set-on-exit : func (on-exit : on-exit );
123+
124+ get-on-exit : func () -> on-exit ;
125+
126+ get-state : func () -> option <list <u8 >>;
127+
128+ set-state : func (bytes : list <u8 >);
129+
130+ clear-state : func ();
131+
132+ spawn : func (
133+ name : option <string >,
134+ wasm-path : string , // must be located within package's drive
135+ on-exit : on-exit ,
136+ request-capabilities : list <capability >,
137+ // note that we are restricting granting to just messaging the
138+ // newly spawned process
139+ grant-capabilities : list <process-id >,
140+ public : bool
141+ ) -> result <process-id , spawn-error >;
142+
143+ //
144+ // Capabilities management:
145+ //
146+
147+ // Saves the capabilities to persisted process state.
148+ save-capabilities : func (caps : list <capability >);
149+
150+ // Deletes the capabilities from persisted process state.
151+ drop-capabilities : func (caps : list <capability >);
152+
153+ // Gets all capabilities from persisted process state.
154+ our-capabilities : func () -> list <capability >;
155+
156+ //
157+ // Message I/O:
158+ //
159+
160+ // Ingest next message when it arrives along with its source.
161+ // Almost all long-running processes will call this in a loop.
162+ receive : func () ->
163+ result<tuple<address, message>, tuple<send-error, option<context>>>;
164+
165+ // Gets lazy-load-blob, if any, of the message we most recently received.
166+ get-blob : func () -> option <lazy-load-blob >;
167+
168+ // Send message(s) to target(s).
169+ send-request : func (
170+ target : address ,
171+ request : request ,
172+ context : option <context >,
173+ lazy-load-blob : option <lazy-load-blob >
174+ );
175+
176+ send-requests : func (
177+ requests : list <tuple <address ,
178+ request ,
179+ option <context >,
180+ option <lazy-load-blob >>>
181+ );
182+
183+ send-response : func (
184+ response : response ,
185+ lazy-load-blob : option <lazy-load-blob >
186+ );
187+
188+ // Send a single request, then block (internally) until its response. The
189+ // type returned is Message but will always contain Response.
190+ send-and-await-response : func (
191+ target : address ,
192+ request : request ,
193+ lazy-load-blob : option <lazy-load-blob >
194+ ) -> result <tuple <address , message >, send-error >;
195+ }
196+
197+ world lib {
198+ import standard ;
199+ }
200+
201+ world process-v0 {
202+ include lib ;
203+
204+ export init : func (our : string );
205+ }
0 commit comments