@sogni-ai/sogni-client 4.2.0-alpha.2 → 4.2.0-alpha.21
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.
- package/CHANGELOG.md +148 -0
- package/CLAUDE.md +25 -3
- package/README.md +411 -136
- package/dist/Account/index.d.ts +4 -2
- package/dist/Account/index.js +27 -23
- package/dist/Account/index.js.map +1 -1
- package/dist/Account/types.d.ts +7 -0
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.d.ts +3 -1
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js +26 -2
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/eventSubscriptions.d.ts +33 -0
- package/dist/ApiClient/WebSocketClient/eventSubscriptions.js +39 -0
- package/dist/ApiClient/WebSocketClient/eventSubscriptions.js.map +1 -0
- package/dist/ApiClient/WebSocketClient/events.d.ts +24 -7
- package/dist/ApiClient/WebSocketClient/index.d.ts +5 -1
- package/dist/ApiClient/WebSocketClient/index.js +24 -1
- package/dist/ApiClient/WebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/messages.d.ts +2 -0
- package/dist/ApiClient/WebSocketClient/types.d.ts +2 -0
- package/dist/ApiClient/index.d.ts +6 -1
- package/dist/ApiClient/index.js +7 -3
- package/dist/ApiClient/index.js.map +1 -1
- package/dist/Chat/ChatTools.d.ts +5 -49
- package/dist/Chat/ChatTools.js +311 -88
- package/dist/Chat/ChatTools.js.map +1 -1
- package/dist/Chat/index.d.ts +11 -2
- package/dist/Chat/index.js +78 -4
- package/dist/Chat/index.js.map +1 -1
- package/dist/Chat/modelRouting.d.ts +100 -0
- package/dist/Chat/modelRouting.js +441 -0
- package/dist/Chat/modelRouting.js.map +1 -0
- package/dist/Chat/sogniHostedTools.generated.json +529 -0
- package/dist/Chat/tools.d.ts +9 -55
- package/dist/Chat/tools.js +72 -228
- package/dist/Chat/tools.js.map +1 -1
- package/dist/Chat/types.d.ts +91 -2
- package/dist/CreativeWorkflows/index.d.ts +23 -0
- package/dist/CreativeWorkflows/index.js +274 -0
- package/dist/CreativeWorkflows/index.js.map +1 -0
- package/dist/CreativeWorkflows/types.d.ts +106 -0
- package/dist/CreativeWorkflows/types.js +3 -0
- package/dist/CreativeWorkflows/types.js.map +1 -0
- package/dist/Projects/Job.d.ts +6 -0
- package/dist/Projects/Job.js +60 -5
- package/dist/Projects/Job.js.map +1 -1
- package/dist/Projects/Project.js +15 -3
- package/dist/Projects/Project.js.map +1 -1
- package/dist/Projects/createJobRequestMessage.js +140 -6
- package/dist/Projects/createJobRequestMessage.js.map +1 -1
- package/dist/Projects/index.d.ts +10 -1
- package/dist/Projects/index.js +197 -58
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/types/ModelOptions.d.ts +3 -3
- package/dist/Projects/types/ModelOptions.js +12 -5
- package/dist/Projects/types/ModelOptions.js.map +1 -1
- package/dist/Projects/types/ModelTiersRaw.d.ts +7 -7
- package/dist/Projects/types/RawProject.d.ts +2 -0
- package/dist/Projects/types/events.d.ts +5 -4
- package/dist/Projects/types/index.d.ts +77 -7
- package/dist/Projects/types/index.js.map +1 -1
- package/dist/Projects/utils/index.d.ts +8 -1
- package/dist/Projects/utils/index.js +22 -8
- package/dist/Projects/utils/index.js.map +1 -1
- package/dist/index.d.ts +28 -3
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/RestClient.d.ts +4 -1
- package/dist/lib/RestClient.js +17 -9
- package/dist/lib/RestClient.js.map +1 -1
- package/dist/lib/mediaValidation.d.ts +16 -0
- package/dist/lib/mediaValidation.js +280 -0
- package/dist/lib/mediaValidation.js.map +1 -0
- package/dist/lib/validation.d.ts +6 -1
- package/dist/lib/validation.js +28 -2
- package/dist/lib/validation.js.map +1 -1
- package/llms-full.txt +372 -133
- package/llms.txt +197 -86
- package/package.json +13 -4
- package/src/Account/index.ts +22 -2
- package/src/Account/types.ts +7 -0
- package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/index.ts +47 -3
- package/src/ApiClient/WebSocketClient/eventSubscriptions.ts +92 -0
- package/src/ApiClient/WebSocketClient/events.ts +25 -7
- package/src/ApiClient/WebSocketClient/index.ts +33 -1
- package/src/ApiClient/WebSocketClient/messages.ts +2 -0
- package/src/ApiClient/WebSocketClient/types.ts +2 -0
- package/src/ApiClient/index.ts +32 -2
- package/src/Chat/ChatTools.ts +395 -95
- package/src/Chat/index.ts +149 -5
- package/src/Chat/modelRouting.ts +602 -0
- package/src/Chat/sogniHostedTools.generated.json +529 -0
- package/src/Chat/tools.ts +98 -245
- package/src/Chat/types.ts +100 -2
- package/src/CreativeWorkflows/index.ts +290 -0
- package/src/CreativeWorkflows/types.ts +134 -0
- package/src/Projects/Job.ts +76 -5
- package/src/Projects/Project.ts +13 -3
- package/src/Projects/createJobRequestMessage.ts +152 -13
- package/src/Projects/index.ts +230 -52
- package/src/Projects/types/ModelOptions.ts +15 -8
- package/src/Projects/types/ModelTiersRaw.ts +7 -7
- package/src/Projects/types/RawProject.ts +2 -0
- package/src/Projects/types/events.ts +5 -4
- package/src/Projects/types/index.ts +86 -6
- package/src/Projects/utils/index.ts +24 -8
- package/src/index.ts +93 -0
- package/src/lib/RestClient.ts +15 -5
- package/src/lib/mediaValidation.ts +367 -0
- package/src/lib/validation.ts +38 -2
package/dist/ApiClient/index.js
CHANGED
|
@@ -23,11 +23,12 @@ class ApiError extends Error {
|
|
|
23
23
|
}
|
|
24
24
|
exports.ApiError = ApiError;
|
|
25
25
|
class ApiClient extends TypedEventEmitter_1.default {
|
|
26
|
-
constructor({ baseUrl, socketUrl, appId, networkType, authType, logger, disableSocket = false, multiInstance = false }) {
|
|
26
|
+
constructor({ baseUrl, socketUrl, appId, appSource, socketEventSubscriptions, networkType, authType, logger, disableSocket = false, multiInstance = false }) {
|
|
27
27
|
super();
|
|
28
28
|
this._reconnectAttempts = WS_RECONNECT_ATTEMPTS;
|
|
29
29
|
this._disableSocket = false;
|
|
30
30
|
this.appId = appId;
|
|
31
|
+
this.appSource = (appSource === null || appSource === void 0 ? void 0 : appSource.trim()) || undefined;
|
|
31
32
|
this.logger = logger;
|
|
32
33
|
if (authType === 'apiKey') {
|
|
33
34
|
this._auth = new ApiKeyAuthManager_1.default(logger);
|
|
@@ -42,10 +43,10 @@ class ApiClient extends TypedEventEmitter_1.default {
|
|
|
42
43
|
const supportMultiInstance = !isNodejs_1.default && this._auth instanceof CookieAuthManager_1.default;
|
|
43
44
|
if (supportMultiInstance && multiInstance) {
|
|
44
45
|
// Use coordinated WebSocket client to share single connection between tabs
|
|
45
|
-
this._socket = new BrowserWebSocketClient_1.default(socketUrl, this._auth, appId, networkType, logger);
|
|
46
|
+
this._socket = new BrowserWebSocketClient_1.default(socketUrl, this._auth, appId, networkType, logger, this.appSource, socketEventSubscriptions);
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
this._socket = new WebSocketClient_1.default(socketUrl, this._auth, appId, networkType, logger);
|
|
49
|
+
this._socket = new WebSocketClient_1.default(socketUrl, this._auth, appId, networkType, logger, this.appSource, socketEventSubscriptions);
|
|
49
50
|
}
|
|
50
51
|
this._disableSocket = disableSocket;
|
|
51
52
|
this._auth.on('updated', this.handleAuthUpdated.bind(this));
|
|
@@ -67,6 +68,9 @@ class ApiClient extends TypedEventEmitter_1.default {
|
|
|
67
68
|
get socketEnabled() {
|
|
68
69
|
return !this._disableSocket;
|
|
69
70
|
}
|
|
71
|
+
setSocketEventSubscriptions(update) {
|
|
72
|
+
return this.socket.setSocketEventSubscriptions(update);
|
|
73
|
+
}
|
|
70
74
|
handleSocketConnect({ network }) {
|
|
71
75
|
this._reconnectAttempts = WS_RECONNECT_ATTEMPTS;
|
|
72
76
|
this.emit('connected', { network });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ApiClient/index.ts"],"names":[],"mappings":";;;;;;AAAA,m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CAAC;YACxD,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,kBAAkB,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,kBAAkB,GAAG,qBAAqB,CAAC;YAChD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,iBAAiB,CAAC,eAAwB;QACxC,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAC5D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAC1B,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;QAClC,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAChC,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AAED,kBAAe,SAAS,CAAC"}
|
package/dist/Chat/ChatTools.d.ts
CHANGED
|
@@ -1,65 +1,21 @@
|
|
|
1
1
|
import type ProjectsApi from '../Projects';
|
|
2
2
|
import { ToolCall, ToolExecutionOptions, ToolExecutionProgress, ToolExecutionResult } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* API for executing Sogni platform tool calls (image, video, music generation).
|
|
5
|
-
*
|
|
6
|
-
* Accessed via `sogni.chat.tools`. Provides methods to execute tool calls returned
|
|
7
|
-
* by the LLM, mapping them to `sogni.projects.create()` calls automatically.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // Execute a single tool call
|
|
12
|
-
* const result = await sogni.chat.tools.execute(toolCall, {
|
|
13
|
-
* tokenType: 'sogni',
|
|
14
|
-
* onProgress: (p) => console.log(`${p.status}: ${p.percent}%`),
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* // Execute all tool calls from a completion
|
|
18
|
-
* const results = await sogni.chat.tools.executeAll(result.tool_calls, {
|
|
19
|
-
* onToolCall: async (tc) => myCustomHandler(tc), // for non-Sogni tools
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
3
|
declare class ChatToolsApi {
|
|
24
4
|
private projects;
|
|
25
5
|
constructor(projects: ProjectsApi);
|
|
26
|
-
/**
|
|
27
|
-
* Execute a single Sogni platform tool call.
|
|
28
|
-
*
|
|
29
|
-
* Maps tool call arguments to `sogni.projects.create()`, waits for the media
|
|
30
|
-
* generation to complete, and returns the result URLs.
|
|
31
|
-
*
|
|
32
|
-
* @throws Error if the tool call is not a Sogni tool (use `isSogniToolCall()` to check first)
|
|
33
|
-
*/
|
|
34
6
|
execute(toolCall: ToolCall, options?: ToolExecutionOptions): Promise<ToolExecutionResult>;
|
|
35
|
-
/**
|
|
36
|
-
* Execute multiple tool calls from a single LLM response.
|
|
37
|
-
*
|
|
38
|
-
* Sogni tool calls (prefixed with `sogni_`) are executed automatically via
|
|
39
|
-
* `projects.create()`. Non-Sogni tool calls are delegated to the `onToolCall`
|
|
40
|
-
* callback if provided, or returned as errors.
|
|
41
|
-
*
|
|
42
|
-
* @param toolCalls - Array of tool calls from `result.tool_calls`
|
|
43
|
-
* @param options - Execution options plus optional handler for non-Sogni tools
|
|
44
|
-
*/
|
|
45
7
|
executeAll(toolCalls: ToolCall[], options?: ToolExecutionOptions & {
|
|
46
|
-
/** Handler for non-Sogni tool calls. Must return the tool result content string. */
|
|
47
8
|
onToolCall?: (toolCall: ToolCall) => Promise<string>;
|
|
48
|
-
/** Per-tool progress callback (wraps the per-tool onProgress with tool identity). */
|
|
49
9
|
onToolProgress?: (toolCall: ToolCall, progress: ToolExecutionProgress) => void;
|
|
50
10
|
}): Promise<ToolExecutionResult[]>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* Falls back to the model with the most available workers.
|
|
54
|
-
*/
|
|
55
|
-
private getDefaultModel;
|
|
56
|
-
/**
|
|
57
|
-
* Create a project, wait for completion with timeout, track per-job progress,
|
|
58
|
-
* and clean up on failure or timeout.
|
|
59
|
-
*/
|
|
11
|
+
private getAvailableModels;
|
|
12
|
+
private selectModel;
|
|
60
13
|
private executeProject;
|
|
61
14
|
private executeImageGeneration;
|
|
15
|
+
private executeImageEdit;
|
|
62
16
|
private executeVideoGeneration;
|
|
17
|
+
private executeSoundToVideo;
|
|
18
|
+
private executeVideoToVideo;
|
|
63
19
|
private executeMusicGeneration;
|
|
64
20
|
private makeErrorResult;
|
|
65
21
|
}
|
package/dist/Chat/ChatTools.js
CHANGED
|
@@ -9,41 +9,47 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const validation_1 = require("../lib/validation");
|
|
13
|
+
const mediaValidation_1 = require("../lib/mediaValidation");
|
|
14
|
+
const modelRouting_1 = require("./modelRouting");
|
|
12
15
|
const tools_1 = require("./tools");
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
const DEFAULT_TIMEOUT = 30 * 60 * 1000;
|
|
17
|
+
const MAX_SOGNI_TOOL_CALLS_PER_ROUND = 8;
|
|
18
|
+
const MAX_INPUT_MEDIA_BYTES = {
|
|
19
|
+
image: 20 * 1024 * 1024,
|
|
20
|
+
audio: 50 * 1024 * 1024,
|
|
21
|
+
video: 100 * 1024 * 1024
|
|
22
|
+
};
|
|
23
|
+
function getVariationCount(args, options) {
|
|
24
|
+
return (0, modelRouting_1.getHostedVariationCount)(args, options === null || options === void 0 ? void 0 : options.numberOfMedia);
|
|
25
|
+
}
|
|
26
|
+
function getStringArg(value) {
|
|
27
|
+
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
|
|
28
|
+
}
|
|
29
|
+
function normalizeImageOutputFormat(value) {
|
|
30
|
+
var _a;
|
|
31
|
+
const outputFormat = (_a = getStringArg(value)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
32
|
+
if (!outputFormat)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (outputFormat === 'jpeg')
|
|
35
|
+
return 'jpg';
|
|
36
|
+
return outputFormat === 'png' || outputFormat === 'jpg' || outputFormat === 'webp'
|
|
37
|
+
? outputFormat
|
|
38
|
+
: undefined;
|
|
39
|
+
}
|
|
40
|
+
function applyHostedImageOptions(projectParams, args) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const gptImageQuality = getStringArg((_a = args.gpt_image_quality) !== null && _a !== void 0 ? _a : args.gptImageQuality);
|
|
43
|
+
if (gptImageQuality)
|
|
44
|
+
projectParams.gptImageQuality = gptImageQuality.toLowerCase();
|
|
45
|
+
const outputFormat = normalizeImageOutputFormat((_b = args.output_format) !== null && _b !== void 0 ? _b : args.outputFormat);
|
|
46
|
+
if (outputFormat)
|
|
47
|
+
projectParams.outputFormat = outputFormat;
|
|
48
|
+
}
|
|
35
49
|
class ChatToolsApi {
|
|
36
50
|
constructor(projects) {
|
|
37
51
|
this.projects = projects;
|
|
38
52
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Execute a single Sogni platform tool call.
|
|
41
|
-
*
|
|
42
|
-
* Maps tool call arguments to `sogni.projects.create()`, waits for the media
|
|
43
|
-
* generation to complete, and returns the result URLs.
|
|
44
|
-
*
|
|
45
|
-
* @throws Error if the tool call is not a Sogni tool (use `isSogniToolCall()` to check first)
|
|
46
|
-
*/
|
|
47
53
|
execute(toolCall, options) {
|
|
48
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
55
|
if (!this.projects) {
|
|
@@ -55,11 +61,18 @@ class ChatToolsApi {
|
|
|
55
61
|
const args = (0, tools_1.parseToolCallArguments)(toolCall);
|
|
56
62
|
const name = toolCall.function.name;
|
|
57
63
|
try {
|
|
64
|
+
(0, modelRouting_1.assertHostedToolArguments)(tools_1.SogniTools.all, name, args);
|
|
58
65
|
switch (name) {
|
|
59
66
|
case 'sogni_generate_image':
|
|
60
67
|
return yield this.executeImageGeneration(toolCall, args, options);
|
|
68
|
+
case 'sogni_edit_image':
|
|
69
|
+
return yield this.executeImageEdit(toolCall, args, options);
|
|
61
70
|
case 'sogni_generate_video':
|
|
62
71
|
return yield this.executeVideoGeneration(toolCall, args, options);
|
|
72
|
+
case 'sogni_sound_to_video':
|
|
73
|
+
return yield this.executeSoundToVideo(toolCall, args, options);
|
|
74
|
+
case 'sogni_video_to_video':
|
|
75
|
+
return yield this.executeVideoToVideo(toolCall, args, options);
|
|
63
76
|
case 'sogni_generate_music':
|
|
64
77
|
return yield this.executeMusicGeneration(toolCall, args, options);
|
|
65
78
|
default:
|
|
@@ -67,23 +80,17 @@ class ChatToolsApi {
|
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
82
|
catch (err) {
|
|
70
|
-
const error =
|
|
83
|
+
const error = (0, modelRouting_1.serializeUnknownError)(err);
|
|
71
84
|
return this.makeErrorResult(toolCall, error);
|
|
72
85
|
}
|
|
73
86
|
});
|
|
74
87
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Execute multiple tool calls from a single LLM response.
|
|
77
|
-
*
|
|
78
|
-
* Sogni tool calls (prefixed with `sogni_`) are executed automatically via
|
|
79
|
-
* `projects.create()`. Non-Sogni tool calls are delegated to the `onToolCall`
|
|
80
|
-
* callback if provided, or returned as errors.
|
|
81
|
-
*
|
|
82
|
-
* @param toolCalls - Array of tool calls from `result.tool_calls`
|
|
83
|
-
* @param options - Execution options plus optional handler for non-Sogni tools
|
|
84
|
-
*/
|
|
85
88
|
executeAll(toolCalls, options) {
|
|
86
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const sogniToolCallCount = toolCalls.filter((toolCall) => (0, tools_1.isSogniToolCall)(toolCall)).length;
|
|
91
|
+
if (sogniToolCallCount > MAX_SOGNI_TOOL_CALLS_PER_ROUND) {
|
|
92
|
+
throw new Error(`Too many Sogni tool calls in a single round (${sogniToolCallCount}); maximum is ${MAX_SOGNI_TOOL_CALLS_PER_ROUND}`);
|
|
93
|
+
}
|
|
87
94
|
const results = [];
|
|
88
95
|
for (const toolCall of toolCalls) {
|
|
89
96
|
if ((0, tools_1.isSogniToolCall)(toolCall)) {
|
|
@@ -110,7 +117,7 @@ class ChatToolsApi {
|
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
119
|
catch (err) {
|
|
113
|
-
const error =
|
|
120
|
+
const error = (0, modelRouting_1.serializeUnknownError)(err);
|
|
114
121
|
results.push(this.makeErrorResult(toolCall, error));
|
|
115
122
|
}
|
|
116
123
|
}
|
|
@@ -121,34 +128,17 @@ class ChatToolsApi {
|
|
|
121
128
|
return results;
|
|
122
129
|
});
|
|
123
130
|
}
|
|
124
|
-
|
|
125
|
-
* Get the default model for a media type. For video, prefers LTX-2.3 t2v models.
|
|
126
|
-
* Falls back to the model with the most available workers.
|
|
127
|
-
*/
|
|
128
|
-
getDefaultModel(mediaType) {
|
|
131
|
+
getAvailableModels() {
|
|
129
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const ltx2 = candidates.filter((m) => m.id.includes('ltx2') && m.id.includes('t2v'));
|
|
138
|
-
if (ltx2.length > 0) {
|
|
139
|
-
ltx2.sort((a, b) => b.workerCount - a.workerCount);
|
|
140
|
-
return ltx2[0].id;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// Default: pick the model with most workers (highest availability)
|
|
144
|
-
candidates.sort((a, b) => b.workerCount - a.workerCount);
|
|
145
|
-
return candidates[0].id;
|
|
133
|
+
return this.projects.waitForModels(10000);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
selectModel(options) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const models = yield this.getAvailableModels();
|
|
139
|
+
return (0, modelRouting_1.selectBackboneModel)(models, options).modelId;
|
|
146
140
|
});
|
|
147
141
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Create a project, wait for completion with timeout, track per-job progress,
|
|
150
|
-
* and clean up on failure or timeout.
|
|
151
|
-
*/
|
|
152
142
|
executeProject(toolCall, mediaType, modelId, projectParams, prompt, options) {
|
|
153
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
144
|
var _a, _b, _c, _d, _e;
|
|
@@ -159,7 +149,6 @@ class ChatToolsApi {
|
|
|
159
149
|
let jobsCompleted = 0;
|
|
160
150
|
let jobsFailed = 0;
|
|
161
151
|
const totalJobs = projectParams.numberOfMedia || 1;
|
|
162
|
-
// Track per-job progress via project events
|
|
163
152
|
const onJobCompleted = () => {
|
|
164
153
|
var _a;
|
|
165
154
|
jobsCompleted++;
|
|
@@ -169,7 +158,6 @@ class ChatToolsApi {
|
|
|
169
158
|
const onJobFailed = () => {
|
|
170
159
|
jobsFailed++;
|
|
171
160
|
};
|
|
172
|
-
// Track step-level progress via project progress event
|
|
173
161
|
const onProgress = (percent) => {
|
|
174
162
|
var _a;
|
|
175
163
|
(_a = options === null || options === void 0 ? void 0 : options.onProgress) === null || _a === void 0 ? void 0 : _a.call(options, {
|
|
@@ -208,12 +196,11 @@ class ChatToolsApi {
|
|
|
208
196
|
};
|
|
209
197
|
}
|
|
210
198
|
catch (err) {
|
|
211
|
-
// Attempt to cancel the project on timeout to free worker resources
|
|
212
199
|
try {
|
|
213
200
|
yield project.cancel();
|
|
214
201
|
}
|
|
215
202
|
catch (_f) {
|
|
216
|
-
|
|
203
|
+
// best-effort cleanup
|
|
217
204
|
}
|
|
218
205
|
(_e = options === null || options === void 0 ? void 0 : options.onProgress) === null || _e === void 0 ? void 0 : _e.call(options, { status: 'failed', percent: 0 });
|
|
219
206
|
throw err;
|
|
@@ -229,12 +216,15 @@ class ChatToolsApi {
|
|
|
229
216
|
}
|
|
230
217
|
executeImageGeneration(toolCall, args, options) {
|
|
231
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
const modelId =
|
|
219
|
+
const modelId = yield this.selectModel({
|
|
220
|
+
mediaType: 'image',
|
|
221
|
+
requestedModel: (0, modelRouting_1.resolveHostedToolModelSelector)('sogni_generate_image', args)
|
|
222
|
+
});
|
|
233
223
|
const projectParams = {
|
|
234
224
|
type: 'image',
|
|
235
225
|
modelId,
|
|
236
226
|
positivePrompt: args.prompt,
|
|
237
|
-
numberOfMedia: (
|
|
227
|
+
numberOfMedia: getVariationCount(args, options)
|
|
238
228
|
};
|
|
239
229
|
if (args.negative_prompt)
|
|
240
230
|
projectParams.negativePrompt = args.negative_prompt;
|
|
@@ -247,6 +237,48 @@ class ChatToolsApi {
|
|
|
247
237
|
projectParams.steps = args.steps;
|
|
248
238
|
if (args.seed !== undefined)
|
|
249
239
|
projectParams.seed = args.seed;
|
|
240
|
+
applyHostedImageOptions(projectParams, args);
|
|
241
|
+
if (options === null || options === void 0 ? void 0 : options.tokenType)
|
|
242
|
+
projectParams.tokenType = options.tokenType;
|
|
243
|
+
if (options === null || options === void 0 ? void 0 : options.network)
|
|
244
|
+
projectParams.network = options.network;
|
|
245
|
+
return this.executeProject(toolCall, 'image', modelId, projectParams, args.prompt, options);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
executeImageEdit(toolCall, args, options) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
const sourceImageUrl = (0, modelRouting_1.isNonEmptyString)(args.source_image_url) ? args.source_image_url : null;
|
|
251
|
+
const referenceImageUrls = (0, modelRouting_1.asStringArray)(args.reference_image_urls);
|
|
252
|
+
const inputUrls = [...(sourceImageUrl ? [sourceImageUrl] : []), ...referenceImageUrls];
|
|
253
|
+
if (inputUrls.length === 0) {
|
|
254
|
+
throw new Error('sogni_edit_image requires source_image_url or reference_image_urls');
|
|
255
|
+
}
|
|
256
|
+
const modelId = yield this.selectModel({
|
|
257
|
+
mediaType: 'image',
|
|
258
|
+
requestedModel: (0, modelRouting_1.resolveHostedToolModelSelector)('sogni_edit_image', args),
|
|
259
|
+
filter: modelRouting_1.isEditImageModel
|
|
260
|
+
});
|
|
261
|
+
const maxContextImages = (0, validation_1.getMaxContextImages)(modelId);
|
|
262
|
+
const contextImages = yield Promise.all(inputUrls.slice(0, maxContextImages).map((url) => (0, mediaValidation_1.parseInlineMediaDataUri)(url, 'image', {
|
|
263
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.image
|
|
264
|
+
}).blob));
|
|
265
|
+
const projectParams = {
|
|
266
|
+
type: 'image',
|
|
267
|
+
modelId,
|
|
268
|
+
positivePrompt: args.prompt,
|
|
269
|
+
numberOfMedia: getVariationCount(args, options),
|
|
270
|
+
contextImages
|
|
271
|
+
};
|
|
272
|
+
if (args.negative_prompt)
|
|
273
|
+
projectParams.negativePrompt = args.negative_prompt;
|
|
274
|
+
if (args.width && args.height) {
|
|
275
|
+
projectParams.width = args.width;
|
|
276
|
+
projectParams.height = args.height;
|
|
277
|
+
projectParams.sizePreset = 'custom';
|
|
278
|
+
}
|
|
279
|
+
if (args.seed !== undefined)
|
|
280
|
+
projectParams.seed = args.seed;
|
|
281
|
+
applyHostedImageOptions(projectParams, args);
|
|
250
282
|
if (options === null || options === void 0 ? void 0 : options.tokenType)
|
|
251
283
|
projectParams.tokenType = options.tokenType;
|
|
252
284
|
if (options === null || options === void 0 ? void 0 : options.network)
|
|
@@ -256,27 +288,197 @@ class ChatToolsApi {
|
|
|
256
288
|
}
|
|
257
289
|
executeVideoGeneration(toolCall, args, options) {
|
|
258
290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
291
|
+
const hasReferenceImages = (0, modelRouting_1.isNonEmptyString)(args.reference_image_url) || (0, modelRouting_1.isNonEmptyString)(args.reference_image_end_url);
|
|
292
|
+
const workflowPreference = hasReferenceImages ? ['i2v'] : ['t2v'];
|
|
293
|
+
const preferredModelIds = hasReferenceImages
|
|
294
|
+
? [modelRouting_1.PREFERRED_MODEL_IDS.video.i2v]
|
|
295
|
+
: [modelRouting_1.PREFERRED_MODEL_IDS.video.t2v];
|
|
296
|
+
const modelId = yield this.selectModel({
|
|
297
|
+
mediaType: 'video',
|
|
298
|
+
requestedModel: (0, modelRouting_1.resolveHostedToolModelSelector)('sogni_generate_video', args),
|
|
299
|
+
workflows: workflowPreference,
|
|
300
|
+
preferredModelIds
|
|
301
|
+
});
|
|
302
|
+
const defaults = (0, modelRouting_1.getVideoDefaults)(modelId);
|
|
303
|
+
const isSeedanceModel = modelId.startsWith('seedance-2-0');
|
|
265
304
|
const projectParams = {
|
|
266
305
|
type: 'video',
|
|
267
306
|
modelId,
|
|
268
307
|
positivePrompt: args.prompt,
|
|
269
|
-
numberOfMedia: (
|
|
270
|
-
width: args.width ||
|
|
271
|
-
height: args.height ||
|
|
272
|
-
fps: args.fps ||
|
|
308
|
+
numberOfMedia: getVariationCount(args, options),
|
|
309
|
+
width: args.width || defaults.width,
|
|
310
|
+
height: args.height || defaults.height,
|
|
311
|
+
fps: args.fps || defaults.fps
|
|
273
312
|
};
|
|
274
|
-
if (args.negative_prompt)
|
|
313
|
+
if (args.negative_prompt && !isSeedanceModel) {
|
|
275
314
|
projectParams.negativePrompt = args.negative_prompt;
|
|
315
|
+
}
|
|
276
316
|
if (args.duration !== undefined)
|
|
277
317
|
projectParams.duration = args.duration;
|
|
278
318
|
if (args.seed !== undefined)
|
|
279
319
|
projectParams.seed = args.seed;
|
|
320
|
+
if ((0, modelRouting_1.isNonEmptyString)(args.reference_image_url)) {
|
|
321
|
+
projectParams.referenceImage = (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_image_url, 'image', {
|
|
322
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.image
|
|
323
|
+
}).blob;
|
|
324
|
+
}
|
|
325
|
+
if ((0, modelRouting_1.isNonEmptyString)(args.reference_image_end_url)) {
|
|
326
|
+
projectParams.referenceImageEnd = (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_image_end_url, 'image', {
|
|
327
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.image
|
|
328
|
+
}).blob;
|
|
329
|
+
}
|
|
330
|
+
if ((0, modelRouting_1.isNonEmptyString)(args.reference_audio_identity_url)) {
|
|
331
|
+
projectParams.referenceAudioIdentity = (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_audio_identity_url, 'audio', {
|
|
332
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.audio
|
|
333
|
+
}).blob;
|
|
334
|
+
}
|
|
335
|
+
if (args.audio_identity_strength !== undefined) {
|
|
336
|
+
projectParams.audioIdentityStrength = args.audio_identity_strength;
|
|
337
|
+
}
|
|
338
|
+
if (args.first_frame_strength !== undefined) {
|
|
339
|
+
projectParams.firstFrameStrength = args.first_frame_strength;
|
|
340
|
+
}
|
|
341
|
+
if (args.last_frame_strength !== undefined) {
|
|
342
|
+
projectParams.lastFrameStrength = args.last_frame_strength;
|
|
343
|
+
}
|
|
344
|
+
if (args.generate_audio !== undefined) {
|
|
345
|
+
projectParams.generateAudio = Boolean(args.generate_audio);
|
|
346
|
+
}
|
|
347
|
+
if (options === null || options === void 0 ? void 0 : options.tokenType)
|
|
348
|
+
projectParams.tokenType = options.tokenType;
|
|
349
|
+
if (options === null || options === void 0 ? void 0 : options.network)
|
|
350
|
+
projectParams.network = options.network;
|
|
351
|
+
return this.executeProject(toolCall, 'video', modelId, projectParams, args.prompt, options);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
executeSoundToVideo(toolCall, args, options) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
var _a;
|
|
357
|
+
if (!(0, modelRouting_1.isNonEmptyString)(args.reference_audio_url)) {
|
|
358
|
+
throw new Error('sogni_sound_to_video requires reference_audio_url');
|
|
359
|
+
}
|
|
360
|
+
const hasReferenceImage = (0, modelRouting_1.isNonEmptyString)(args.reference_image_url);
|
|
361
|
+
const workflows = hasReferenceImage ? ['ia2v', 's2v'] : ['a2v'];
|
|
362
|
+
const preferredModelIds = hasReferenceImage
|
|
363
|
+
? [modelRouting_1.PREFERRED_MODEL_IDS.video.ia2v, modelRouting_1.PREFERRED_MODEL_IDS.video.s2v]
|
|
364
|
+
: [modelRouting_1.PREFERRED_MODEL_IDS.video.a2v];
|
|
365
|
+
const modelId = yield this.selectModel({
|
|
366
|
+
mediaType: 'video',
|
|
367
|
+
requestedModel: (0, modelRouting_1.resolveHostedToolModelSelector)('sogni_sound_to_video', args),
|
|
368
|
+
workflows,
|
|
369
|
+
preferredModelIds
|
|
370
|
+
});
|
|
371
|
+
const defaults = (0, modelRouting_1.getVideoDefaults)(modelId);
|
|
372
|
+
const duration = (_a = (0, modelRouting_1.asFiniteNumber)(args.duration)) !== null && _a !== void 0 ? _a : 5;
|
|
373
|
+
const projectParams = {
|
|
374
|
+
type: 'video',
|
|
375
|
+
modelId,
|
|
376
|
+
positivePrompt: args.prompt,
|
|
377
|
+
numberOfMedia: getVariationCount(args, options),
|
|
378
|
+
referenceAudio: (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_audio_url, 'audio', {
|
|
379
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.audio
|
|
380
|
+
}).blob,
|
|
381
|
+
width: args.width || defaults.width,
|
|
382
|
+
height: args.height || defaults.height,
|
|
383
|
+
fps: defaults.fps,
|
|
384
|
+
duration,
|
|
385
|
+
audioDuration: duration
|
|
386
|
+
};
|
|
387
|
+
if ((0, modelRouting_1.isNonEmptyString)(args.reference_image_url)) {
|
|
388
|
+
projectParams.referenceImage = (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_image_url, 'image', {
|
|
389
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.image
|
|
390
|
+
}).blob;
|
|
391
|
+
}
|
|
392
|
+
if (args.audio_start !== undefined)
|
|
393
|
+
projectParams.audioStart = args.audio_start;
|
|
394
|
+
if (args.generate_audio !== undefined) {
|
|
395
|
+
projectParams.generateAudio = Boolean(args.generate_audio);
|
|
396
|
+
}
|
|
397
|
+
if (args.seed !== undefined)
|
|
398
|
+
projectParams.seed = args.seed;
|
|
399
|
+
if (options === null || options === void 0 ? void 0 : options.tokenType)
|
|
400
|
+
projectParams.tokenType = options.tokenType;
|
|
401
|
+
if (options === null || options === void 0 ? void 0 : options.network)
|
|
402
|
+
projectParams.network = options.network;
|
|
403
|
+
return this.executeProject(toolCall, 'video', modelId, projectParams, args.prompt, options);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
executeVideoToVideo(toolCall, args, options) {
|
|
407
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
+
var _a;
|
|
409
|
+
if (!(0, modelRouting_1.isNonEmptyString)(args.reference_video_url)) {
|
|
410
|
+
throw new Error('sogni_video_to_video requires reference_video_url');
|
|
411
|
+
}
|
|
412
|
+
const controlMode = (0, modelRouting_1.normalizeVideoControlMode)(args.control_mode);
|
|
413
|
+
const isAnimateMode = controlMode === 'animate-move' || controlMode === 'animate-replace';
|
|
414
|
+
const isSeedanceMode = controlMode === 'seedance-v2v';
|
|
415
|
+
const workflows = isAnimateMode ? [controlMode] : ['v2v'];
|
|
416
|
+
const preferredModelIds = isAnimateMode
|
|
417
|
+
? [
|
|
418
|
+
controlMode === 'animate-move'
|
|
419
|
+
? modelRouting_1.PREFERRED_MODEL_IDS.video.animateMove
|
|
420
|
+
: modelRouting_1.PREFERRED_MODEL_IDS.video.animateReplace
|
|
421
|
+
]
|
|
422
|
+
: isSeedanceMode
|
|
423
|
+
? [modelRouting_1.PREFERRED_MODEL_IDS.video.seedanceV2v, modelRouting_1.PREFERRED_MODEL_IDS.video.v2v]
|
|
424
|
+
: [modelRouting_1.PREFERRED_MODEL_IDS.video.v2v];
|
|
425
|
+
const modelId = yield this.selectModel({
|
|
426
|
+
mediaType: 'video',
|
|
427
|
+
requestedModel: (0, modelRouting_1.resolveHostedToolModelSelector)('sogni_video_to_video', args),
|
|
428
|
+
workflows,
|
|
429
|
+
preferredModelIds
|
|
430
|
+
});
|
|
431
|
+
const defaults = (0, modelRouting_1.getVideoDefaults)(modelId);
|
|
432
|
+
const isSeedanceModel = modelId.startsWith('seedance-2-0');
|
|
433
|
+
if (isAnimateMode && !(0, modelRouting_1.isNonEmptyString)(args.reference_image_url)) {
|
|
434
|
+
throw new Error(`${controlMode} requires reference_image_url`);
|
|
435
|
+
}
|
|
436
|
+
const projectParams = {
|
|
437
|
+
type: 'video',
|
|
438
|
+
modelId,
|
|
439
|
+
positivePrompt: args.prompt,
|
|
440
|
+
numberOfMedia: getVariationCount(args, options),
|
|
441
|
+
referenceVideo: (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_video_url, 'video', {
|
|
442
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.video
|
|
443
|
+
}).blob,
|
|
444
|
+
width: args.width || defaults.width,
|
|
445
|
+
height: args.height || defaults.height,
|
|
446
|
+
fps: defaults.fps,
|
|
447
|
+
duration: (_a = (0, modelRouting_1.asFiniteNumber)(args.duration)) !== null && _a !== void 0 ? _a : 5
|
|
448
|
+
};
|
|
449
|
+
if (args.negative_prompt && !isSeedanceModel) {
|
|
450
|
+
projectParams.negativePrompt = args.negative_prompt;
|
|
451
|
+
}
|
|
452
|
+
if (args.seed !== undefined)
|
|
453
|
+
projectParams.seed = args.seed;
|
|
454
|
+
if ((0, modelRouting_1.isNonEmptyString)(args.reference_image_url)) {
|
|
455
|
+
projectParams.referenceImage = (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_image_url, 'image', {
|
|
456
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.image
|
|
457
|
+
}).blob;
|
|
458
|
+
}
|
|
459
|
+
if ((0, modelRouting_1.isNonEmptyString)(args.reference_audio_identity_url)) {
|
|
460
|
+
projectParams.referenceAudioIdentity = (0, mediaValidation_1.parseInlineMediaDataUri)(args.reference_audio_identity_url, 'audio', {
|
|
461
|
+
maxBytes: MAX_INPUT_MEDIA_BYTES.audio
|
|
462
|
+
}).blob;
|
|
463
|
+
}
|
|
464
|
+
if (args.audio_identity_strength !== undefined) {
|
|
465
|
+
projectParams.audioIdentityStrength = args.audio_identity_strength;
|
|
466
|
+
}
|
|
467
|
+
if (args.video_start !== undefined) {
|
|
468
|
+
projectParams.videoStart = args.video_start;
|
|
469
|
+
}
|
|
470
|
+
if (args.generate_audio !== undefined) {
|
|
471
|
+
projectParams.generateAudio = Boolean(args.generate_audio);
|
|
472
|
+
}
|
|
473
|
+
if (!isAnimateMode && !isSeedanceModel) {
|
|
474
|
+
projectParams.controlNet = {
|
|
475
|
+
name: controlMode,
|
|
476
|
+
strength: controlMode === 'detailer' ? 1 : 0.85
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (!isSeedanceModel && args.detailer_strength !== undefined) {
|
|
480
|
+
projectParams.detailerStrength = args.detailer_strength;
|
|
481
|
+
}
|
|
280
482
|
if (options === null || options === void 0 ? void 0 : options.tokenType)
|
|
281
483
|
projectParams.tokenType = options.tokenType;
|
|
282
484
|
if (options === null || options === void 0 ? void 0 : options.network)
|
|
@@ -286,12 +488,19 @@ class ChatToolsApi {
|
|
|
286
488
|
}
|
|
287
489
|
executeMusicGeneration(toolCall, args, options) {
|
|
288
490
|
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
const modelId =
|
|
491
|
+
const modelId = yield this.selectModel({
|
|
492
|
+
mediaType: 'audio',
|
|
493
|
+
requestedModel: (0, modelRouting_1.resolveHostedToolModelSelector)('sogni_generate_music', args),
|
|
494
|
+
preferredModelIds: [
|
|
495
|
+
modelRouting_1.PREFERRED_MODEL_IDS.audio.aceStepTurbo,
|
|
496
|
+
modelRouting_1.PREFERRED_MODEL_IDS.audio.aceStepSft
|
|
497
|
+
]
|
|
498
|
+
});
|
|
290
499
|
const projectParams = {
|
|
291
500
|
type: 'audio',
|
|
292
501
|
modelId,
|
|
293
502
|
positivePrompt: args.prompt,
|
|
294
|
-
numberOfMedia: (
|
|
503
|
+
numberOfMedia: getVariationCount(args, options)
|
|
295
504
|
};
|
|
296
505
|
if (args.duration !== undefined)
|
|
297
506
|
projectParams.duration = args.duration;
|
|
@@ -299,10 +508,24 @@ class ChatToolsApi {
|
|
|
299
508
|
projectParams.bpm = args.bpm;
|
|
300
509
|
if (args.keyscale)
|
|
301
510
|
projectParams.keyscale = args.keyscale;
|
|
302
|
-
if (args.
|
|
303
|
-
projectParams.
|
|
511
|
+
if (args.lyrics)
|
|
512
|
+
projectParams.lyrics = args.lyrics;
|
|
513
|
+
if (args.language)
|
|
514
|
+
projectParams.language = args.language;
|
|
304
515
|
if (args.output_format)
|
|
305
516
|
projectParams.outputFormat = args.output_format;
|
|
517
|
+
const timeSignature = (0, modelRouting_1.normalizeTimeSignature)(args.timesignature);
|
|
518
|
+
if (timeSignature)
|
|
519
|
+
projectParams.timesignature = timeSignature;
|
|
520
|
+
const composerMode = (0, modelRouting_1.asBooleanValue)(args.composer_mode);
|
|
521
|
+
if (composerMode !== undefined)
|
|
522
|
+
projectParams.composerMode = composerMode;
|
|
523
|
+
const promptStrength = (0, modelRouting_1.asFiniteNumber)(args.prompt_strength);
|
|
524
|
+
if (promptStrength !== undefined)
|
|
525
|
+
projectParams.promptStrength = promptStrength;
|
|
526
|
+
const creativity = (0, modelRouting_1.asFiniteNumber)(args.creativity);
|
|
527
|
+
if (creativity !== undefined)
|
|
528
|
+
projectParams.creativity = creativity;
|
|
306
529
|
if (args.seed !== undefined)
|
|
307
530
|
projectParams.seed = args.seed;
|
|
308
531
|
if (options === null || options === void 0 ? void 0 : options.tokenType)
|