@otonoma/paranet-client 2.14.0 → 2.15.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,353 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * This file was automatically generated by json-schema-to-typescript.
4
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
- * and run json-schema-to-typescript to regenerate this file.
6
- */
7
-
8
- /**
9
- * `PncpPacket` wraps all core PNCP message variants.
10
- */
11
- export type PncpPacket =
12
- | {
13
- type: "request";
14
- body: PncpRequest;
15
- [k: string]: any;
16
- }
17
- | {
18
- type: "message";
19
- body: PncpMessage;
20
- [k: string]: any;
21
- };
22
- export type ConversationId = string;
23
- export type EntityReq = string;
24
- export type EntityId = string;
25
- export type PncpMessageBody =
26
- | {
27
- type: "response";
28
- body: PncpDataMessage;
29
- [k: string]: any;
30
- }
31
- | {
32
- type: "status";
33
- body: PncpDataMessage;
34
- [k: string]: any;
35
- }
36
- | {
37
- type: "cancel";
38
- body: PncpDataMessage;
39
- [k: string]: any;
40
- }
41
- | {
42
- type: "question";
43
- body: PncpQuestionMessage;
44
- [k: string]: any;
45
- }
46
- | {
47
- type: "answer";
48
- body: PncpAnswerMessage;
49
- [k: string]: any;
50
- }
51
- | {
52
- type: "error";
53
- body: PncpDataMessage;
54
- [k: string]: any;
55
- };
56
- /**
57
- * Determines the match strategy used by the paranet.
58
- */
59
- export type SkillMatchStrategy = "BEST" | "FIRST" | "STRICT";
60
- export type Id = string;
61
- export type ResponseKind = "MATCH" | "BROADCAST" | "UNMATCHED" | "NETWORKED" | "DATA";
62
- /**
63
- * Represents all message types that can be sent from the paranet to an actor.
64
- */
65
- export type PncpCallback =
66
- | {
67
- type: "skill";
68
- body: PncpRequestCallback;
69
- [k: string]: any;
70
- }
71
- | {
72
- type: "message";
73
- body: PncpMessageCallback;
74
- [k: string]: any;
75
- };
76
- export type SchemaRef = {
77
- /**
78
- * Allowed to be empty/not present.
79
- */
80
- optional?: boolean;
81
- /**
82
- * Indicates that the field should be redacted from the ledger as well as observers.
83
- */
84
- redacted?: boolean;
85
- /**
86
- * Indicates that the object can be an array of values.
87
- */
88
- repeated?: boolean;
89
- [k: string]: any;
90
- } & SchemaRef1;
91
- export type SchemaRef1 =
92
- | {
93
- type: "ref";
94
- value: string;
95
- [k: string]: any;
96
- }
97
- | {
98
- type: "object";
99
- value: {
100
- [k: string]: SchemaRef;
101
- };
102
- [k: string]: any;
103
- };
104
- export type SchemaRefValue =
105
- | {
106
- type: "ref";
107
- value: string;
108
- [k: string]: any;
109
- }
110
- | {
111
- type: "object";
112
- value: {
113
- [k: string]: SchemaRef;
114
- };
115
- [k: string]: any;
116
- };
117
-
118
- /**
119
- * A common root type. This type is itself not used, but it will allow schema resolution to
120
- * properly find all of the types in one place.
121
- */
122
- export interface ParanetTypes {
123
- pncp: PncpPacket;
124
- strategy: SkillMatchStrategy;
125
- response: MessageResponse;
126
- callback: PncpCallback;
127
- schema_ref: SchemaRef;
128
- schema_ref_value: SchemaRefValue;
129
- [k: string]: any;
130
- }
131
- /**
132
- * Represents a "skill message" request. All conversations are initiated via a skill request.
133
- */
134
- export interface PncpRequest {
135
- body: PncpSkillMessage;
136
- /**
137
- * Information provided on callback to the actor when a response is received.
138
- */
139
- callback?: {
140
- [k: string]: any;
141
- };
142
- /**
143
- * The parent conversation ID, if one exists.
144
- */
145
- parentId?: ConversationId | null;
146
- /**
147
- * Identifying information about who is making the call.
148
- */
149
- author: string;
150
- /**
151
- * Specifies the match strategy.
152
- */
153
- matchStrategy?: "BEST" | "FIRST" | "STRICT";
154
- /**
155
- * Version request spec for the (subject, action) pair.
156
- */
157
- versionReq?: string | null;
158
- /**
159
- * When specified, the particular actor is called if the skill matches.
160
- */
161
- targetActorId?: EntityReq | null;
162
- /**
163
- * An arbitrary key that is allowed to be set and provided on further messages from mediums.
164
- */
165
- key?: {
166
- [k: string]: any;
167
- };
168
- /**
169
- * ID of the medium that made the request.
170
- */
171
- mediumInfo?: PncpRequestMediumInfo | null;
172
- /**
173
- * If this is true, a match is required to be made upon the initial request. If it is false, the
174
- * broker can store the message and conversation in an unmatched state and rematch it at a later
175
- * time based on later actor availability.
176
- * If the corresponding skill is a `Broadcast` skill, this field is not considered as they are
177
- * not matched.
178
- */
179
- mustMatch?: boolean;
180
- /**
181
- * If this is true, then this request should use the provided actor lock.
182
- */
183
- useLock?: boolean;
184
- /**
185
- * If this is true, then the request can use open networking and search other nodes open nodes on the
186
- * network for a fulfiller if this node doesn't know of a fulfiller.
187
- */
188
- allowOpenMatch?: boolean;
189
- [k: string]: any;
190
- }
191
- /**
192
- * The core body to the request.
193
- */
194
- export interface PncpSkillMessage {
195
- /**
196
- * Subject of the request.
197
- */
198
- subject: string;
199
- /**
200
- * Action of the request.
201
- */
202
- action: string;
203
- body: any;
204
- taint?: string | null;
205
- [k: string]: any;
206
- }
207
- export interface PncpRequestMediumInfo {
208
- id: EntityId;
209
- userInfo: any;
210
- [k: string]: any;
211
- }
212
- /**
213
- * PNCP Message. Messages are a variety of types of data sent within a conversation.
214
- */
215
- export interface PncpMessage {
216
- id: ConversationId;
217
- message: PncpMessageBody;
218
- taint?: string | null;
219
- [k: string]: any;
220
- }
221
- /**
222
- * A simple data packet.
223
- */
224
- export interface PncpDataMessage {
225
- data: any;
226
- [k: string]: any;
227
- }
228
- /**
229
- * A PNCP packet for question messages.
230
- */
231
- export interface PncpQuestionMessage {
232
- /**
233
- * The id of the question.
234
- */
235
- id: string;
236
- data: any;
237
- callback?: {
238
- [k: string]: any;
239
- };
240
- [k: string]: any;
241
- }
242
- /**
243
- * A PNCP packet for answer messages.
244
- */
245
- export interface PncpAnswerMessage {
246
- /**
247
- * The ID of the question message being replied to.
248
- */
249
- replyTo: string;
250
- data: any;
251
- [k: string]: any;
252
- }
253
- /**
254
- * Response generated from the paranet in response to an actor making a "MessageRequest".
255
- */
256
- export interface MessageResponse {
257
- id: ConversationId;
258
- message_id: Id;
259
- time_created: string;
260
- /**
261
- * Current state of the conversation after this request was made.
262
- */
263
- state: ("IN_PROGRESS" | "COMPLETED" | "ERRORED" | "CANCELED" | "UNMATCHED") | "NETWORKING";
264
- kind: ResponseKind;
265
- matched_id?: EntityId | null;
266
- [k: string]: any;
267
- }
268
- /**
269
- * Skill request sent to an actor from the paranet.
270
- */
271
- export interface PncpRequestCallback {
272
- id: ConversationId;
273
- messageId: Id;
274
- body: PncpSkillMessage1;
275
- /**
276
- * The parent conversation ID, if one exists.
277
- */
278
- parentId?: ConversationId | null;
279
- timeCreated: string;
280
- authorId: EntityId;
281
- /**
282
- * The actor ID of the receiving actor. This is optional as some skill matches have no targets
283
- * in the case of a broadcast skill message type.
284
- */
285
- targetActorId?: EntityId | null;
286
- parameters?: ParameterData;
287
- /**
288
- * See pncp.proto CallbackFlags
289
- */
290
- flags?: number;
291
- [k: string]: any;
292
- }
293
- export interface PncpSkillMessage1 {
294
- /**
295
- * Subject of the request.
296
- */
297
- subject: string;
298
- /**
299
- * Action of the request.
300
- */
301
- action: string;
302
- body: any;
303
- taint?: string | null;
304
- [k: string]: any;
305
- }
306
- /**
307
- * Additional parameters included with the request. These come from actor/skill templates.
308
- */
309
- export interface ParameterData {
310
- /**
311
- * Default to empty values.
312
- */
313
- provider?: {
314
- [k: string]: any;
315
- };
316
- skill?: {
317
- [k: string]: any;
318
- };
319
- medium?: any;
320
- [k: string]: any;
321
- }
322
- /**
323
- * In the flow of paranet messages, this is logically a "response" message. The `data` field comes
324
- * from the targeted actor whereas others are contextual from the paranet.
325
- */
326
- export interface PncpMessageCallback {
327
- /**
328
- * The identifier for the target actor (initiator of the original conversation, typically).
329
- */
330
- id: string;
331
- messageId: Id;
332
- timeCreated: string;
333
- /**
334
- * Key provided from response to initial call.
335
- */
336
- key?: {
337
- [k: string]: any;
338
- };
339
- message: PncpMessage;
340
- params?: any;
341
- /**
342
- * Callback information if any was provided in the conversation.
343
- */
344
- callback?: {
345
- [k: string]: any;
346
- };
347
- medium?: any;
348
- /**
349
- * Any change to the conversation state will be present here.
350
- */
351
- conversationState: ("IN_PROGRESS" | "COMPLETED" | "ERRORED" | "CANCELED" | "UNMATCHED") | "NETWORKING";
352
- [k: string]: any;
353
- }
package/src/util.ts DELETED
@@ -1,129 +0,0 @@
1
- // Utility wrappers for protobuf.
2
-
3
- import { JsonValue, JsonObject, typeofJsonValue, isJsonObject, JsonReadOptions } from "@protobuf-ts/runtime";
4
- import { jsonReadOptions } from "@protobuf-ts/runtime";
5
- import { Value, NullValue, ListValue, Struct } from "./proto/otonoma/common/value";
6
-
7
-
8
- // Hijack the fromJson function, provide our own implementation that is the sensible choice.
9
- Value.fromJson = (json: JsonValue, options) => fromJsonValueInner(json, jsonReadOptions(options));
10
- export function fromJsonValue(json: JsonValue): Value {
11
- return fromJsonValueInner(json, { ignoreUnknownFields: false });
12
- }
13
-
14
- // Converts a json value to a otonoma common Value.
15
- function fromJsonValueInner(json: JsonValue, options: JsonReadOptions, target?: Value): Value {
16
- if (!target)
17
- target = Value.create();
18
- switch (typeof json) {
19
- case "undefined":
20
- // NOTE: We coalesce undefined to null, which is fine for our purposes.
21
- target.kind = { oneofKind: "nullValue", nullValue: NullValue.NULL_VALUE };
22
- break;
23
- case "bigint":
24
- if (json < 0) {
25
- target.kind = { oneofKind: "negIntValue", negIntValue: json };
26
- } else {
27
- target.kind = { oneofKind: "posIntValue", posIntValue: json };
28
- }
29
- break;
30
- case "number":
31
- // Check the number further.
32
- if (Number.isNaN(json) || !Number.isFinite(json)) {
33
- // TODO: We could special case NaN and Inf.
34
- throw "PNCP cannot handle NaN or infinite values yet.";
35
- }
36
- if (Number.isInteger(json)) {
37
- if (json < 0) {
38
- target.kind = { oneofKind: "negIntValue", negIntValue: BigInt(json) };
39
- } else {
40
- target.kind = { oneofKind: "posIntValue", posIntValue: BigInt(json) };
41
- }
42
- } else {
43
- target.kind = { oneofKind: "numberValue", numberValue: json };
44
- }
45
- break;
46
- case "string":
47
- target.kind = { oneofKind: "stringValue", stringValue: json };
48
- break;
49
- case "boolean":
50
- target.kind = { oneofKind: "boolValue", boolValue: json };
51
- break;
52
- case "object":
53
- if (json === null) {
54
- target.kind = { oneofKind: "nullValue", nullValue: NullValue.NULL_VALUE };
55
- }
56
- else if (globalThis.Array.isArray(json)) {
57
- target.kind = { oneofKind: "listValue", listValue: ListValue.fromJson(json) };
58
- }
59
- else {
60
- target.kind = { oneofKind: "structValue", structValue: Struct.fromJson(json) };
61
- }
62
- break;
63
- default: throw new globalThis.Error("Unable to parse " + Value.typeName + " from JSON " + typeofJsonValue(json));
64
- }
65
- return target;
66
- }
67
-
68
- ListValue.fromJson = (json: Array<JsonValue>) => {
69
- if (!globalThis.Array.isArray(json))
70
- throw new globalThis.Error("Unable to parse " + ListValue.typeName + " from JSON " + typeofJsonValue(json));
71
- let target = ListValue.create();
72
- let values = json.map(v => Value.fromJson(v));
73
- target.values.push(...values);
74
- return target;
75
- };
76
-
77
- Struct.fromJson = (json: JsonObject) => {
78
-
79
- if (!isJsonObject(json))
80
- throw new globalThis.Error("Unable to parse message " + Struct.typeName + " from JSON " + typeofJsonValue(json) + ".");
81
- let target = Struct.create();
82
- for (let [k, v] of globalThis.Object.entries(json)) {
83
- target.fields[k] = Value.fromJson(v);
84
- }
85
- return target;
86
- };
87
-
88
- Value.toJson = (message: Value, options) => fromValueToJson(message);
89
-
90
- export function fromValueToJson(message: Value): JsonValue {
91
- if (message.kind.oneofKind === undefined)
92
- throw new globalThis.Error();
93
- switch (message.kind.oneofKind) {
94
- case undefined: throw new globalThis.Error();
95
- case "boolValue": return message.kind.boolValue;
96
- case "nullValue": return null;
97
- case "negIntValue": return Number(message.kind.negIntValue);
98
- case "posIntValue": return Number(message.kind.posIntValue);
99
- case "numberValue":
100
- let numberValue = message.kind.numberValue;
101
- if (typeof numberValue == "number" && !Number.isFinite(numberValue))
102
- throw new globalThis.Error();
103
- return numberValue;
104
- case "stringValue": return message.kind.stringValue;
105
- case "listValue":
106
- let listValueField = Value.fields.find(f => f.no === 8);
107
- if (listValueField?.kind !== "message")
108
- throw new globalThis.Error();
109
- return listValueField.T().toJson(message.kind.listValue);
110
- case "structValue":
111
- let structValueField = Value.fields.find(f => f.no === 7);
112
- if (structValueField?.kind !== "message")
113
- throw new globalThis.Error();
114
- return structValueField.T().toJson(message.kind.structValue);
115
- }
116
-
117
- }
118
-
119
- Struct.toJson = (message: Struct) => {
120
- let json: JsonObject = {};
121
- for (let [k, v] of Object.entries(message.fields)) {
122
- json[k] = Value.toJson(v);
123
- }
124
- return json;
125
- };
126
-
127
- ListValue.toJson = (message: ListValue) => {
128
- return message.values.map(v => Value.toJson(v));
129
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "lib": [
5
- "dom",
6
- "dom.iterable",
7
- "esnext"
8
- ],
9
- "allowJs": true,
10
- // "skipLibCheck": true,
11
- "esModuleInterop": true,
12
- "allowSyntheticDefaultImports": true,
13
- "strict": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "module": "esnext",
17
- "moduleResolution": "node",
18
- "resolveJsonModule": true,
19
- "isolatedModules": true,
20
- "declaration": true,
21
- "declarationMap": true,
22
- "outDir": "./dist"
23
- },
24
- "include": [
25
- "src/**/*"
26
- ]
27
- }