@otonoma/paranet-client 2.11.0-rc.18

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.
Files changed (75) hide show
  1. package/README.md +2 -0
  2. package/dist/client.d.ts +168 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +497 -0
  5. package/dist/graphql.d.ts +8 -0
  6. package/dist/graphql.d.ts.map +1 -0
  7. package/dist/graphql.js +113 -0
  8. package/dist/index.d.ts +12 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +11 -0
  11. package/dist/pncp.d.ts +129 -0
  12. package/dist/pncp.d.ts.map +1 -0
  13. package/dist/pncp.js +100 -0
  14. package/dist/proto/broker.grpc.client.d.ts +154 -0
  15. package/dist/proto/broker.grpc.client.d.ts.map +1 -0
  16. package/dist/proto/broker.grpc.client.js +102 -0
  17. package/dist/proto/broker.grpc.d.ts +6 -0
  18. package/dist/proto/broker.grpc.d.ts.map +1 -0
  19. package/dist/proto/broker.grpc.js +32 -0
  20. package/dist/proto/broker_api.d.ts +324 -0
  21. package/dist/proto/broker_api.d.ts.map +1 -0
  22. package/dist/proto/broker_api.js +566 -0
  23. package/dist/proto/google/protobuf/descriptor.d.ts +2492 -0
  24. package/dist/proto/google/protobuf/descriptor.d.ts.map +1 -0
  25. package/dist/proto/google/protobuf/descriptor.js +3250 -0
  26. package/dist/proto/google/protobuf/timestamp.d.ts +157 -0
  27. package/dist/proto/google/protobuf/timestamp.d.ts.map +1 -0
  28. package/dist/proto/google/protobuf/timestamp.js +132 -0
  29. package/dist/proto/grpc/health/v1/health.client.d.ts +79 -0
  30. package/dist/proto/grpc/health/v1/health.client.d.ts.map +1 -0
  31. package/dist/proto/grpc/health/v1/health.client.js +46 -0
  32. package/dist/proto/grpc/health/v1/health.d.ts +74 -0
  33. package/dist/proto/grpc/health/v1/health.d.ts.map +1 -0
  34. package/dist/proto/grpc/health/v1/health.js +152 -0
  35. package/dist/proto/identifiers.d.ts +82 -0
  36. package/dist/proto/identifiers.d.ts.map +1 -0
  37. package/dist/proto/identifiers.js +132 -0
  38. package/dist/proto/mediums.d.ts +71 -0
  39. package/dist/proto/mediums.d.ts.map +1 -0
  40. package/dist/proto/mediums.js +120 -0
  41. package/dist/proto/observation.d.ts +287 -0
  42. package/dist/proto/observation.d.ts.map +1 -0
  43. package/dist/proto/observation.js +443 -0
  44. package/dist/proto/otonoma/common/value.d.ts +127 -0
  45. package/dist/proto/otonoma/common/value.d.ts.map +1 -0
  46. package/dist/proto/otonoma/common/value.js +248 -0
  47. package/dist/proto/pncp.d.ts +607 -0
  48. package/dist/proto/pncp.d.ts.map +1 -0
  49. package/dist/proto/pncp.js +936 -0
  50. package/dist/schema/paranet.d.ts +245 -0
  51. package/dist/schema/paranet.d.ts.map +1 -0
  52. package/dist/schema/paranet.js +7 -0
  53. package/dist/util.d.ts +5 -0
  54. package/dist/util.d.ts.map +1 -0
  55. package/dist/util.js +120 -0
  56. package/package.json +39 -0
  57. package/src/client.ts +677 -0
  58. package/src/graphql.ts +103 -0
  59. package/src/index.ts +14 -0
  60. package/src/pncp.ts +236 -0
  61. package/src/proto/broker.grpc.client.ts +193 -0
  62. package/src/proto/broker.grpc.ts +32 -0
  63. package/src/proto/broker_api.ts +778 -0
  64. package/src/proto/google/protobuf/descriptor.ts +4860 -0
  65. package/src/proto/google/protobuf/timestamp.ts +288 -0
  66. package/src/proto/grpc/health/v1/health.client.ts +106 -0
  67. package/src/proto/grpc/health/v1/health.ts +174 -0
  68. package/src/proto/identifiers.ts +176 -0
  69. package/src/proto/mediums.ts +168 -0
  70. package/src/proto/observation.ts +636 -0
  71. package/src/proto/otonoma/common/value.ts +334 -0
  72. package/src/proto/pncp.ts +1333 -0
  73. package/src/schema/paranet.ts +257 -0
  74. package/src/util.ts +129 -0
  75. package/tsconfig.json +27 -0
