@squidcloud/client 1.0.59 → 1.0.60

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 (31) hide show
  1. package/dist/common/src/ai-assistant.schemas.d.ts +210 -0
  2. package/dist/common/src/ai-assistant.types.d.ts +76 -0
  3. package/dist/common/src/api-call.context.d.ts +1 -1
  4. package/dist/common/src/api.types.d.ts +1 -1
  5. package/dist/common/src/application.schemas.d.ts +32 -1
  6. package/dist/common/src/application.types.d.ts +16 -4
  7. package/dist/common/src/bundle-data.types.d.ts +1 -1
  8. package/dist/common/src/index.d.ts +3 -1
  9. package/dist/common/src/integrations/ai_assistant.types.d.ts +30 -0
  10. package/dist/common/src/integrations/api.types.d.ts +80 -0
  11. package/dist/common/src/integrations/auth.types.d.ts +22 -0
  12. package/dist/common/src/integrations/database.types.d.ts +236 -0
  13. package/dist/common/src/integrations/index.d.ts +97 -0
  14. package/dist/common/src/integrations/observability.types.d.ts +22 -0
  15. package/dist/common/src/secret.types.d.ts +0 -3
  16. package/dist/common/src/socket.types.d.ts +11 -3
  17. package/dist/common/src/utils/validation.d.ts +1 -1
  18. package/dist/index.js +6 -6
  19. package/dist/typescript-client/src/ai-assistant-client.d.ts +66 -0
  20. package/dist/typescript-client/src/ai-client.factory.d.ts +13 -0
  21. package/dist/typescript-client/src/api.manager.d.ts +4 -3
  22. package/dist/typescript-client/src/backend-function.manager.d.ts +3 -3
  23. package/dist/typescript-client/src/client-id.service.d.ts +24 -0
  24. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +4 -3
  25. package/dist/typescript-client/src/named-query.manager.d.ts +4 -3
  26. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +9 -4
  27. package/dist/typescript-client/src/rpc.manager.d.ts +4 -3
  28. package/dist/typescript-client/src/socket.manager.d.ts +11 -3
  29. package/dist/typescript-client/src/squid.d.ts +2 -1
  30. package/package.json +1 -1
  31. package/dist/common/src/integration.types.d.ts +0 -404
@@ -0,0 +1,66 @@
1
+ import { AiAssistantMutateRequest, IntegrationId, OpenAiModelName } from '@squidcloud/common';
2
+ import { Observable } from 'rxjs';
3
+ import { RpcManager } from './rpc.manager';
4
+ import { SocketManager } from './socket.manager';
5
+ import { ClientIdService } from './client-id.service';
6
+ export declare class AiAssistantClient {
7
+ private readonly clientIdService;
8
+ private readonly rpcManager;
9
+ private readonly socketManager;
10
+ private readonly integrationId;
11
+ private readonly ongoingChatRequests;
12
+ constructor(clientIdService: ClientIdService, rpcManager: RpcManager, socketManager: SocketManager, integrationId: IntegrationId);
13
+ profile(id: string): AiAssistantProfileClient;
14
+ mutate(request: AiAssistantMutateRequest): Promise<void>;
15
+ chat(profileId: string, prompt: string): Observable<string>;
16
+ private handleChatResponse;
17
+ }
18
+ declare class AiAssistantProfileClient {
19
+ private readonly client;
20
+ private readonly integrationId;
21
+ private readonly profileId;
22
+ constructor(client: AiAssistantClient, integrationId: IntegrationId, profileId: string);
23
+ chat(prompt: string): Observable<string>;
24
+ context(id?: string): AiAssistantContextClient;
25
+ instruction(id?: string): AiAssistantInstructionClient;
26
+ insert(data: {
27
+ modelName: OpenAiModelName;
28
+ strictContext: boolean;
29
+ }): Promise<void>;
30
+ update(data: {
31
+ modelName?: OpenAiModelName;
32
+ strictContext?: true;
33
+ }): Promise<void>;
34
+ delete(): Promise<void>;
35
+ }
36
+ declare class AiAssistantContextClient {
37
+ private readonly client;
38
+ private readonly integrationId;
39
+ private readonly profileId;
40
+ private readonly id;
41
+ constructor(client: AiAssistantClient, integrationId: IntegrationId, profileId: string, id?: string);
42
+ insert(data: {
43
+ title: string;
44
+ context: string;
45
+ }): Promise<void>;
46
+ update(data: {
47
+ title?: string;
48
+ context?: string;
49
+ }): Promise<void>;
50
+ delete(): Promise<void>;
51
+ }
52
+ declare class AiAssistantInstructionClient {
53
+ private readonly client;
54
+ private readonly integrationId;
55
+ private readonly profileId;
56
+ private readonly id;
57
+ constructor(client: AiAssistantClient, integrationId: IntegrationId, profileId: string, id?: string);
58
+ insert(data: {
59
+ instruction: string;
60
+ }): Promise<void>;
61
+ update(data: {
62
+ instruction: string;
63
+ }): Promise<void>;
64
+ delete(): Promise<void>;
65
+ }
66
+ export {};
@@ -0,0 +1,13 @@
1
+ import { IntegrationId } from '@squidcloud/common';
2
+ import { AiAssistantClient } from './ai-assistant-client';
3
+ import { RpcManager } from './rpc.manager';
4
+ import { SocketManager } from './socket.manager';
5
+ import { ClientIdService } from './client-id.service';
6
+ export declare class AiClientFactory {
7
+ private readonly clientIdService;
8
+ private readonly rpcManager;
9
+ private readonly socketManager;
10
+ private readonly assistantsMap;
11
+ constructor(clientIdService: ClientIdService, rpcManager: RpcManager, socketManager: SocketManager);
12
+ getAssistant(integrationId: IntegrationId): AiAssistantClient;
13
+ }
@@ -1,14 +1,15 @@
1
- import { ApiEndpointId, ClientId, IntegrationId } from '@squidcloud/common';
1
+ import { ApiEndpointId, IntegrationId } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
3
  import { RpcManager } from './rpc.manager';
