1
1
//
2
- // kinode.wit, copied from https://github.com/kinode-dao/kinode-wit/tree/v0.8
2
+ // kinode.wit, copied from https://github.com/kinode-dao/kinode-wit
3
+ // https://raw.githubusercontent.com/kinode-dao/kinode-wit/v1.0.0/kinode.wit
3
4
//
4
5
5
- package kinode : process @ 0.8 .0;
6
+ package kinode : process @ 1.0 .0;
6
7
7
8
interface standard {
8
- //
9
- // System types:
10
- //
11
9
12
- // JSON is passed over WASM boundary as a string.
10
+ // ˗ˏˋ ♡ ˎˊ˗
11
+ // System Types
12
+ // ˗ˏˋ ♡ ˎˊ˗
13
+
14
+ /// JSON is passed over Wasm boundary as a string.
13
15
type json = string ;
14
16
17
+ /// In types passed from kernel, node-id will be a valid Kimap entry.
15
18
type node-id = string ;
16
19
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.
20
+ /// Context, like a message body, is a protocol-defined serialized byte
21
+ /// array. It is used when building a Request to save information that
22
+ /// will not be part of a Response, in order to more easily handle
23
+ /// ("contextualize") that Response.
21
24
type context = list <u8 >;
22
25
23
26
record process-id {
@@ -45,7 +48,8 @@ interface standard {
45
48
// set in order to inherit lazy-load-blob from parent message, and if
46
49
// expects-response is none, direct response to source of parent.
47
50
// also carries forward certain aspects of parent message in kernel,
48
- // see documentation for formal spec and examples.
51
+ // see documentation for formal spec and examples:
52
+ // https://docs.rs/kinode_process_lib/latest/kinode_process_lib/struct.Request.html
49
53
inherit : bool ,
50
54
// if some, request expects a response in the given number of seconds
51
55
expects-response : option <u64 >,
@@ -63,10 +67,10 @@ interface standard {
63
67
// to grab lazy-load-blob, use get_blob()
64
68
}
65
69
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
+ /// A message can be a request or a response. Within a response, there is
71
+ /// a result which surfaces any error that happened because of a request.
72
+ /// A successful response will contain the context of the request it
73
+ /// matches, if any was set.
70
74
variant message {
71
75
request (request ),
72
76
response (tuple <response , option <context >>),
@@ -77,21 +81,24 @@ interface standard {
77
81
params : json ,
78
82
}
79
83
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.
84
+ /// On-exit is a setting that determines what happens when a process
85
+ /// panics, completes, or otherwise "ends".
86
+ /// NOTE: requests will always have expects-response set to false by kernel.
83
87
variant on-exit {
84
88
none ,
85
89
restart ,
86
90
requests (list <tuple <address , request , option <lazy-load-blob >>>),
87
91
}
88
92
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.
93
+ /// Send errors come from trying to send a message to another process,
94
+ /// either locally or on another node.
95
+ /// A message can fail by timing out, or by the node being entirely
96
+ /// unreachable (offline or can't be found in PKI). In either case,
97
+ /// the message is not delivered and the process that sent it receives
98
+ /// that message back along with any assigned context and/or lazy-load-blob,
99
+ /// and is free to handle it as it sees fit.
100
+ /// In the local case, only timeout errors are possible and also cover the case
101
+ /// in which a process is not running or does not exist.
95
102
record send-error {
96
103
kind : send-error-kind ,
97
104
target : address ,
@@ -109,84 +116,101 @@ interface standard {
109
116
no-file-at-path ,
110
117
}
111
118
112
- //
113
- // System utils:
114
- //
119
+ // ˗ˏˋ ♡ ˎˊ˗
120
+ // System Utils
121
+ // ˗ˏˋ ♡ ˎˊ˗
115
122
123
+ /// Prints to the terminal at a given verbosity level.
124
+ /// Higher verbosity levels print more information.
125
+ /// Level 0 is always printed -- use sparingly.
116
126
print-to-terminal : func (verbosity : u8 , message : string );
117
127
118
- //
119
- // Process management:
120
- //
128
+ /// Returns the address of the process.
129
+ our : func () -> address ;
121
130
122
- set-on-exit : func (on-exit : on-exit );
131
+ // ˗ˏˋ ♡ ˎˊ˗
132
+ // Process Management
133
+ // ˗ˏˋ ♡ ˎˊ˗
123
134
124
135
get-on-exit : func () -> on-exit ;
125
136
137
+ set-on-exit : func (on-exit : on-exit );
138
+
126
139
get-state : func () -> option <list <u8 >>;
127
140
128
141
set-state : func (bytes : list <u8 >);
129
142
130
143
clear-state : func ();
131
144
132
145
spawn : func (
146
+ // name is optional. if not provided, name will be a random u64.
133
147
name : option <string >,
134
- wasm-path : string , // must be located within package's drive
148
+ // wasm-path must be located within package's drive
149
+ wasm-path : string ,
135
150
on-exit : on-exit ,
151
+ // requested capabilities must be owned by the caller
136
152
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 >,
153
+ // granted capabilities will be generated by the child process
154
+ // and handed out to the indicated process-id.
155
+ grant-capabilities : list <tuple < process-id , json > >,
140
156
public : bool
141
157
) -> result <process-id , spawn-error >;
142
158
143
- //
144
- // Capabilities management:
145
- //
159
+ // ˗ˏˋ ♡ ˎˊ˗
160
+ // Capabilities Management
161
+ // ˗ˏˋ ♡ ˎˊ˗
146
162
147
- // Saves the capabilities to persisted process state.
163
+ /// Saves the capabilities to persisted process state.
148
164
save-capabilities : func (caps : list <capability >);
149
165
150
- // Deletes the capabilities from persisted process state.
166
+ /// Deletes the capabilities from persisted process state.
151
167
drop-capabilities : func (caps : list <capability >);
152
168
153
- // Gets all capabilities from persisted process state.
169
+ /// Gets all capabilities from persisted process state.
154
170
our-capabilities : func () -> list <capability >;
155
171
156
- //
157
- // Message I/O:
158
- //
172
+ // ˗ˏˋ ♡ ˎˊ˗
173
+ // Message I/O
174
+ // ˗ˏˋ ♡ ˎˊ˗
159
175
160
- // Ingest next message when it arrives along with its source.
161
- // Almost all long-running processes will call this in a loop.
176
+ /// Ingest next message when it arrives along with its source.
177
+ /// Almost all long-running processes will call this in a loop.
162
178
receive : func () ->
163
179
result<tuple<address, message>, tuple<send-error, option<context>>>;
164
180
165
- // Gets lazy-load-blob, if any, of the message we most recently received.
181
+ /// Returns whether or not the current message has a blob.
182
+ has-blob : func () -> bool ;
183
+
184
+ /// Returns the blob of the current message, if any.
166
185
get-blob : func () -> option <lazy-load-blob >;
167
186
168
- // Send message(s) to target(s).
187
+ /// Returns the last blob this process received.
188
+ last-blob : func () -> option <lazy-load-blob >;
189
+
190
+ /// Send request to target.
169
191
send-request : func (
170
192
target : address ,
171
193
request : request ,
172
194
context : option <context >,
173
195
lazy-load-blob : option <lazy-load-blob >
174
196
);
175
197
198
+ /// Send requests to targets.
176
199
send-requests : func (
177
200
requests : list <tuple <address ,
178
201
request ,
179
202
option <context >,
180
203
option <lazy-load-blob >>>
181
204
);
182
205
206
+ /// Send response to the request currently being handled.
183
207
send-response : func (
184
208
response : response ,
185
209
lazy-load-blob : option <lazy-load-blob >
186
210
);
187
211
188
- // Send a single request, then block (internally) until its response. The
189
- // type returned is Message but will always contain Response.
212
+ /// Send a single request, then block (internally) until its response. The
213
+ /// type returned is Message but will always contain Response.
190
214
send-and-await-response : func (
191
215
target : address ,
192
216
request : request ,
@@ -198,7 +222,7 @@ world lib {
198
222
import standard ;
199
223
}
200
224
201
- world process-v0 {
225
+ world process-v1 {
202
226
include lib ;
203
227
204
228
export init : func (our : string );
0 commit comments