@sogni-ai/sogni-client 3.0.0-alpha.8 → 3.0.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +335 -0
  2. package/README.md +4 -11
  3. package/dist/Account/CurrentAccount.d.ts +3 -3
  4. package/dist/Account/CurrentAccount.js +12 -4
  5. package/dist/Account/CurrentAccount.js.map +1 -1
  6. package/dist/Account/index.d.ts +42 -13
  7. package/dist/Account/index.js +132 -29
  8. package/dist/Account/index.js.map +1 -1
  9. package/dist/Account/types.d.ts +21 -0
  10. package/dist/ApiClient/WebSocketClient/events.d.ts +55 -7
  11. package/dist/ApiClient/WebSocketClient/index.js +1 -1
  12. package/dist/ApiClient/index.d.ts +4 -2
  13. package/dist/ApiClient/index.js +12 -3
  14. package/dist/ApiClient/index.js.map +1 -1
  15. package/dist/ApiGroup.d.ts +0 -3
  16. package/dist/ApiGroup.js +0 -1
  17. package/dist/ApiGroup.js.map +1 -1
  18. package/dist/Projects/Job.d.ts +43 -0
  19. package/dist/Projects/Job.js +76 -0
  20. package/dist/Projects/Job.js.map +1 -1
  21. package/dist/Projects/Project.d.ts +1 -1
  22. package/dist/Projects/Project.js +9 -18
  23. package/dist/Projects/Project.js.map +1 -1
  24. package/dist/Projects/createJobRequestMessage.js +2 -2
  25. package/dist/Projects/createJobRequestMessage.js.map +1 -1
  26. package/dist/Projects/index.d.ts +7 -2
  27. package/dist/Projects/index.js +48 -10
  28. package/dist/Projects/index.js.map +1 -1
  29. package/dist/Projects/types/ControlNetParams.d.ts +7 -2
  30. package/dist/Projects/types/events.d.ts +6 -0
  31. package/dist/Projects/types/index.d.ts +16 -3
  32. package/dist/Projects/utils.d.ts +2 -0
  33. package/dist/Projects/utils.js +14 -0
  34. package/dist/Projects/utils.js.map +1 -0
  35. package/dist/index.d.ts +10 -6
  36. package/dist/index.js +6 -15
  37. package/dist/index.js.map +1 -1
  38. package/dist/lib/utils.d.ts +1 -0
  39. package/dist/lib/utils.js +15 -0
  40. package/dist/lib/utils.js.map +1 -1
  41. package/dist/types/token.d.ts +1 -0
  42. package/dist/types/token.js +3 -0
  43. package/dist/types/token.js.map +1 -0
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +2 -1
  46. package/dist/version.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/Account/CurrentAccount.ts +14 -6
  49. package/src/Account/index.ts +163 -59
  50. package/src/Account/types.ts +26 -0
  51. package/src/ApiClient/WebSocketClient/events.ts +59 -7
  52. package/src/ApiClient/WebSocketClient/index.ts +1 -1
  53. package/src/ApiClient/index.ts +15 -4
  54. package/src/ApiGroup.ts +0 -4
  55. package/src/Projects/Job.ts +98 -0
  56. package/src/Projects/Project.ts +11 -19
  57. package/src/Projects/createJobRequestMessage.ts +4 -2
  58. package/src/Projects/index.ts +53 -13
  59. package/src/Projects/types/ControlNetParams.ts +8 -2
  60. package/src/Projects/types/events.ts +6 -0
  61. package/src/Projects/types/index.ts +17 -3
  62. package/src/Projects/utils.ts +12 -0
  63. package/src/Stats/index.ts +2 -2
  64. package/src/index.ts +23 -19
  65. package/src/lib/utils.ts +4 -0
  66. package/src/types/token.ts +1 -0
  67. package/src/version.ts +2 -1
@@ -16,7 +16,8 @@ export type ControlNetName =
16
16
  | 'segmentation'
17
17
  | 'shuffle'
18
18
  | 'softedge'
19
- | 'tile';
19
+ | 'tile'
20
+ | 'instantid';
20
21
 
21
22
  /**
22
23
  * Raw ControlNet parameters passed to the API
@@ -53,8 +54,13 @@ export interface ControlNetParams {
53
54
  name: ControlNetName;
54
55
  /**
55
56
  * ControlNet input image
57
+ * Supported types:
58
+ * `File` - file object from input[type=file]
59
+ * `Buffer` - Node.js buffer object with image data
60
+ * `Blob` - blob object with image data
61
+ * `true` - indicates that the image is already uploaded to the server
56
62
  */