4
4
  import { SocketManager } from './socket.manager';
5
+ import { ClientIdService } from './client-id.service';
5
6
  export declare class ApiManager {
6
- private readonly clientId;
7
+ private readonly clientIdService;
7
8
  private readonly rpcManager;
8
9
  private readonly socketManager;
9
10
  private readonly apiServerUrlOverrideMapping;
10
11
  private readonly ongoingApiExecutions;
11
- constructor(clientId: ClientId, rpcManager: RpcManager, socketManager: SocketManager, apiServerUrlOverrideMapping?: Record<IntegrationId, string>);
12
+ constructor(clientIdService: ClientIdService, rpcManager: RpcManager, socketManager: SocketManager, apiServerUrlOverrideMapping?: Record<IntegrationId, string>);
12
13
  callApiAndSubscribe<T>(integrationId: IntegrationId, endpointId: ApiEndpointId, request: Record<string, any>): Observable<T>;
13
14
  private handleApiResponse;
14
15
  }
@@ -1,13 +1,13 @@
1
- import { ClientId } from '@squidcloud/common';
2
1
  import { Observable } from 'rxjs';
3
2
  import { RpcManager } from './rpc.manager';
4
3
  import { SocketManager } from './socket.manager';
4
+ import { ClientIdService } from './client-id.service';
5
5
  export declare class BackendFunctionManager {
6
- private readonly clientId;
6
+ private readonly clientIdService;
7
7
  private readonly rpcManager;
8
8
  private readonly socketManager;
9
9
  private readonly ongoingFunctionExecutions;
10
- constructor(clientId: ClientId, rpcManager: RpcManager, socketManager: SocketManager);
10
+ constructor(clientIdService: ClientIdService, rpcManager: RpcManager, socketManager: SocketManager);
11
11
  executeFunctionAndSubscribe<T>(functionName: string, ...params: any[]): Observable<T>;
12
12
  private handleFunctionResponse;
13
13
  }
@@ -0,0 +1,24 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ClientId } from '@squidcloud/common';
3
+ import { DestructManager } from './destruct.manager';
4
+ /**
5
+ * Whenever a squid client is created, it assigns itself a client id.
6
+ * Later on, if the squid client disconnects for a specified time interval, it will generate itself a new client id.
7
+ * The client id is generated before the socket is reconnected, so it is possible that the new client id is generated,
8
+ * but the socket has not connected yet.
9
+ *
10
+ * Short-term disconnects/reconnects of the socket do not cause the client id to be regenerated.
11
+ */
12
+ export declare class ClientIdService {
13
+ private readonly destructManager;
14
+ private readonly clientTooOldSubject;
15
+ private clientId;
16
+ constructor(destructManager: DestructManager);
17
+ observeClientTooOld(): Observable<void>;
18
+ /** there was a long-term disconnection of the socket */
19
+ notifyClientTooOld(): void;
20
+ notifyClientReadyToBeRegenerated(): void;
21
+ observeClientReadyToBeRegenerated(): Observable<void>;
22
+ getClientId(): ClientId;
23
+ isClientTooOld(): boolean;
24
+ }
@@ -1,11 +1,12 @@
1
- import { ClientId, IntegrationId, LockManager, MutateResponse, Mutation } from '@squidcloud/common';
1
+ import { IntegrationId, LockManager, MutateResponse, Mutation } from '@squidcloud/common';
2
2
  import { QuerySubscriptionManager } from '../query/query-subscription.manager';
