@superblocksteam/sdk 1.4.2 → 1.5.0

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.
@@ -0,0 +1,61 @@
1
+ import { Api as ApiPb, Signature } from "./common";
2
+
3
+ export type SignatureResponse = {
4
+ signature: Signature;
5
+ };
6
+
7
+ export type ApiResource = {
8
+ api: ApiPb;
9
+ };
10
+
11
+ export type GenericResource = {
12
+ literal: {
13
+ data: any;
14
+ signature?: Signature;
15
+ };
16
+ };
17
+
18
+ interface PageHash {
19
+ /** The version of the page DSL. */
20
+ version: number;
21
+ /** The SHA-256 hash of the page DSL (i.e. `page.layouts[0].dsl`), in base64. */
22
+ hash: string;
23
+ }
24
+
25
+ export interface ApplicationSettingsHashes {
26
+ /** The SHA-256 hash of all custom components related properties from settings, in base64. */
27
+ components: string;
28
+ /** The SHA-256 hash of settings without the custom components related properties, in base64. */
29
+ rest: string;
30
+ }
31
+
32
+ export interface ApplicationSignatureTree {
33
+ /** The version of the signature tree. */
34
+ v: 1;
35
+ settings: ApplicationSettingsHashes;
36
+ page: PageHash;
37
+ }
38
+
39
+ export interface ApplicationSignatureTreeSigned {
40
+ /** The SHA-256 hash of `root`, in base64. */
41
+ signature: Signature;
42
+ root: ApplicationSignatureTree;
43
+ }
44
+
45
+ export type AppToSign = {
46
+ rootHash: string;
47
+ };
48
+
49
+ export type AppToVerify = {
50
+ rootHash: string;
51
+ signature?: Signature;
52
+ };
53
+
54
+ export type ApiToSign = {
55
+ apiPb: ApiPb;
56
+ };
57
+
58
+ export type ApiToVerify = {
59
+ apiPb: ApiPb;
60
+ signature?: Signature;
61
+ };
@@ -0,0 +1,48 @@
1
+ export type MethodHandler<Params, Result, PeerMethods, RequestContext> = (
2
+ params: Params,
3
+ peer: ISocketClient<PeerMethods>,
4
+ ctx: RequestContext
5
+ ) => Promise<Result>;
6
+
7
+ export type MiddlewareHandler<Params, PeerMethods, RequestContext> = (
8
+ params: Params,
9
+ peerAuthorization: string | undefined,
10
+ peer: ISocketClient<PeerMethods>,
11
+ ctx: RequestContext
12
+ ) => Promise<void>;
13
+
14
+ export type MethodHandlers<Methods, PeerMethods, RequestContext> = {
15
+ [Key in keyof Methods]: Methods[Key] extends (
16
+ params: infer Params
17
+ ) => Promise<infer Result>
18
+ ? [
19
+ ...middlewareHandlers: MiddlewareHandler<
20
+ Params,
21
+ PeerMethods,
22
+ RequestContext
23
+ >[],
24
+ handler: MethodHandler<Params, Result, PeerMethods, RequestContext>
25
+ ]
26
+ : Methods[Key] extends Record<string, unknown>
27
+ ? MethodHandlers<Methods[Key], PeerMethods, RequestContext>
28
+ : never;
29
+ };
30
+
31
+ type ISocketClientMethodCall<Methods> = {
32
+ [Key in keyof Methods]: Methods[Key] extends (
33
+ params: infer P
34
+ ) => Promise<infer R>
35
+ ? (params: P) => Promise<R>
36
+ : Methods[Key] extends Record<string, unknown>
37
+ ? ISocketClientMethodCall<Methods[Key]>
38
+ : never;
39
+ };
40
+
41
+ export type ISocketClient<Methods> = {
42
+ close: () => void;
43
+ call: ISocketClientMethodCall<Methods>;
44
+ };
45
+
46
+ export type MethodSchema<Params, Response> = (
47
+ params: Params
48
+ ) => Promise<Response>;
package/src/utils.ts ADDED
@@ -0,0 +1,45 @@
1
+ import {
2
+ Agent,
3
+ AgentStatus,
4
+ AgentType,
5
+ Api,
6
+ OpenAiPluginId,
7
+ transcribeAudioToTextTranslateToEnglishTruthyValues,
8
+ } from "./types";
9
+
10
+ export function getAgentUrls(agents: Agent[], agentType: AgentType): string[] {
11
+ const filtered = agents.filter(
12
+ (a) => a.type === agentType && a.status === AgentStatus.ACTIVE
13
+ );
14
+ return filtered.map((f) => f.url);
15
+ }
16
+
17
+ export const sanitizeV2RequestBody = (
18
+ apiBody: Record<string, unknown>
19
+ ): Record<string, unknown> => {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const traverseJSON = (obj: any) => {
22
+ for (const key in obj) {
23
+ if (key === "step" && obj.step[OpenAiPluginId]) {
24
+ const value =
25
+ obj.step[OpenAiPluginId].transcribeAudioToTextTranslateToEnglish;
26
+ obj.step[OpenAiPluginId].transcribeAudioToTextTranslateToEnglish =
27
+ transcribeAudioToTextTranslateToEnglishTruthyValues.includes(value);
28
+ } else if (typeof obj[key] === "object") {
29
+ sanitizeV2RequestBody(obj[key]);
30
+ }
31
+ }
32
+ };
33
+ traverseJSON(apiBody);
34
+ return apiBody;
35
+ };
36
+
37
+ export const getSanitizedApi = (api: Api): any => {
38
+ const sanitizedBlocks = (api.blocks ?? [])?.map(
39
+ (block: Record<string, unknown>) => sanitizeV2RequestBody(block)
40
+ );
41
+ return {
42
+ ...api,
43
+ blocks: sanitizedBlocks,
44
+ };
45
+ };
package/tsconfig.json CHANGED
@@ -6,7 +6,9 @@
6
6
  "outDir": "dist",
7
7
  "rootDir": "src",
8
8
  "strict": true,
9
- "target": "es2019"
9
+ "target": "es2019",
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true
10
12
  },
11
13
  "include": ["src/**/*"]
12
14
  }