seacloud-sdk 0.4.0 → 0.5.1

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/dist/index.js CHANGED
@@ -5080,6 +5080,240 @@ async function* parseStreamingResponse(response) {
5080
5080
  }
5081
5081
  }
5082
5082
 
5083
- export { SeacloudClient, SeacloudError, alibabaAnimateAnyoneDetect, alibabaAnimateAnyoneTemplate, alibabaAnimateAnyoneVideo, alibabaQianwenImage, alibabaWan22T2iFlash, alibabaWan22T2iPlus, alibabaWan25I2iPreview, alibabaWan25T2iPreview, alibabaWanx20T2iTurbo, alibabaWanx21I2vPlus, alibabaWanx21I2vTurbo, alibabaWanx21T2iPlus, alibabaWanx21T2iTurbo, alibabaWanx21T2vPlus, alibabaWanx21T2vTurbo, alibabaWanx22I2vFlash, alibabaWanx22I2vPlus, alibabaWanx22T2vPlus, alibabaWanx25I2vPreview, alibabaWanx25T2vPreview, alibabaWanx26I2v, alibabaWanx26Reference, alibabaWanx26T2v, blackforestlabsFlux11Pro, blackforestlabsFlux1Pro, blackforestlabsFlux2Flex, blackforestlabsFlux2FlexEdit, blackforestlabsFlux2Pro, blackforestlabsFlux2ProEdit, blackforestlabsFluxKontextMax, blackforestlabsFluxKontextPro, createAndWaitTask, createConfig, elevenlabsTtsGenerator, getClient, getDefaultPollingOptions, googleGemini3ProImage, googleGeminiImage, googleImagen4FastGenerate, googleImagen4Generate, googleImagen4UltraGenerate, googleVeo20Generate001, googleVeo20GenerateExp, googleVeo20GeneratePreview, googleVeo30FastGenerate001, googleVeo30Generate001, googleVeo31, initSeacloud, klingAvatar, klingDurationExtension, klingEffectsMultiV1, klingEffectsMultiV15, klingEffectsMultiV16, klingEffectsSingle, klingLipsync, klingOmniImage, klingOmniVideo, klingV1, klingV15, klingV15I2v, klingV16, klingV16I2v, klingV1I2v, klingV21I2v, klingV21Master, klingV21MasterI2v, klingV25Turbo, klingV25TurboI2v, klingV26, klingV26I2v, klingV2Master, klingV2MasterI2v, llmChatCompletions, microsoftGptImage1, microsoftGptImage15, microsoftSora2, minimaxHailuo02, minimaxHailuo02I2v, minimaxHailuo23FastI2v, minimaxHailuo23I2v, minimaxI2v01, minimaxI2v01Director, minimaxI2v01Live, minimaxT2a, minimaxT2v01, minimaxT2v01Director, pixverseV35I2v, pixverseV35T2v, pixverseV35Transition, pixverseV45I2v, pixverseV45T2v, pixverseV45Transition, pixverseV4I2v, pixverseV4T2v, pixverseV4Transition, pixverseV55I2v, pixverseV55T2v, pixverseV55Transition, pixverseV5I2v, pixverseV5T2v, pixverseV5Transition, pollTaskUntilComplete, resetConfig, runwayGen3aTurboI2v, setDefaultPollingOptions, tencentHunyuan3d, tencentHunyuan3dPro, tencentHunyuan3dRapid, tencentImageCreation3, tencentMpsSuperResolution, validateConfig, vidu15, vidu15I2v, vidu20I2v, viduQ1, viduQ1I2v, viduQ2, viduTemplate, viduTemplateV2, volcesJimeng30, volcesJimeng31, volcesJimengDreamActorM1, volcesJimengI2i30, volcesRealmanAvatarImitatorV2v, volcesRealmanAvatarPictureOmniV15, volcesRealmanAvatarPictureOmniV2, volcesSeed3d, volcesSeedance30, volcesSeedance30I2v, volcesSeedance30Pro, volcesSeedanceProFast, volcesSeededit20, volcesSeededit30, volcesSeededit30I2i, volcesSeededit3dStyle, volcesSeededitMultiIp, volcesSeededitMultiStyle, volcesSeededitPortrait, volcesSeededitSingleIp, volcesSeedream30, volcesSeedream40, volcesSeedream45, volcesSeedream45I2i, volcesSeedream45MultiBlend, volcesSubjectDetection, volcesSubjectRecognition };
5083
+ // src/api/agent_chat_completions.ts
5084
+ async function agentChatCompletions(params) {
5085
+ const client = getClient();
5086
+ const config = client.getConfig();
5087
+ const url = `${config.baseUrl}/agent/api/v1/chat/completions`;
5088
+ const model = params.model || "custom_openai/vertex-ai-claude-sonnet-4.5";
5089
+ const userWantsStreaming = params.stream !== false;
5090
+ const requestBody = {
5091
+ ...params,
5092
+ model,
5093
+ stream: true
5094
+ // Always request SSE from API
5095
+ };
5096
+ const controller = new AbortController();
5097
+ const timeoutId = setTimeout(() => controller.abort(), config.timeout);
5098
+ try {
5099
+ const response = await config.fetch(url, {
5100
+ method: "POST",
5101
+ headers: {
5102
+ "Content-Type": "application/json",
5103
+ "Authorization": `Bearer ${config.apiKey}`,
5104
+ "X-Project": "SeaArt"
5105
+ // Required header for agent API
5106
+ },
5107
+ body: JSON.stringify(requestBody),
5108
+ signal: controller.signal
5109
+ });
5110
+ clearTimeout(timeoutId);
5111
+ if (!response.ok) {
5112
+ const errorBody = await response.text();
5113
+ throw new SeacloudError(
5114
+ `HTTP ${response.status}: ${errorBody}`,
5115
+ response.status,
5116
+ errorBody
5117
+ );
5118
+ }
5119
+ if (userWantsStreaming) {
5120
+ return parseAgentStreamingResponse(response);
5121
+ }
5122
+ return await parseAgentNonStreamingResponse(response);
5123
+ } catch (error) {
5124
+ clearTimeout(timeoutId);
5125
+ if (error instanceof SeacloudError) {
5126
+ throw error;
5127
+ }
5128
+ if (error.name === "AbortError") {
5129
+ throw new SeacloudError(`Request timeout after ${config.timeout}ms`);
5130
+ }
5131
+ throw new SeacloudError(
5132
+ `Request failed: ${error.message}`,
5133
+ void 0,
5134
+ error
5135
+ );
5136
+ }
5137
+ }
5138
+ async function parseAgentNonStreamingResponse(response) {
5139
+ const reader = response.body?.getReader();
5140
+ if (!reader) {
5141
+ throw new SeacloudError("Response body is not readable");
5142
+ }
5143
+ const decoder = new TextDecoder();
5144
+ let buffer = "";
5145
+ let fullContent = "";
5146
+ let artifacts = [];
5147
+ let finishReason = "";
5148
+ let sessionId = "";
5149
+ let msgId = "";
5150
+ let lastChunk = null;
5151
+ let usage;
5152
+ try {
5153
+ while (true) {
5154
+ const { done, value } = await reader.read();
5155
+ if (done) {
5156
+ break;
5157
+ }
5158
+ buffer += decoder.decode(value, { stream: true });
5159
+ const lines = buffer.split("\n");
5160
+ buffer = lines.pop() || "";
5161
+ for (const line of lines) {
5162
+ const trimmedLine = line.trim();
5163
+ if (!trimmedLine) continue;
5164
+ if (trimmedLine === "data: [DONE]") continue;
5165
+ if (trimmedLine === "event: heartbeat") continue;
5166
+ if (trimmedLine.startsWith("data: ")) {
5167
+ const data = trimmedLine.slice(6).trim();
5168
+ try {
5169
+ const parsed = JSON.parse(data);
5170
+ lastChunk = parsed;
5171
+ const delta = parsed.choices?.[0]?.delta;
5172
+ if (delta?.content) {
5173
+ if (typeof delta.content === "string") {
5174
+ fullContent += delta.content;
5175
+ } else if (Array.isArray(delta.content)) {
5176
+ for (const item of delta.content) {
5177
+ if (item.type === "text" && item.text) {
5178
+ fullContent += item.text;
5179
+ }
5180
+ }
5181
+ }
5182
+ }
5183
+ if (delta?.artifacts) {
5184
+ artifacts.push(...delta.artifacts);
5185
+ }
5186
+ if (parsed.choices?.[0]?.finish_reason) {
5187
+ finishReason = parsed.choices[0].finish_reason;
5188
+ }
5189
+ if (parsed.session_id) {
5190
+ sessionId = parsed.session_id;
5191
+ }
5192
+ if (parsed.msg_id) {
5193
+ msgId = parsed.msg_id;
5194
+ }
5195
+ if (parsed.usage) {
5196
+ usage = parsed.usage;
5197
+ }
5198
+ } catch (e) {
5199
+ console.warn("Failed to parse SSE chunk:", data.substring(0, 100));
5200
+ }
5201
+ }
5202
+ }
5203
+ }
5204
+ } finally {
5205
+ reader.releaseLock();
5206
+ }
5207
+ if (!lastChunk) {
5208
+ throw new SeacloudError("No valid response chunks received");
5209
+ }
5210
+ return {
5211
+ id: lastChunk.id,
5212
+ object: "chat.completion",
5213
+ created: lastChunk.created,
5214
+ model: lastChunk.model,
5215
+ system_fingerprint: lastChunk.system_fingerprint,
5216
+ choices: [
5217
+ {
5218
+ index: 0,
5219
+ message: {
5220
+ role: "assistant",
5221
+ content: fullContent
5222
+ },
5223
+ finish_reason: finishReason || null
5224
+ }
5225
+ ],
5226
+ usage,
5227
+ session_id: sessionId || void 0,
5228
+ msg_id: msgId || void 0,
5229
+ artifacts: artifacts.length > 0 ? artifacts : void 0
5230
+ };
5231
+ }
5232
+ async function* parseAgentStreamingResponse(response) {
5233
+ const reader = response.body?.getReader();
5234
+ if (!reader) {
5235
+ throw new SeacloudError("Response body is not readable");
5236
+ }
5237
+ const decoder = new TextDecoder();
5238
+ let buffer = "";
5239
+ try {
5240
+ while (true) {
5241
+ const { done, value } = await reader.read();
5242
+ if (done) {
5243
+ break;
5244
+ }
5245
+ buffer += decoder.decode(value, { stream: true });
5246
+ const lines = buffer.split("\n");
5247
+ buffer = lines.pop() || "";
5248
+ for (const line of lines) {
5249
+ const trimmedLine = line.trim();
5250
+ if (!trimmedLine || trimmedLine.startsWith(":")) continue;
5251
+ if (trimmedLine.startsWith("event: ")) {
5252
+ const eventType = trimmedLine.slice(7).trim();
5253
+ if (eventType === "heartbeat") {
5254
+ continue;
5255
+ }
5256
+ }
5257
+ if (trimmedLine.startsWith("data: ")) {
5258
+ const data = trimmedLine.slice(6).trim();
5259
+ if (data === "[DONE]") {
5260
+ break;
5261
+ }
5262
+ try {
5263
+ const chunk = JSON.parse(data);
5264
+ yield chunk;
5265
+ } catch (error) {
5266
+ console.warn("Failed to parse SSE chunk:", data);
5267
+ }
5268
+ }
5269
+ }
5270
+ }
5271
+ } finally {
5272
+ reader.releaseLock();
5273
+ }
5274
+ }
5275
+ function createTextMessage(role, text) {
5276
+ return {
5277
+ role,
5278
+ content: [{ type: "text", text }]
5279
+ };
5280
+ }
5281
+ function createImageMessage(role, text, imageUrl) {
5282
+ return {
5283
+ role,
5284
+ content: [
5285
+ { type: "text", text },
5286
+ { type: "image", image_url: imageUrl }
5287
+ ]
5288
+ };
5289
+ }
5290
+ function createVideoMessage(role, text, videoUrl) {
5291
+ return {
5292
+ role,
5293
+ content: [
5294
+ { type: "text", text },
5295
+ { type: "video", video_url: videoUrl }
5296
+ ]
5297
+ };
5298
+ }
5299
+ function createAudioMessage(role, text, audioUrl) {
5300
+ return {
5301
+ role,
5302
+ content: [
5303
+ { type: "text", text },
5304
+ { type: "audio", audio_url: audioUrl }
5305
+ ]
5306
+ };
5307
+ }
5308
+ function createTool(toolName) {
5309
+ return {
5310
+ type: "function",
5311
+ function: {
5312
+ name: toolName
5313
+ }
5314
+ };
5315
+ }
5316
+
5317
+ export { SeacloudClient, SeacloudError, agentChatCompletions, alibabaAnimateAnyoneDetect, alibabaAnimateAnyoneTemplate, alibabaAnimateAnyoneVideo, alibabaQianwenImage, alibabaWan22T2iFlash, alibabaWan22T2iPlus, alibabaWan25I2iPreview, alibabaWan25T2iPreview, alibabaWanx20T2iTurbo, alibabaWanx21I2vPlus, alibabaWanx21I2vTurbo, alibabaWanx21T2iPlus, alibabaWanx21T2iTurbo, alibabaWanx21T2vPlus, alibabaWanx21T2vTurbo, alibabaWanx22I2vFlash, alibabaWanx22I2vPlus, alibabaWanx22T2vPlus, alibabaWanx25I2vPreview, alibabaWanx25T2vPreview, alibabaWanx26I2v, alibabaWanx26Reference, alibabaWanx26T2v, blackforestlabsFlux11Pro, blackforestlabsFlux1Pro, blackforestlabsFlux2Flex, blackforestlabsFlux2FlexEdit, blackforestlabsFlux2Pro, blackforestlabsFlux2ProEdit, blackforestlabsFluxKontextMax, blackforestlabsFluxKontextPro, createAndWaitTask, createAudioMessage, createConfig, createImageMessage, createTextMessage, createTool, createVideoMessage, elevenlabsTtsGenerator, getClient, getDefaultPollingOptions, googleGemini3ProImage, googleGeminiImage, googleImagen4FastGenerate, googleImagen4Generate, googleImagen4UltraGenerate, googleVeo20Generate001, googleVeo20GenerateExp, googleVeo20GeneratePreview, googleVeo30FastGenerate001, googleVeo30Generate001, googleVeo31, initSeacloud, klingAvatar, klingDurationExtension, klingEffectsMultiV1, klingEffectsMultiV15, klingEffectsMultiV16, klingEffectsSingle, klingLipsync, klingOmniImage, klingOmniVideo, klingV1, klingV15, klingV15I2v, klingV16, klingV16I2v, klingV1I2v, klingV21I2v, klingV21Master, klingV21MasterI2v, klingV25Turbo, klingV25TurboI2v, klingV26, klingV26I2v, klingV2Master, klingV2MasterI2v, llmChatCompletions, microsoftGptImage1, microsoftGptImage15, microsoftSora2, minimaxHailuo02, minimaxHailuo02I2v, minimaxHailuo23FastI2v, minimaxHailuo23I2v, minimaxI2v01, minimaxI2v01Director, minimaxI2v01Live, minimaxT2a, minimaxT2v01, minimaxT2v01Director, pixverseV35I2v, pixverseV35T2v, pixverseV35Transition, pixverseV45I2v, pixverseV45T2v, pixverseV45Transition, pixverseV4I2v, pixverseV4T2v, pixverseV4Transition, pixverseV55I2v, pixverseV55T2v, pixverseV55Transition, pixverseV5I2v, pixverseV5T2v, pixverseV5Transition, pollTaskUntilComplete, resetConfig, runwayGen3aTurboI2v, setDefaultPollingOptions, tencentHunyuan3d, tencentHunyuan3dPro, tencentHunyuan3dRapid, tencentImageCreation3, tencentMpsSuperResolution, validateConfig, vidu15, vidu15I2v, vidu20I2v, viduQ1, viduQ1I2v, viduQ2, viduTemplate, viduTemplateV2, volcesJimeng30, volcesJimeng31, volcesJimengDreamActorM1, volcesJimengI2i30, volcesRealmanAvatarImitatorV2v, volcesRealmanAvatarPictureOmniV15, volcesRealmanAvatarPictureOmniV2, volcesSeed3d, volcesSeedance30, volcesSeedance30I2v, volcesSeedance30Pro, volcesSeedanceProFast, volcesSeededit20, volcesSeededit30, volcesSeededit30I2i, volcesSeededit3dStyle, volcesSeededitMultiIp, volcesSeededitMultiStyle, volcesSeededitPortrait, volcesSeededitSingleIp, volcesSeedream30, volcesSeedream40, volcesSeedream45, volcesSeedream45I2i, volcesSeedream45MultiBlend, volcesSubjectDetection, volcesSubjectRecognition };
5084
5318
  //# sourceMappingURL=index.js.map
5085
5319
  //# sourceMappingURL=index.js.map