3
3
  import { RpcManager } from '../rpc.manager';
4
+ import { ClientIdService } from '../client-id.service';
4
5
  export declare class MutationSender {
5
- private readonly clientId;
6
+ private readonly clientIdService;
6
7
  private readonly rpcManager;
7
8
  private readonly lockManager;
8
9
  private readonly querySubscriptionManager;
9
- constructor(clientId: ClientId, rpcManager: RpcManager, lockManager: LockManager, querySubscriptionManager: QuerySubscriptionManager);
10
+ constructor(clientIdService: ClientIdService, rpcManager: RpcManager, lockManager: LockManager, querySubscriptionManager: QuerySubscriptionManager);
10
11
  sendMutations(mutations: Array<Mutation>, integrationId: IntegrationId): Promise<MutateResponse>;
11
12
  }
@@ -1,13 +1,14 @@
1
- import { ClientId, IntegrationId, QueryName } from '@squidcloud/common';
1
+ import { IntegrationId, QueryName } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
3
  import { RpcManager } from './rpc.manager';
4
4
  import { SocketManager } from './socket.manager';
5
+ import { ClientIdService } from './client-id.service';
5
6
  export declare class NamedQueryManager {
6
- private readonly clientId;
7
+ private readonly clientIdService;
7
8
  private readonly rpcManager;
8
9
  private readonly socketManager;
9
10
  private readonly ongoingNamedQueryExecutions;
10
- constructor(clientId: ClientId, rpcManager: RpcManager, socketManager: SocketManager);
11
+ constructor(clientIdService: ClientIdService, rpcManager: RpcManager, socketManager: SocketManager);
11
12
  executeNamedQueryAndSubscribe<T>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>): Observable<T>;
12
13
  private handleNamedQueryResponse;
13
14
  }