57
- image?: File | Buffer | Blob;
63
+ image?: File | Buffer | Blob | boolean;
58
64
  /**
59
65
  * ControlNet strength 0 to 1. 0 full control to prompt, 1 full control to ControlNet
60
66
  */
@@ -29,11 +29,17 @@ export interface JobEventBase {
29
29
  export interface JobInitiating extends JobEventBase {
30
30
  type: 'initiating';
31
31
  workerName: string;
32
+ positivePrompt?: string;
33
+ negativePrompt?: string;
34
+ jobIndex?: number;
32
35
  }
33
36
 
34
37
  export interface JobStarted extends JobEventBase {
35
38
  type: 'started';
36
39
  workerName: string;
40
+ positivePrompt?: string;
41
+ negativePrompt?: string;
42
+ jobIndex?: number;
37
43
  }
38
44
 
39
45
  export interface JobProgress extends JobEventBase {
@@ -1,5 +1,6 @@
1
1
  import { SupernetType } from '../../ApiClient/WebSocketClient/types';
2
2
  import { ControlNetParams } from './ControlNetParams';
3
+ import { TokenType } from '../../types/token';
3
4
 
4
5
  export interface SupportedModel {
5
6
  id: string;
@@ -102,12 +103,14 @@ export interface ProjectParams {
102
103
  */
103
104
  numberOfImages: number;
104
105
  /**
105
- * Generate images based on starting image.
106
+ * Generate images based on the starting image.
107
+ * Supported types:
106
108
  * `File` - file object from input[type=file]
107
- * `Buffer` - buffer object with image data
109
+ * `Buffer` - Node.js buffer object with image data
108
110
  * `Blob` - blob object with image data
111
+ * `true` - indicates that the image is already uploaded to the server
109
112
  */
110
- startingImage?: File | Buffer | Blob;
113
+ startingImage?: File | Buffer | Blob | boolean;
111
114
  /**
112
115
  * How strong effect of starting image should be. From 0 to 1, default 0.5
113
116
  */
@@ -141,6 +144,11 @@ export interface ProjectParams {
141
144
  * ControlNet model parameters
142
145
  */
143
146
  controlNet?: ControlNetParams;
147
+ /**
148
+ * Select which tokens to use for the project.
149
+ * If not specified, the Sogni token will be used.
150
+ */
151
+ tokenType?: TokenType;
144
152
  }
145
153
 
146
154
  export type ImageUrlParams = {
@@ -156,6 +164,10 @@ export interface EstimateRequest {
156
164
  * Network to use. Can be 'fast' or 'relaxed'
157
165
  */
158
166
  network: SupernetType;
167
+ /**
168
+ * Token type
169
+ */
170
+ tokenType?: TokenType;
159
171
  /**
160
172
  * Model ID
161
173
  */
@@ -195,3 +207,5 @@ export interface EstimateRequest {
195
207
  */
196
208
  height?: number;
197
209
  }
210
+
211
+ export type EnhancementStrength = 'light' | 'medium' | 'heavy';
@@ -0,0 +1,12 @@
1
+ import { EnhancementStrength } from './types';
2
+
3
+ export function getEnhacementStrength(strength: EnhancementStrength): number {
4
+ switch (strength) {
5
+ case 'light':
6
+ return 0.15;
7
+ case 'heavy':
8
+ return 0.49;
9
+ default:
10
+ return 0.35;
11
+ }
12
+ }
@@ -1,10 +1,10 @@
1
1
  import ApiGroup from '../ApiGroup';
2
- import { ApiReponse } from '../ApiClient';
2
+ import { ApiResponse } from '../ApiClient';
3
3
  import { LeaderboardItem, LeaderboardParams } from './types';
4
4
 
5
5
  class StatsApi extends ApiGroup {
6
6
  async leaderboard(params: LeaderboardParams) {
7
- const res = await this.client.rest.get<ApiReponse<LeaderboardItem[]>>(
7
+ const res = await this.client.rest.get<ApiResponse<LeaderboardItem[]>>(
8
8
  '/v1/leaderboard/',
9
9
  params
10
10
  );
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { AbstractProvider, JsonRpcProvider, getDefaultProvider } from 'ethers';
2
1
  // Account API
3
2
  import AccountApi from './Account';
4
3
  import CurrentAccount from './Account/CurrentAccount';
@@ -18,6 +17,7 @@ import { AvailableModel, ProjectParams, Scheduler, TimeStepSpacing } from './Pro
18
17
  import StatsApi from './Stats';
19
18
  // Base Types
20
19
  import ErrorData from './types/ErrorData';
20
+ import { TokenType } from './types/token';
21
21
 
22
22
  export type {
23
23
  AvailableModel,
@@ -29,7 +29,8 @@ export type {
29
29
  ProjectStatus,
30
30
  Scheduler,
31
31
  SupernetType,
32
- TimeStepSpacing
32
+ TimeStepSpacing,
33
+ TokenType
33
34
  };
34
35
 
35
36
  export { ApiError, CurrentAccount, Job, Project };
@@ -49,6 +50,13 @@ export interface SogniClientConfig {
49
50
  * @internal
50
51
  */
51
52
  socketEndpoint?: string;
53
+ /**
54
+ * Disable WebSocket connection. Useful for testing or when WebSocket is not needed.
55
+ * Note that many may not work without WebSocket connection.
56
+ * @experimental
57
+ * @internal
58
+ */
59
+ disableSocket?: boolean;
52
60
  /**
53
61
  * Which network to use after logging in. Can be 'fast' or 'relaxed'
54
62
  */
@@ -62,10 +70,6 @@ export interface SogniClientConfig {
62
70
  * @default 'warn'
63
71
  **/
64
72
  logLevel?: LogLevel;
65
- /**
66
- * If provided, the client will connect to this JSON-RPC endpoint to interact with the blockchain
67
- */
68
- jsonRpcUrl?: string;
69
73
  /**
70
74
  * If true, the client will connect to the testnet. Ignored if jsonRpcUrl is provided
71
75
  */
@@ -92,7 +96,7 @@ export class SogniClient {
92
96
  }
93
97
 
94
98
  /**
95
- * Instance creation may involve async operations, so we use a static method
99
+ * Create client instance, with default configuration
96
100
  * @param config
97
101
  */
98
102
  static async createInstance(config: SogniClientConfig): Promise<SogniClient> {
@@ -100,21 +104,21 @@ export class SogniClient {
100
104
  const socketEndpoint = config.socketEndpoint || 'wss://socket.sogni.ai';
101
105
  const network = config.network || 'fast';
102
106
  const logger = config.logger || new DefaultLogger(config.logLevel || 'warn');
103
- const isTestnet = config.testnet !== undefined ? config.testnet : true;
107
+ const isTestnet = config.testnet !== undefined ? config.testnet : false;
104
108
 
105
- const client = new ApiClient(restEndpoint, socketEndpoint, config.appId, network, logger);
106
- let provider: AbstractProvider;
107
- if ('jsonRpcUrl' in config) {
108
- provider = new JsonRpcProvider(config.jsonRpcUrl);
109
- } else {
110
- provider = getDefaultProvider(isTestnet ? 84532 : 8453);
111
- }
112
- const chainId = await provider.getNetwork().then((network) => network.chainId);
109
+ const client = new ApiClient(
110
+ restEndpoint,
111
+ socketEndpoint,
112
+ config.appId,
113
+ network,
114
+ logger,
115
+ config.disableSocket
116
+ );
113
117
  const eip712 = new EIP712Helper({
114
- name: 'Sogni-testnet',
118
+ name: isTestnet ? 'Sogni-testnet' : 'Sogni AI',
115
119
  version: '1',
116
- chainId: chainId.toString()
120
+ chainId: isTestnet ? '84532' : '8453'
117
121
  });
118
- return new SogniClient({ client, provider, eip712 });
122
+ return new SogniClient({ client, eip712 });
119
123
  }
120
124
  }
package/src/lib/utils.ts CHANGED
@@ -15,3 +15,7 @@ export function decodeRefreshToken(token: string) {
15
15
  expiresAt: new Date(data.exp * 1000)
16
16
  };
17
17
  }
18
+
19
+ export async function delay(ms: number) {
20
+ return new Promise((resolve) => setTimeout(resolve, ms));
21
+ }
@@ -0,0 +1 @@
1
+ export type TokenType = 'sogni' | 'spark';
package/src/version.ts CHANGED
@@ -1 +1,2 @@
1
- export const LIB_VERSION = "1.0.0-alpha.4";
1
+ import { version } from '../package.json';
2
+ export const LIB_VERSION = version;