@otonoma/paracord-panels-interface 0.17.1-rc.12

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 (38) hide show
  1. package/dist/channel.d.ts +14 -0
  2. package/dist/channel.d.ts.map +1 -0
  3. package/dist/channel.js +46 -0
  4. package/dist/client/abstractClient.d.ts +27 -0
  5. package/dist/client/abstractClient.d.ts.map +1 -0
  6. package/dist/client/abstractClient.js +22 -0
  7. package/dist/client/index.d.ts +6 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +18 -0
  10. package/dist/client/managedPncpClient.d.ts +38 -0
  11. package/dist/client/managedPncpClient.d.ts.map +1 -0
  12. package/dist/client/managedPncpClient.js +156 -0
  13. package/dist/client/paracordClient.d.ts +28 -0
  14. package/dist/client/paracordClient.d.ts.map +1 -0
  15. package/dist/client/paracordClient.js +97 -0
  16. package/dist/client/pncpClient.d.ts +34 -0
  17. package/dist/client/pncpClient.d.ts.map +1 -0
  18. package/dist/client/pncpClient.js +234 -0
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +2 -0
  22. package/dist/interface/index.d.ts +43 -0
  23. package/dist/interface/index.d.ts.map +1 -0
  24. package/dist/interface/index.js +3 -0
  25. package/dist/interface/methods.d.ts +98 -0
  26. package/dist/interface/methods.d.ts.map +1 -0
  27. package/dist/interface/methods.js +1 -0
  28. package/package.json +35 -0
  29. package/src/channel.ts +58 -0
  30. package/src/client/abstractClient.ts +63 -0
  31. package/src/client/index.ts +20 -0
  32. package/src/client/managedPncpClient.ts +195 -0
  33. package/src/client/paracordClient.ts +149 -0
  34. package/src/client/pncpClient.ts +304 -0
  35. package/src/index.ts +2 -0
  36. package/src/interface/index.ts +74 -0
  37. package/src/interface/methods.ts +136 -0
  38. package/tsconfig.json +21 -0