@@ -1,13 +1,14 @@
1
- import { ClientId, ClientRequestId, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
1
+ import { ClientRequestId, Query, QuerySubscriptionId, SquidDocId, SquidDocument } from '@squidcloud/common';
2
2
  import { BehaviorSubject, Observable, Subject } from 'rxjs';
3
3
  import { DestructManager } from '../destruct.manager';
4
4
  import DocumentIdentityService from '../document-identity.service';
5
5
  import { DocumentStore } from '../document-store';
6
6
  import { RpcManager } from '../rpc.manager';
7
7
  import { Alias, JoinCondition } from './query.types';
8
+ import { ClientIdService } from '../client-id.service';
8
9
  export declare class QuerySubscriptionManager {
9
10
  private readonly rpcManager;
10
- private readonly clientId;
11
+ private readonly clientIdService;
11
12
  private readonly documentStore;
12
13
  private readonly destructManager;
13
14
  private readonly documentIdentityService;
@@ -22,7 +23,7 @@ export declare class QuerySubscriptionManager {
22
23
  private readonly clientRequestIdToLocalDocuments;
23
24
  private readonly localDocumentToClientRequestIds;
24
25
  private readonly queryMappingManager;
25
- constructor(rpcManager: RpcManager, clientId: ClientId, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
26
+ constructor(rpcManager: RpcManager, clientIdService: ClientIdService, documentStore: DocumentStore, destructManager: DestructManager, documentIdentityService: DocumentIdentityService);
26
27
  hasOngoingQuery(clientRequestId: ClientRequestId): boolean;
27
28
  getQuery(clientRequestId: ClientRequestId): Query;
28
29
  setGotResponseFromServer(clientRequestId: ClientRequestId): void;
@@ -38,7 +39,7 @@ export declare class QuerySubscriptionManager {
38
39
  notifyAllSubscriptions(clientRequestIds: ClientRequestId[]): void;
39
40
  processQuery(query: Query, rootAlias: Alias, joins: Record<string, Query>, joinConditions: Record<Alias, JoinCondition>, subscribe: boolean): Observable<Array<Record<Alias, SquidDocument | undefined>>>;
40
41
  hasOngoingQueryForDocId(squidDocId: string): boolean;
41
- private removeClientRequestId;
42
+ private removeClientRequestIdMapping;
42
43
  waitForAllQueriesToFinish(): Promise<void>;
43
44
  private registerQueryFinalizer;
44
45
  /** Creates a graph of ongoing queries and returns the root of the graph. */
@@ -55,5 +56,9 @@ export declare class QuerySubscriptionManager {
55
56
  hasSubscription(clientRequestId: ClientRequestId): boolean;
56
57
  /** Sends the query request to the server and makes sure to unsubscribe once the subject completes. */
57
58
  private sendQueryToServer;
59
+ /**
60
+ * naive way to refresh queries/subscriptions when we have a new client id
61
+ */
62
+ private refreshOngoingQueries;
58
63
  private migrateDocIds;
59
64
  }
@@ -1,4 +1,5 @@
1
1
  import { AuthManager } from './auth.manager';
2
+ import { ClientIdService } from './client-id.service';
2
3
  import { DestructManager } from './destruct.manager';
3
4
  import { SocketManager } from './socket.manager';
4
5
  export declare class RpcManager {
@@ -7,9 +8,10 @@ export declare class RpcManager {
7
8
  private readonly destructManager;
8
9
  private readonly headers;
9
10
  private readonly authManager;
11
+ private readonly clientIdService;
10
12
  private readonly staticHeaders;
11
13
  private readonly onGoingRpcCounter;
12
- constructor(rpcEndpoint: string, socketManager: SocketManager, destructManager: DestructManager, headers: Record<string, string>, authManager: AuthManager);
14
+ constructor(rpcEndpoint: string, socketManager: SocketManager, destructManager: DestructManager, headers: Record<string, string>, authManager: AuthManager, clientIdService: ClientIdService);
13
15
  awaitAllSettled(): Promise<void>;
14
16
  setStaticHeader(key: string, value: string): void;
15
17
  deleteStaticHeader(key: string): void;
@@ -22,6 +24,5 @@ export declare class RpcError extends Error {
22
24
  readonly statusText: string;
23
25
  readonly headers: Headers;
24
26
  readonly url: string;
25
- readonly body: string;
26
- constructor(statusCode: number, statusText: string, headers: Headers, url: string, body: string);
27
+ constructor(statusCode: number, statusText: string, headers: Headers, url: string, message?: string);
27
28
  }
@@ -1,9 +1,10 @@
1
- import { ClientId, MessageFromClient, MessageToClient } from '@squidcloud/common';
1
+ import { MessageFromClient, MessageToClient } from '@squidcloud/common';
2
2
  import { Observable } from 'rxjs';
3
3
  import { DestructManager } from './destruct.manager';
4
4
  import { AuthManager } from './auth.manager';
5
+ import { ClientIdService } from './client-id.service';
5
6
  export declare class SocketManager {
6
- private readonly clientId;
7
+ private readonly clientIdService;
7
8
  private readonly socketIoEndpoint;
8
9
  private readonly messageNotificationWrapper;
9
10
  private readonly destructManager;
@@ -14,7 +15,14 @@ export declare class SocketManager {
14
15
  private readonly seenMessageIds;
15
16
  private socket;
16
17
  private firstConnection;
17
- constructor(clientId: ClientId, socketIoEndpoint: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, extraHeaders: Record<string, string> | undefined, authManager: AuthManager);
18
+ /**
19
+ * On a client disconnecting, we wait for a bit to see if the client reconnects,
20
+ * if no reconnect happens within the timeout, we consider the client to be too old.
21
+ * This value means we wait for 5 minutes before considering the client to be too old.
22
+ * Note: we make this a function so that we can easily override it in tests.
23
+ */
24
+ private clientTooOldThreshold;
25
+ constructor(clientIdService: ClientIdService, socketIoEndpoint: string, messageNotificationWrapper: (fn: () => any) => any, destructManager: DestructManager, extraHeaders: Record<string, string> | undefined, authManager: AuthManager);
18
26
  observeNotifications<T extends MessageToClient>(): Observable<T>;
19
27
  observeConnectionReady(): Observable<boolean>;
20
28
  sendMessage(message: MessageFromClient): void;
@@ -41,7 +41,6 @@ export interface SquidOptions {
41
41
  */
42
42
  export declare class Squid {
43
43
  private readonly socketManager;
44
- private readonly clientId;
45
44
  private readonly rpcManager;
46
45
  private readonly dataManager;
47
46
  private readonly documentReferenceFactory;
@@ -59,6 +58,8 @@ export declare class Squid {
59
58
  private readonly documentIdentityService;
60
59
  private readonly distributedLockManager;
61
60
  private readonly authManager;
61
+ private readonly clientIdService;
62
+ private readonly aiClientFactory;
62
63
  private static readonly squidInstancesMap;
63
64
  /**
64
65
  * Creates a new instance of Squid with the given options.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/typescript-client/src/index.d.ts",