seacloud-sdk 0.9.5 → 0.9.7
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/cli.js +165 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +252 -1
- package/dist/index.js +55 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -57,7 +57,7 @@ function validateConfig(config) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/core/version.ts
|
|
60
|
-
var VERSION = "0.9.
|
|
60
|
+
var VERSION = "0.9.6";
|
|
61
61
|
|
|
62
62
|
// src/core/client.ts
|
|
63
63
|
var SeacloudClient = class {
|
|
@@ -505,6 +505,39 @@ function createTextMessage(role, text) {
|
|
|
505
505
|
content: [{ type: "text", text }]
|
|
506
506
|
};
|
|
507
507
|
}
|
|
508
|
+
|
|
509
|
+
// src/api/app_search.ts
|
|
510
|
+
async function appSearch(params) {
|
|
511
|
+
const client = getClient();
|
|
512
|
+
const config = client.getConfig();
|
|
513
|
+
const url = `${config.baseUrl}/model/v1/template/specs`;
|
|
514
|
+
const controller = new AbortController();
|
|
515
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeout);
|
|
516
|
+
try {
|
|
517
|
+
const requestId = `req-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
518
|
+
const response = await config.fetch(url, {
|
|
519
|
+
method: "POST",
|
|
520
|
+
headers: {
|
|
521
|
+
"Content-Type": "application/json",
|
|
522
|
+
"Authorization": `Bearer ${config.apiKey}`,
|
|
523
|
+
"X-Request-Id": requestId,
|
|
524
|
+
"X-Project": "KIIRA"
|
|
525
|
+
},
|
|
526
|
+
body: JSON.stringify(params),
|
|
527
|
+
signal: controller.signal
|
|
528
|
+
});
|
|
529
|
+
clearTimeout(timeoutId);
|
|
530
|
+
if (!response.ok) {
|
|
531
|
+
const errorBody = await response.text();
|
|
532
|
+
throw new Error(`HTTP ${response.status}: ${errorBody}`);
|
|
533
|
+
}
|
|
534
|
+
const result = await response.json();
|
|
535
|
+
return result;
|
|
536
|
+
} catch (error) {
|
|
537
|
+
clearTimeout(timeoutId);
|
|
538
|
+
throw error;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
508
541
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
509
542
|
dirname(__filename$1);
|
|
510
543
|
function showHelp() {
|
|
@@ -517,8 +550,13 @@ Usage:
|
|
|
517
550
|
Commands:
|
|
518
551
|
llm <prompt> Chat with LLM models
|
|
519
552
|
agent <prompt> Chat with Fast Agent (supports image/video generation)
|
|
553
|
+
app <subcommand> App-related operations (search, generation)
|
|
520
554
|
<model> Test specific model generation
|
|
521
555
|
|
|
556
|
+
App Subcommands:
|
|
557
|
+
app search <ids> Query template specifications by template IDs
|
|
558
|
+
app generation Create generation task from template
|
|
559
|
+
|
|
522
560
|
LLM Options:
|
|
523
561
|
--model <name> Model name (default: seaart-mix-sonnet-4-5)
|
|
524
562
|
--stream Enable streaming mode
|
|
@@ -531,6 +569,13 @@ Agent Options:
|
|
|
531
569
|
--stream Enable streaming mode
|
|
532
570
|
--session-id <id> Session ID for multi-turn conversation
|
|
533
571
|
|
|
572
|
+
App Search Options:
|
|
573
|
+
--type <type> Template type (default: comfyui)
|
|
574
|
+
|
|
575
|
+
App Generation Options:
|
|
576
|
+
--template-id <id> Template ID (required)
|
|
577
|
+
--params <json> Input parameters as JSON string (required)
|
|
578
|
+
|
|
534
579
|
Model Generation Options:
|
|
535
580
|
--api-key <key> API key (or set API_SERVICE_TOKEN env var)
|
|
536
581
|
--base-url <url> Base URL (default: http://proxy.sg.seaverse.dev)
|
|
@@ -552,6 +597,13 @@ Examples:
|
|
|
552
597
|
# Chat with Agent (streaming)
|
|
553
598
|
seacloud agent "Create a cat image" --stream
|
|
554
599
|
|
|
600
|
+
# Query template specifications (app search)
|
|
601
|
+
seacloud app search "template-id-1,template-id-2"
|
|
602
|
+
seacloud app search "template-abc" --type comfyui
|
|
603
|
+
|
|
604
|
+
# Create generation task (app generation)
|
|
605
|
+
seacloud app generation --template-id "d26trpte878eqsnm3bjg" --params '[{"field":"prompt1","value":"hello"}]'
|
|
606
|
+
|
|
555
607
|
# Test model generation
|
|
556
608
|
seacloud flux_1_1_pro --params '{"prompt":"a beautiful sunset"}'
|
|
557
609
|
|
|
@@ -591,7 +643,7 @@ function parseArgs(args) {
|
|
|
591
643
|
}
|
|
592
644
|
async function testModel(model, options) {
|
|
593
645
|
const apiKey = options.apiKey || process.env.API_SERVICE_TOKEN || "";
|
|
594
|
-
const baseUrl = options.baseUrl || process.env.
|
|
646
|
+
const baseUrl = options.baseUrl || process.env.SEACLOUD_BASE_URL || "http://proxy.sg.seaverse.dev";
|
|
595
647
|
if (!options.params) {
|
|
596
648
|
console.error("Error: --params required. Provide JSON parameters for the model");
|
|
597
649
|
process.exit(1);
|
|
@@ -761,6 +813,95 @@ async function runAgent(prompt, args) {
|
|
|
761
813
|
console.log("Message ID:", response.msg_id);
|
|
762
814
|
}
|
|
763
815
|
}
|
|
816
|
+
async function runAppGeneration(args) {
|
|
817
|
+
const options = {};
|
|
818
|
+
for (let i = 0; i < args.length; i++) {
|
|
819
|
+
const arg = args[i];
|
|
820
|
+
if (arg === "--template-id") options.templateId = args[++i];
|
|
821
|
+
else if (arg === "--params") {
|
|
822
|
+
try {
|
|
823
|
+
options.params = JSON.parse(args[++i]);
|
|
824
|
+
} catch (e) {
|
|
825
|
+
console.error("Error: --params must be valid JSON array");
|
|
826
|
+
console.error(`Example: --params '[{"field":"prompt1","value":"hello"}]'`);
|
|
827
|
+
process.exit(1);
|
|
828
|
+
}
|
|
829
|
+
} else if (arg === "--api-key") options.apiKey = args[++i];
|
|
830
|
+
else if (arg === "--base-url") options.baseUrl = args[++i];
|
|
831
|
+
}
|
|
832
|
+
if (!options.templateId) {
|
|
833
|
+
console.error("Error: --template-id required");
|
|
834
|
+
console.error("Usage: seacloud app generation --template-id <id> --params <json>");
|
|
835
|
+
process.exit(1);
|
|
836
|
+
}
|
|
837
|
+
if (!options.params) {
|
|
838
|
+
console.error("Error: --params required");
|
|
839
|
+
console.error("Usage: seacloud app generation --template-id <id> --params <json>");
|
|
840
|
+
console.error(`Example: --params '[{"field":"prompt1","value":"hello"}]'`);
|
|
841
|
+
process.exit(1);
|
|
842
|
+
}
|
|
843
|
+
const apiKey = options.apiKey || process.env.API_SERVICE_TOKEN || "";
|
|
844
|
+
const baseUrl = options.baseUrl || process.env.SEACLOUD_BASE_URL || "http://proxy.sg.seaverse.dev";
|
|
845
|
+
const client = new SeacloudClient({ apiKey, baseUrl });
|
|
846
|
+
try {
|
|
847
|
+
console.log("Creating task...");
|
|
848
|
+
const task = await client.createTask("/model/v1/generation", {
|
|
849
|
+
model: "comfyui",
|
|
850
|
+
input: [{ params: { template_id: options.templateId, inputs: options.params } }]
|
|
851
|
+
});
|
|
852
|
+
console.log(`Task created: ${task.id}`);
|
|
853
|
+
console.log(`Initial status: ${task.status}`);
|
|
854
|
+
console.log("");
|
|
855
|
+
if (task.status === "failed") {
|
|
856
|
+
console.error("Task failed immediately:", task.error);
|
|
857
|
+
process.exit(1);
|
|
858
|
+
}
|
|
859
|
+
console.log("Polling for results...");
|
|
860
|
+
let attempt = 0;
|
|
861
|
+
const maxAttempts = 120;
|
|
862
|
+
const intervalMs = 3e3;
|
|
863
|
+
while (attempt < maxAttempts) {
|
|
864
|
+
attempt++;
|
|
865
|
+
const result = await client.getTaskStatus("/model/v1/generation", task.id);
|
|
866
|
+
process.stdout.write(`\rAttempt ${attempt}/${maxAttempts} - Status: ${result.status} `);
|
|
867
|
+
if (result.status === "completed") {
|
|
868
|
+
console.log("\n\nTask completed!");
|
|
869
|
+
console.log("\nResults:");
|
|
870
|
+
console.log(JSON.stringify(result, null, 2));
|
|
871
|
+
process.exit(0);
|
|
872
|
+
}
|
|
873
|
+
if (result.status === "failed") {
|
|
874
|
+
console.log("\n\nTask failed!");
|
|
875
|
+
console.error("Error:", result.error);
|
|
876
|
+
process.exit(1);
|
|
877
|
+
}
|
|
878
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
879
|
+
}
|
|
880
|
+
console.log("\n\nTimeout: Task did not complete within the time limit");
|
|
881
|
+
process.exit(1);
|
|
882
|
+
} catch (error) {
|
|
883
|
+
console.error("\nError:", error.message);
|
|
884
|
+
process.exit(1);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
async function runAppSearch(templateIdsStr, args) {
|
|
888
|
+
const options = { type: "comfyui" };
|
|
889
|
+
for (let i = 0; i < args.length; i++) {
|
|
890
|
+
const arg = args[i];
|
|
891
|
+
if (arg === "--type") options.type = args[++i];
|
|
892
|
+
else if (arg === "--api-key") options.apiKey = args[++i];
|
|
893
|
+
else if (arg === "--base-url") options.baseUrl = args[++i];
|
|
894
|
+
}
|
|
895
|
+
const apiKey = options.apiKey || process.env.API_SERVICE_TOKEN || "";
|
|
896
|
+
const baseUrl = options.baseUrl || process.env.SEACLOUD_BASE_URL || "http://proxy.sg.seaverse.dev";
|
|
897
|
+
initSeacloud(apiKey, { baseUrl });
|
|
898
|
+
const templateIds = templateIdsStr.split(",").map((id) => id.trim());
|
|
899
|
+
const result = await appSearch({
|
|
900
|
+
type: options.type,
|
|
901
|
+
template_ids: templateIds
|
|
902
|
+
});
|
|
903
|
+
console.log(JSON.stringify(result, null, 2));
|
|
904
|
+
}
|
|
764
905
|
async function main() {
|
|
765
906
|
const args = process.argv.slice(2);
|
|
766
907
|
if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
|
|
@@ -783,6 +924,28 @@ async function main() {
|
|
|
783
924
|
process.exit(1);
|
|
784
925
|
}
|
|
785
926
|
await runAgent(args[1], args.slice(2));
|
|
927
|
+
} else if (command === "app") {
|
|
928
|
+
const subcommand = args[1];
|
|
929
|
+
if (!subcommand) {
|
|
930
|
+
console.error("Error: subcommand required for app command");
|
|
931
|
+
console.log("Usage: seacloud app <subcommand> [options]");
|
|
932
|
+
console.log("Subcommands: search, generation");
|
|
933
|
+
process.exit(1);
|
|
934
|
+
}
|
|
935
|
+
if (subcommand === "search") {
|
|
936
|
+
if (args.length < 3) {
|
|
937
|
+
console.error("Error: template IDs required for app search command");
|
|
938
|
+
console.log('Usage: seacloud app search "<id1,id2,...>" [options]');
|
|
939
|
+
process.exit(1);
|
|
940
|
+
}
|
|
941
|
+
await runAppSearch(args[2], args.slice(3));
|
|
942
|
+
} else if (subcommand === "generation") {
|
|
943
|
+
await runAppGeneration(args.slice(2));
|
|
944
|
+
} else {
|
|
945
|
+
console.error(`Error: unknown subcommand '${subcommand}'`);
|
|
946
|
+
console.log("Available subcommands: search, generation");
|
|
947
|
+
process.exit(1);
|
|
948
|
+
}
|
|
786
949
|
} else {
|
|
787
950
|
const model = command;
|
|
788
951
|
if (model.startsWith("--")) {
|