@@ -0,0 +1,234 @@
1
+ // TODO: A lot of this code is copied from the pncpRpcClient found in the main paracord source code.
2
+ // As such, we should refactor that to make use of this code instead. We should likely move this into a more abstract location and not be
3
+ // part of the "panels" library, but something else instead. All of this is totally generic, and it could
4
+ // just live in the paranet-client repo instead, but then we would just need to implement it in the panels
5
+ // library specifically (which already depends on the paranet-client repo, so that would be OK).
6
+ import { ObservationMessageType, ObservationStartPoint, ParanetServiceClient, PncpClient, PncpMessageKind, simplifyObservationCallback, simplifyPncpCallback, Timestamp } from "@otonoma/paranet-client";
7
+ import { AbstractPncpClient } from ".";
8
+ export class PncpRpcClient extends AbstractPncpClient {
9
+ constructor(init) {
10
+ super(init.init);
11
+ this.connectionState = "disconnected";
12
+ this.client = new PncpClient({
13
+ endpoint: init.broker,
14
+ actorId: init.actorId,
15
+ // TODO: We need to simplify this process of determining the version of client actors.
16
+ actorVersion: init.actorVersion,
17
+ token: init.tokens?.access_token,
18
+ refreshToken: init.tokens?.refresh_token,
19
+ });
20
+ this.actorId = init.actorId;
21
+ this.actorVersion = init.actorVersion;
22
+ this.svcClient = new ParanetServiceClient({
23
+ actorId: init.actorId,
24
+ endpoint: init.service,
25
+ });
26
+ this.client.setTokenCb((token, refresh) => {
27
+ this.svcClient.setTokens(token, refresh);
28
+ });
29
+ if (init.tokens) {
30
+ this.svcClient.setTokens(init.tokens.access_token, init.tokens.refresh_token);
31
+ }
32
+ // TODO: Manage connection state, same as PncpRpcClient.
33
+ const listener = this.client
34
+ .pncpListener()
35
+ .onstart(() => {
36
+ this.connectionState = "connected";
37
+ // TODO: Trigger a callback here.
38
+ // useConnectionStore
39
+ // .getState()
40
+ // .setConnectionState(this.connectionState);
41
+ // resolve();
42
+ })
43
+ .ondisconnect(() => {
44
+ this.connectionState = "disconnected";
45
+ })
46
+ .onreconnect(() => {
47
+ this.connectionState = "connected";
48
+ })
49
+ .onmessage((msg) => {
50
+ const simplified = simplifyPncpCallback(msg);
51
+ switch (simplified.type) {
52
+ case "skill":
53
+ {
54
+ this.skillCb?.(simplified);
55
+ }
56
+ break;
57
+ case "message":
58
+ {
59
+ this.msgCb?.(simplified);
60
+ }
61
+ break;
62
+ }
63
+ })
64
+ .onerror((err, isFatal) => {
65
+ // this.error = decodeURIComponent(err);
66
+ this.connectionState = isFatal ? "unauthenticated" : "failed";
67
+ // reject(this.error);
68
+ })
69
+ .autoReconnect(true);
70
+ this.listener = listener;
71
+ this.observerState = new Map();
72
+ }
73
+ async login(creds) {
74
+ let tokens = await this.client.login(creds);
75
+ this.svcClient.setTokens(tokens.access_token, tokens.refresh_token);
76
+ }
77
+ async pncpRequest(req) {
78
+ let res = await this.client.pncpRequest(req);
79
+ const date = res.timeCreated && Timestamp.toDate(res.timeCreated);
80
+ return {
81
+ type: "response",
82
+ messageId: res.messageId,
83
+ conversationId: res.id,
84
+ actorId: res.matchedId?.id,
85
+ actorVersion: res.matchedId?.version,
86
+ date,
87
+ };
88
+ }
89
+ async pncpResponse(req) {
90
+ let response = await this.client.pncpMessage({
91
+ conversation: req.conversation,
92
+ message: {
93
+ type: PncpMessageKind.PNCP_RESPONSE,
94
+ value: {
95
+ data: req.data,
96
+ }
97
+ },
98
+ });
99
+ const date = response.timeCreated && Timestamp.toDate(response.timeCreated);
100
+ const messageId = response.messageId;
101
+ const entityId = response.matchedId;
102
+ const actorId = entityId?.id;
103
+ const actorVersion = entityId?.version;
104
+ return { type: "response", date, messageId, actorId, actorVersion };
105
+ }
106
+ async pncpMessage(data) {
107
+ const response = await this.client.pncpMessageObject(data);
108
+ const date = response.timeCreated && Timestamp.toDate(response.timeCreated);
109
+ const messageId = response.messageId;
110
+ const entityId = response.matchedId;
111
+ const actorId = entityId?.id;
112
+ const actorVersion = entityId?.version;
113
+ return { type: "response", date, messageId, actorId, actorVersion };
114
+ }
115
+ async registerSkillCallback(_req) {
116
+ // Nothing to do. We could have the paranet only send skill requests to certain clients,
117
+ // like the way observers work now - probably a useful feature. But for now, nothing to do here.
118
+ }
119
+ async registerObserverCallback(req) {
120
+ if (!this.obsCb) {
121
+ throw new Error("Set an observer callback first");
122
+ }
123
+ const state = this.createOrGetObserverStream({
124
+ body: {
125
+ subject: req.subject,
126
+ action: req.action,
127
+ conversationId: req.conversationId,
128
+ filters: req.filters !== undefined ? req.filters : [{ kind: ObservationMessageType.OBS_MESSAGE_TYPE_SKILL }],
129
+ },
130
+ offset: req.offset,
131
+ });
132
+ console.log(state);
133
+ state.observer
134
+ .onstart(() => {
135
+ console.log("Started observer stream", req);
136
+ })
137
+ .ondisconnect(() => {
138
+ console.log("Observer disconnected");
139
+ })
140
+ .onerror((e) => {
141
+ console.log("Error from observer:", e);
142
+ })
143
+ .onmessage((msg) => {
144
+ const simplified = simplifyObservationCallback(msg);
145
+ this.obsCb?.(simplified, req.callback);
146
+ })
147
+ .autoReconnect(true)
148
+ .connect();
149
+ return {
150
+ type: "registerObserverCallback",
151
+ args: {
152
+ key: state.key
153
+ }
154
+ };
155
+ }
156
+ createOrGetObserverStream({ body, offset, }) {
157
+ if (!body.subject || !body.action) {
158
+ // TODO: Throw an error.
159
+ }
160
+ const key = JSON.stringify({ body, offset })
161
+ .split("")
162
+ .sort()
163
+ .join("");
164
+ let state = this.observerState.get(key);
165
+ if (state != null) {
166
+ return state;
167
+ }
168
+ // NOTE (JAB, 2025-11-03): We will need to consider if we should allow panels to specify the start point, or just compute
169
+ // it ourselves. For now, probably better to restrict it.
170
+ const startPoint = offset
171
+ ? ObservationStartPoint.OBS_START_OFFSET
172
+ : body.conversationId
173
+ ? ObservationStartPoint.OBS_START_BEGINNING
174
+ : ObservationStartPoint.OBS_START_HEAD;
175
+ const listener = this.client.observerListener({
176
+ author: {
177
+ id: this.actorId,
178
+ version: this.actorVersion,
179
+ },
180
+ body,
181
+ startPoint,
182
+ seqOffset: offset ? BigInt(offset) : undefined,
183
+ // TODO (JAB, 2025-11-04): There may be scenarios where we want to track paracord observers,
184
+ // but currently this is only used in panels and we never want those to be tracked.
185
+ untracked: true,
186
+ });
187
+ // TODO: Setup the callback information correctly.
188
+ const newState = {
189
+ key,
190
+ observer: listener,
191
+ };
192
+ this.observerState.set(key, newState);
193
+ return newState;
194
+ }
195
+ async deleteObserver(key) {
196
+ console.log("Removing observer ", key);
197
+ const state = this.observerState.get(key);
198
+ if (state) {
199
+ state.observer.disconnect();
200
+ this.observerState.delete(key);
201
+ }
202
+ }
203
+ async uploadDocument(args) {
204
+ let response = await this.svcClient.documentUpload(args.body, args.args);
205
+ return {
206
+ type: "uploadDocument",
207
+ body: response,
208
+ };
209
+ }
210
+ async fetchDocument(args) {
211
+ let stream;
212
+ let error;
213
+ try {
214
+ let response = await this.svcClient.documentFetch(args);
215
+ stream = response.body;
216
+ }
217
+ catch (e) {
218
+ error = e;
219
+ }
220
+ return {
221
+ type: "fetchDocument",
222
+ error,
223
+ stream,
224
+ };
225
+ }
226
+ async graphqlCall(args) {
227
+ let response = await this.svcClient.graphql(args.query, args.variables);
228
+ return {
229
+ type: "graphqlCall",
230
+ data: response.data,
231
+ error: response.errors,
232
+ };
233
+ }
234
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./interface";
2
+ export * from "./client";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./interface";
2
+ export * from "./client";
@@ -0,0 +1,43 @@
1
+ import { ObservationCallbackObject, PncpMessageCallbackObject, PncpRequestCallbackObject } from "@otonoma/paranet-client";
2
+ import { MethodCall, MethodReturn } from "./methods";
3
+ export * from "./methods";
4
+ export declare const PARACORD_PANEL_REVISION: number;
5
+ export interface PanelConnect {
6
+ apiRevision: number;
7
+ panelId: string;
8
+ type: "panelConnect";
9
+ }
10
+ export interface PanelMessage {
11
+ apiRevision: number;
12
+ panelId: string;
13
+ messageId?: number;
14
+ body: MessageBody;
15
+ }
16
+ export type MessageBody = PanelMethodCall | PanelMethodReturnMessage | PncpMessageBody | PanelParacordError;
17
+ export interface PanelParacordError {
18
+ type: "paracordError";
19
+ error: string;
20
+ }
21
+ export interface PanelMethodCall {
22
+ type: "call";
23
+ body: MethodCall;
24
+ }
25
+ export interface PanelMethodReturnMessage {
26
+ type: "callReturn";
27
+ body: MethodReturn;
28
+ }
29
+ export type PncpMessageBody = PncpSkillCallback | PncpMessageCallback | ObservationCallback;
30
+ export interface PncpSkillCallback {
31
+ type: "pncpSkillCb";
32
+ body: PncpRequestCallbackObject;
33
+ }
34
+ export interface PncpMessageCallback {
35
+ type: "pncpMessageCb";
36
+ body: PncpMessageCallbackObject;
37
+ }
38
+ export interface ObservationCallback {
39
+ type: "pncpObservationCb";
40
+ body: ObservationCallbackObject;
41
+ callback?: any;
42
+ }
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAErD,cAAc,WAAW,CAAC;AAE1B,eAAO,MAAM,uBAAuB,EAAE,MAAU,CAAC;AAGjD,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;CACtB;AAGD,MAAM,WAAW,YAAY;IAE3B,WAAW,EAAE,MAAM,CAAC;IAEpB,OAAO,EAAE,MAAM,CAAC;IAGhB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,MAAM,WAAW,GACnB,eAAe,GACf,wBAAwB,GACxB,eAAe,GACf,kBAAkB,CAAC;AAEvB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,MAAM,eAAe,GACvB,iBAAiB,GACjB,mBAAmB,GACnB,mBAAmB,CAAC;AAExB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,yBAAyB,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,yBAAyB,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,yBAAyB,CAAC;IAChC,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB"}
@@ -0,0 +1,3 @@
1
+ // Interface types for communication between a panel and paracord.
2
+ export * from "./methods";
3
+ export const PARACORD_PANEL_REVISION = 1;
@@ -0,0 +1,98 @@
1
+ import { ConversationId, DocumentArgs, DocumentInfo, ObservationMessageFilter, PncpMessageObject, SkillRequest } from "@otonoma/paranet-client";
2
+ export type MethodCall = PncpRequestCall | PncpResponseCall | PncpMessageCall | RegisterSkillCallbackCall | RegisterObserverCallbackCall | UnregisterObserverCallbackCall | UploadDocumentCall | FetchDocumentCall | GraphqlCall;
3
+ export type MethodReturn = PncpCallResponse | GraphqlCallResponse | UploadDocumentResponse | FetchDocumentResponse | RegisterObserverResponse | VoidReturn;
4
+ export type PncpRequestCall = {
5
+ method: "pncpRequest";
6
+ args: SkillRequest;
7
+ };
8
+ export type PncpResponseCall = {
9
+ method: "pncpResponse";
10
+ args: PncpMessageResponse;
11
+ };
12
+ export type PncpMessageCall = {
13
+ method: "pncpMessage";
14
+ args: PncpMessageObject;
15
+ };
16
+ export type RegisterSkillCallbackCall = {
17
+ method: "registerSkillCallback";
18
+ args: RegisterSkillCallback;
19
+ };
20
+ export type RegisterObserverCallbackCall = {
21
+ method: "registerObserverCallback";
22
+ args: RegisterObserverCallback;
23
+ };
24
+ export type RegisterObserverResponse = {
25
+ type: "registerObserverCallback";
26
+ args: {
27
+ key: string;
28
+ };
29
+ };
30
+ export type UnregisterObserverCallbackCall = {
31
+ method: "unregisterObserverCallback";
32
+ args: {
33
+ key: string;
34
+ };
35
+ };
36
+ export type UploadDocumentCall = {
37
+ method: "uploadDocumentCall";
38
+ args: UploadDocumentArgs;
39
+ };
40
+ export type UploadDocumentArgs = {
41
+ args?: DocumentArgs;
42
+ body: File | any;
43
+ };
44
+ export type UploadDocumentResponse = {
45
+ type: "uploadDocument";
46
+ error?: string;
47
+ body?: DocumentInfo;
48
+ };
49
+ export type FetchDocumentCall = {
50
+ method: "fetchDocumentCall";
51
+ args: DocumentArgs;
52
+ };
53
+ export type FetchDocumentResponse = {
54
+ type: "fetchDocument";
55
+ stream?: ReadableStream;
56
+ error?: any;
57
+ };
58
+ export type GraphqlCall = {
59
+ method: "graphqlCall";
60
+ args: GraphqlCallArgs;
61
+ };
62
+ export type GraphqlCallArgs = {
63
+ query: string | any;
64
+ variables?: any;
65
+ };
66
+ export type RegisterSkillCallback = {
67
+ subject: string;
68
+ action: string;
69
+ };
70
+ export type RegisterObserverCallback = {
71
+ subject: string;
72
+ action: string;
73
+ offset?: number;
74
+ callback?: any;
75
+ filters?: ObservationMessageFilter[];
76
+ conversationId?: string;
77
+ };
78
+ export interface PncpCallResponse {
79
+ type: "response";
80
+ conversationId?: ConversationId;
81
+ messageId: string;
82
+ date?: Date;
83
+ actorId?: string;
84
+ actorVersion?: string;
85
+ }
86
+ export interface PncpMessageResponse {
87
+ conversation: string;
88
+ data: any;
89
+ }
90
+ export interface GraphqlCallResponse {
91
+ type: "graphqlCall";
92
+ data: any;
93
+ error?: any;
94
+ }
95
+ export interface VoidReturn {
96
+ type: "void";
97
+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,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAIF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,GAAG,CAAC;CACX;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;CACd"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@otonoma/paracord-panels-interface",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "git+https://github.com/otonoma/paracord.git"
6
+ },
7
+ "license": "UNLICENSED",
8
+ "version": "0.17.1-rc.12",
9
+ "description": "Paracord Panels common interface",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "scripts": {
13
+ "build": "tsc -p tsconfig.json",
14
+ "dev": "yarn build -- --watch",
15
+ "prepublish": "yarn build",
16
+ "lint": "eslint ."
17
+ },
18
+ "dependencies": {
19
+ "@ai-zen/async-queue": "1.3.1",
20
+ "@otonoma/paranet-client": "^2.11.0-rc.18"
21
+ },
22
+ "devDependencies": {
23
+ "@eslint/js": "^9.9.1",
24
+ "@protobuf-ts/plugin": "^2.9.4",
25
+ "@types/eslint__js": "^8.42.3",
26
+ "eslint": "^9.9.1",
27
+ "typescript": "^5.5.4",
28
+ "typescript-eslint": "^8.3.0"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "import": "./dist/index.js"
33
+ }
34
+ }
35
+ }
package/src/channel.ts ADDED
@@ -0,0 +1,58 @@
1
+ // A generic channel type.
2
+ import { PanelMessage, MessageBody } from "./interface";
3
+ import { PARACORD_PANEL_REVISION } from "./interface";
4
+ export class Channel {
5
+ evs: Map<number, (data: any) => void>;
6
+ evId: number;
7
+ constructor(
8
+ private panelId: string,
9
+ private port: MessagePort,
10
+ incoming: (msg: PanelMessage) => void
11
+ ) {
12
+ this.evs = new Map();
13
+ this.evId = 0;
14
+ port.onmessage = (ev) => {
15
+ const message: PanelMessage = ev.data;
16
+ if (message.messageId === undefined) {
17
+ // In this case we need to pass the full message so type disambigation can occur on the other side.
18
+ incoming(message);
19
+ } else {
20
+ const cb = this.evs.get(message.messageId);
21
+ this.evs.delete(message.messageId);
22
+ if (cb) {
23
+ // In this case we can destructure the message.
24
+ cb(message.body);
25
+ }
26
+ }
27
+ };
28
+ }
29
+
30
+ // TODO (JAB): Figure out the "continuous" callbacks; observers, skill callbacks, etc. need to be able to
31
+ // receive messages repeatedly.
32
+ private send(
33
+ body: MessageBody,
34
+ cb: (data: MessageBody) => void,
35
+ transferred?: Transferable[]
36
+ ) {
37
+ const id = this.evId++;
38
+ this.evs.set(id, cb);
39
+ const message: PanelMessage = {
40
+ messageId: id,
41
+ body: body,
42
+ panelId: this.panelId,
43
+ apiRevision: PARACORD_PANEL_REVISION,
44
+ };
45
+ this.port.postMessage(message, transferred || []);
46
+ }
47
+
48
+ public asyncSend(body: MessageBody): Promise<MessageBody> {
49
+ const p = new Promise<MessageBody>((r) => this.send(body, (m) => r(m)));
50
+ return p;
51
+ }
52
+
53
+ public async createStream<T, R>(type: string, msg: T): Promise<Stream<R>> {
54
+ throw new Error("Unimplemented");
55
+ }
56
+ }
57
+
58
+ export class Stream<R> {}
@@ -0,0 +1,63 @@
1
+
2
+ import {
3
+ DocumentArgs, LoginCredentials, ObservationCallbackObject, PncpMessageCallbackObject, PncpMessageObject, PncpRequestCallbackObject, SkillRequest,
4
+ } from "@otonoma/paranet-client";
5
+ import {
6
+ FetchDocumentResponse, GraphqlCallArgs, GraphqlCallResponse, PncpCallResponse, PncpMessageResponse, RegisterObserverCallback, RegisterObserverResponse, RegisterSkillCallback, UploadDocumentArgs, UploadDocumentResponse
7
+ } from "../interface";
8
+
9
+ export interface PncpClientInit {
10
+ skill?: (msg: PncpRequestCallbackObject) => void;
11
+ msg?: (msg: PncpMessageCallbackObject) => void;
12
+ obs?: (msg: ObservationCallbackObject, callback?: any) => void;
13
+ }
14
+
15
+ // TODO: Make a better name for this
16
+ // This client represents an abstract wrapper around a managed pncp client.
17
+ export abstract class AbstractPncpClient {
18
+ skillCb?: (msg: PncpRequestCallbackObject) => void;
19
+ msgCb?: (msg: PncpMessageCallbackObject) => void;
20
+ obsCb?: (msg: ObservationCallbackObject, callback?: any) => void;
21
+ constructor(init?: PncpClientInit) {
22
+ this.skillCb = init?.skill;
23
+ this.msgCb = init?.msg;
24
+ this.obsCb = init?.obs;
25
+ }
26
+
27
+ public abstract login(creds: LoginCredentials): Promise<void>;
28
+ public abstract pncpRequest(req: SkillRequest): Promise<PncpCallResponse>;
29
+ public abstract pncpResponse(
30
+ req: PncpMessageResponse
31
+ ): Promise<PncpCallResponse>;
32
+
33
+ public abstract pncpMessage(
34
+ req: PncpMessageObject
35
+ ): Promise<PncpCallResponse>;
36
+
37
+
38
+ public abstract registerSkillCallback(req: RegisterSkillCallback): any;
39
+ public abstract registerObserverCallback(req: RegisterObserverCallback): Promise<RegisterObserverResponse>;
40
+ public abstract deleteObserver(key: string): Promise<void>;
41
+
42
+ // Set the callback on the local listener for skills.
43
+ public skillCallback(cb: (msg: PncpRequestCallbackObject) => void): this {
44
+ this.skillCb = cb;
45
+ return this;
46
+ }
47
+
48
+ public messageCallback(cb: (msg: PncpMessageCallbackObject) => void): this {
49
+ this.msgCb = cb;
50
+ return this;
51
+ }
52
+
53
+ public observationCallback(
54
+ cb: (msg: ObservationCallbackObject, callback?: any) => void
55
+ ): this {
56
+ this.obsCb = cb;
57
+ return this;
58
+ }
59
+
60
+ public abstract uploadDocument(args: UploadDocumentArgs): Promise<UploadDocumentResponse>;
61
+ public abstract fetchDocument(args: DocumentArgs): Promise<FetchDocumentResponse>;
62
+ public abstract graphqlCall(args: GraphqlCallArgs): Promise<GraphqlCallResponse>;
63
+ }
@@ -0,0 +1,20 @@
1
+ export * from "./abstractClient";
2
+ export * from "./paracordClient";
3
+ export * from "./managedPncpClient";
4
+ export * from "./pncpClient";
5
+
6
+ // A function which determines if the application is currently running inside of a paracord panel or as a standalone app.
7
+ // This can be used to present a login page and construct a direct connection as needed for standalone apps and otherwise
8
+ // establish a ParacordClient.
9
+ export function isInParacord(): boolean {
10
+ // This isn't a guaranteed way to check this, we could achieve that by creating a different encoding of the name though.
11
+ if (window.top !== window.self) {
12
+ const name = window.name;
13
+ const parts = name.split('@');
14
+ return parts.length == 3 && parts[0].match(/[a-f0-9]*-[a-f0-9]*/) != null;
15
+ } else {
16
+ return false;
17
+ }
18
+ }
19
+
20
+