@@ -0,0 +1,257 @@
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 EntityId = string;
24
+ /**
25
+ * Determines the match strategy used by the paranet.
26
+ */
27
+ export type SkillMatchStrategy = "BEST" | "FIRST" | "STRICT";
28
+ export type EntityReq = string;
29
+ export type PncpMessageBody =
30
+ | {
31
+ type: "response";
32
+ body: PncpDataMessage;
33
+ [k: string]: any;
34
+ }
35
+ | {
36
+ type: "status";
37
+ body: PncpDataMessage;
38
+ [k: string]: any;
39
+ }
40
+ | {
41
+ type: "cancel";
42
+ body: PncpDataMessage;
43
+ [k: string]: any;
44
+ }
45
+ | {
46
+ type: "question";
47
+ body: PncpQuestionMessage;
48
+ [k: string]: any;
49
+ }
50
+ | {
51
+ type: "answer";
52
+ body: PncpAnswerMessage;
53
+ [k: string]: any;
54
+ }
55
+ | {
56
+ type: "error";
57
+ body: PncpDataMessage;
58
+ [k: string]: any;
59
+ };
60
+ export type Id = string;
61
+ /**
62
+ * Represents all message types that can be sent from the paranet to an actor.
63
+ */
64
+ export type PncpCallback =
65
+ | {
66
+ type: "skill";
67
+ body: PncpRequestCallback;
68
+ [k: string]: any;
69
+ }
70
+ | {
71
+ type: "message";
72
+ body: PncpMessageCallback;
73
+ [k: string]: any;
74
+ };
75
+ /**
76
+ * Used to track the current state of the conversation.
77
+ */
78
+ export type ConversationState = "IN_PROGRESS" | "COMPLETED" | "ERRORED" | "CANCELED";
79
+
80
+ /**
81
+ * A common root type. This type is itself not used, but it will allow schema resolution to properly find all of the types in one place.
82
+ */
83
+ export interface ParanetTypes {
84
+ pncp: PncpPacket;
85
+ callback: PncpCallback;
86
+ [k: string]: any;
87
+ }
88
+ /**
89
+ * Represents a "skill message" request. All conversations are initiated via a skill request.
90
+ */
91
+ export interface PncpRequest {
92
+ /**
93
+ * The core body to the request.
94
+ */
95
+ body: PncpSkillMessage;
96
+ /**
97
+ * Information provided on callback to the actor when a response is received.
98
+ */
99
+ callback?: {
100
+ [k: string]: any;
101
+ };
102
+ /**
103
+ * The parent conversation ID, if one exists.
104
+ */
105
+ parentId?: ConversationId | null;
106
+ /**
107
+ * Identifying information about who is making the call.
108
+ */
109
+ author: EntityId;
110
+ /**
111
+ * Specifies the match strategy.
112
+ */
113
+ matchStrategy?: SkillMatchStrategy & string;
114
+ /**
115
+ * Version request spec for the (subject, action) pair.
116
+ */
117
+ versionReq?: string | null;
118
+ /**
119
+ * When specified, the particular actor is called if the skill matches.
120
+ */
121
+ targetActorId?: EntityReq | null;
122
+ /**
123
+ * An arbitrary key that is allowed to be set and provided on further messages from mediums.
124
+ */
125
+ key?: {
126
+ [k: string]: any;
127
+ };
128
+ /**
129
+ * ID of the medium that made the request.
130
+ */
131
+ mediumInfo?: PncpRequestMediumInfo | null;
132
+ [k: string]: any;
133
+ }
134
+ export interface PncpSkillMessage {
135
+ /**
136
+ * Subject of the request.
137
+ */
138
+ subject: string;
139
+ /**
140
+ * Action of the request.
141
+ */
142
+ action: string;
143
+ body: any;
144
+ [k: string]: any;
145
+ }
146
+ export interface PncpRequestMediumInfo {
147
+ id: EntityId;
148
+ userInfo: any;
149
+ [k: string]: any;
150
+ }
151
+ /**
152
+ * PNCP Message. Messages are a variety of types of data sent within a conversation.
153
+ */
154
+ export interface PncpMessage {
155
+ id: ConversationId;
156
+ message: PncpMessageBody;
157
+ [k: string]: any;
158
+ }
159
+ /**
160
+ * A simple data packet.
161
+ */
162
+ export interface PncpDataMessage {
163
+ data: any;
164
+ [k: string]: any;
165
+ }
166
+ /**
167
+ * A PNCP packet for question messages.
168
+ */
169
+ export interface PncpQuestionMessage {
170
+ /**
171
+ * The id of the question.
172
+ */
173
+ id: string;
174
+ data: any;
175
+ callback?: {
176
+ [k: string]: any;
177
+ };
178
+ [k: string]: any;
179
+ }
180
+ /**
181
+ * A PNCP packet for answer messages.
182
+ */
183
+ export interface PncpAnswerMessage {
184
+ /**
185
+ * The ID of the question message being replied to.
186
+ */
187
+ replyTo: Id;
188
+ data: any;
189
+ [k: string]: any;
190
+ }
191
+ /**
192
+ * Skill request sent to an actor from the paranet.
193
+ */
194
+ export interface PncpRequestCallback {
195
+ id: ConversationId;
196
+ messageId: Id;
197
+ body: PncpSkillMessage;
198
+ /**
199
+ * The parent conversation ID, if one exists.
200
+ */
201
+ parentId?: ConversationId | null;
202
+ timeCreated: string;
203
+ authorId: EntityId;
204
+ /**
205
+ * The actor ID of the receiving actor. This is optional as some skill matches have no targets in the case of a broadcast skill message type.
206
+ */
207
+ targetActorId?: EntityId | null;
208
+ /**
209
+ * Additional parameters included with the request. These come from actor/skill templates.
210
+ */
211
+ parameters?: ParameterData;
212
+ [k: string]: any;
213
+ }
214
+ export interface ParameterData {
215
+ /**
216
+ * Default to empty values.
217
+ */
218
+ provider?: {
219
+ [k: string]: any;
220
+ };
221
+ skill?: {
222
+ [k: string]: any;
223
+ };
224
+ medium?: any;
225
+ [k: string]: any;
226
+ }
227
+ /**
228
+ * In the flow of paranet messages, this is logically a "response" message. The `data` field comes from the targeted actor whereas others are contextual from the paranet.
229
+ */
230
+ export interface PncpMessageCallback {
231
+ /**
232
+ * The identifier for the target actor (initiator of the original conversation, typically).
233
+ */
234
+ id: ConversationId;
235
+ messageId: Id;
236
+ timeCreated: string;
237
+ /**
238
+ * Key provided from response to initial call.
239
+ */
240
+ key?: {
241
+ [k: string]: any;
242
+ };
243
+ message: PncpMessage;
244
+ params?: any;
245
+ /**
246
+ * Callback information if any was provided in the conversation.
247
+ */
248
+ callback?: {
249
+ [k: string]: any;
250
+ };
251
+ medium?: any;
252
+ /**
253
+ * Any change to the conversation state will be present here.
254
+ */
255
+ conversationState: ConversationState;
256
+ [k: string]: any;
257
+ }
package/src/util.ts ADDED
@@ -0,0 +1,129 @@
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 ADDED
@@ -0,0 +1,27 @@
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
+ }