seacloud-sdk 0.4.0 → 0.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.
package/dist/index.js CHANGED
@@ -5080,6 +5080,217 @@ 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 requestBody = {
5089
+ ...params,
5090
+ model: params.model || "custom_openai/vertex-ai-claude-sonnet-4.5"
5091
+ };
5092
+ const controller = new AbortController();
5093
+ const timeoutId = setTimeout(() => controller.abort(), config.timeout);
5094
+ try {
5095
+ const response = await config.fetch(url, {
5096
+ method: "POST",
5097
+ headers: {
5098
+ "Content-Type": "application/json",
5099
+ "Authorization": `Bearer ${config.apiKey}`,
5100
+ "X-Project": "SeaArt"
5101
+ },
5102
+ body: JSON.stringify(requestBody),
5103
+ signal: controller.signal
5104
+ });
5105
+ clearTimeout(timeoutId);
5106
+ if (!response.ok) {
5107
+ const errorBody = await response.text();
5108
+ throw new SeacloudError(
5109
+ `HTTP ${response.status}: ${errorBody}`,
5110
+ response.status,
5111
+ errorBody
5112
+ );
5113
+ }
5114
+ if (params.stream) {
5115
+ return parseAgentStreamingResponse(response);
5116
+ }
5117
+ return await parseAgentNonStreamingResponse(response);
5118
+ } catch (error) {
5119
+ clearTimeout(timeoutId);
5120
+ if (error instanceof SeacloudError) {
5121
+ throw error;
5122
+ }
5123
+ if (error.name === "AbortError") {
5124
+ throw new SeacloudError(`Request timeout after ${config.timeout}ms`);
5125
+ }
5126
+ throw new SeacloudError(
5127
+ `Request failed: ${error.message}`,
5128
+ void 0,
5129
+ error
5130
+ );
5131
+ }
5132
+ }
5133
+ async function parseAgentNonStreamingResponse(response) {
5134
+ const reader = response.body?.getReader();
5135
+ if (!reader) {
5136
+ throw new SeacloudError("Response body is not readable");
5137
+ }
5138
+ const decoder = new TextDecoder();
5139
+ let buffer = "";
5140
+ let fullContent = "";
5141
+ let artifacts = [];
5142
+ let finishReason = "";
5143
+ let sessionId = "";
5144
+ let msgId = "";
5145
+ let lastChunk = null;
5146
+ let usage;
5147
+ try {
5148
+ while (true) {
5149
+ const { done, value } = await reader.read();
5150
+ if (done) {
5151
+ break;
5152
+ }
5153
+ buffer += decoder.decode(value, { stream: true });
5154
+ const lines = buffer.split("\n");
5155
+ buffer = lines.pop() || "";
5156
+ for (const line of lines) {
5157
+ const trimmedLine = line.trim();
5158
+ if (!trimmedLine) continue;
5159
+ if (trimmedLine === "data: [DONE]") continue;
5160
+ if (trimmedLine === "event: heartbeat") continue;
5161
+ if (trimmedLine.startsWith("data: ")) {
5162
+ const data = trimmedLine.slice(6).trim();
5163
+ try {
5164
+ const parsed = JSON.parse(data);
5165
+ lastChunk = parsed;
5166
+ const delta = parsed.choices?.[0]?.delta;
5167
+ if (delta?.content) {
5168
+ if (typeof delta.content === "string") {
5169
+ fullContent += delta.content;
5170
+ } else if (Array.isArray(delta.content)) {
5171
+ for (const item of delta.content) {
5172
+ if (item.type === "text" && item.text) {
5173
+ fullContent += item.text;
5174
+ }
5175
+ }
5176
+ }
5177
+ }
5178
+ if (delta?.artifacts) {
5179
+ artifacts.push(...delta.artifacts);
5180
+ }
5181
+ if (parsed.choices?.[0]?.finish_reason) {
5182
+ finishReason = parsed.choices[0].finish_reason;
5183
+ }
5184
+ if (parsed.session_id) {
5185
+ sessionId = parsed.session_id;
5186
+ }
5187
+ if (parsed.msg_id) {
5188
+ msgId = parsed.msg_id;
5189
+ }
5190
+ if (parsed.usage) {
5191
+ usage = parsed.usage;
5192
+ }
5193
+ } catch (e) {
5194
+ console.warn("Failed to parse SSE chunk:", data.substring(0, 100));
5195
+ }
5196
+ }
5197
+ }
5198
+ }
5199
+ } finally {
5200
+ reader.releaseLock();
5201
+ }
5202
+ if (!lastChunk) {
5203
+ throw new SeacloudError("No valid response chunks received");
5204
+ }
5205
+ return {
5206
+ id: lastChunk.id,
5207
+ object: "chat.completion",
5208
+ created: lastChunk.created,
5209
+ model: lastChunk.model,
5210
+ system_fingerprint: lastChunk.system_fingerprint,
5211
+ choices: [
5212
+ {
5213
+ index: 0,
5214
+ message: {
5215
+ role: "assistant",
5216
+ content: fullContent
5217
+ },
5218
+ finish_reason: finishReason || null
5219
+ }
5220
+ ],
5221
+ usage,
5222
+ session_id: sessionId || void 0,
5223
+ msg_id: msgId || void 0,
5224
+ artifacts: artifacts.length > 0 ? artifacts : void 0
5225
+ };
5226
+ }
5227
+ async function* parseAgentStreamingResponse(response) {
5228
+ const reader = response.body?.getReader();
5229
+ if (!reader) {
5230
+ throw new SeacloudError("Response body is not readable");
5231
+ }
5232
+ const decoder = new TextDecoder();
5233
+ let buffer = "";
5234
+ try {
5235
+ while (true) {
5236
+ const { done, value } = await reader.read();
5237
+ if (done) {
5238
+ break;
5239
+ }
5240
+ buffer += decoder.decode(value, { stream: true });
5241
+ const lines = buffer.split("\n");
5242
+ buffer = lines.pop() || "";
5243
+ for (const line of lines) {
5244
+ const trimmedLine = line.trim();
5245
+ if (!trimmedLine || trimmedLine.startsWith(":")) continue;
5246
+ if (trimmedLine.startsWith("event: ")) {
5247
+ const eventType = trimmedLine.slice(7).trim();
5248
+ if (eventType === "heartbeat") {
5249
+ continue;
5250
+ }
5251
+ }
5252
+ if (trimmedLine.startsWith("data: ")) {
5253
+ const data = trimmedLine.slice(6).trim();
5254
+ if (data === "[DONE]") {
5255
+ break;
5256
+ }
5257
+ try {
5258
+ const chunk = JSON.parse(data);
5259
+ yield chunk;
5260
+ } catch (error) {
5261
+ console.warn("Failed to parse SSE chunk:", data);
5262
+ }
5263
+ }
5264
+ }
5265
+ }
5266
+ } finally {
5267
+ reader.releaseLock();
5268
+ }
5269
+ }
5270
+ function createTextMessage(role, text) {
5271
+ return {
5272
+ role,
5273
+ content: [{ type: "text", text }]
5274
+ };
5275
+ }
5276
+ function createImageMessage(role, text, imageUrl) {
5277
+ return {
5278
+ role,
5279
+ content: [
5280
+ { type: "text", text },
5281
+ { type: "image", url: imageUrl }
5282
+ ]
5283
+ };
5284
+ }
5285
+ function createTool(toolName) {
5286
+ return {
5287
+ type: "function",
5288
+ function: {
5289
+ name: toolName
5290
+ }
5291
+ };
5292
+ }
5293
+
5294
+ 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, createConfig, createImageMessage, createTextMessage, createTool, 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
5295
  //# sourceMappingURL=index.js.map
5085
5296
  //# sourceMappingURL=index.js.map