@pippit-dev/cli 1.0.3 → 1.0.5

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/checksums.txt CHANGED
@@ -1,6 +1,6 @@
1
- e344cebed19cb97f0aef66df54118cb7425714d614f2488c1072ff72d24d91cf pippit-tool-cli-1.0.3-darwin-amd64.tar.gz
2
- a1a516570d4553ef0514442f938da11f0147ad524c9fa7fb078a1ab5d1d0e27d pippit-tool-cli-1.0.3-darwin-arm64.tar.gz
3
- b7840c3b3d6cab08d74de8af15a88f09e9bc5f7c98cc14f7d80487edad505bfe pippit-tool-cli-1.0.3-linux-amd64.tar.gz
4
- 9ef478103cf1e04d825da9a9e1065e76fec6e8e79407fa4543c8010c54ca1bb6 pippit-tool-cli-1.0.3-linux-arm64.tar.gz
5
- f691764e9d5be6fe2d05b2039318458bb1c5763c5e17060389ba39d2b358f2b6 pippit-tool-cli-1.0.3-windows-amd64.zip
6
- 58899eafda91b4d1c9768d3aaa8d1d04279b7f7f7c2a18541a9873da33882960 pippit-tool-cli-1.0.3-windows-arm64.zip
1
+ 49044de4df08065cb51223c192dffa9e67d19c7a7013d5cd1c9e40125c5f4481 pippit-tool-cli-1.0.5-darwin-amd64.tar.gz
2
+ 22708f0a82207cbf1715297a71f0c926b2a29a1adf6cfc7192767ea5cbc43f0c pippit-tool-cli-1.0.5-darwin-arm64.tar.gz
3
+ 9a0b0139343013f3296fa81b4ea21060580a682485ffa34a8b4241621496ae89 pippit-tool-cli-1.0.5-linux-amd64.tar.gz
4
+ 4b08d015ea34b3e92a00fed7c91731614bd19571812889c5c84b36d976c5d667 pippit-tool-cli-1.0.5-linux-arm64.tar.gz
5
+ 74932104a77ddb87c9388eb8549fe1951c1d437433e0bd836e66995b0dfb5d32 pippit-tool-cli-1.0.5-windows-amd64.zip
6
+ 1219784da1a712bb722a1348d342371783b21141db061817c672a3dd488c868c pippit-tool-cli-1.0.5-windows-arm64.zip
@@ -26,7 +26,7 @@ func NewQueryResultCommand(stdout, stderr io.Writer, runner *common.Runner) *cob
26
26
  "run_id": strings.TrimSpace(opts.RunID),
27
27
  "download_dir": strings.TrimSpace(opts.DownloadDir),
28
28
  })
29
- return err
29
+ result = queryResultFromError(err, opts)
30
30
  }
31
31
  encoder := json.NewEncoder(stdout)
32
32
  encoder.SetIndent("", " ")
@@ -40,3 +40,15 @@ func NewQueryResultCommand(stdout, stderr io.Writer, runner *common.Runner) *cob
40
40
  cmd.Flags().StringVar(&opts.DownloadDir, "download-dir", "", "directory to download completed videos into")
41
41
  return cmd
42
42
  }
43
+
44
+ func queryResultFromError(err error, opts *internalgen.QueryResultOptions) *internalgen.QueryResultResult {
45
+ result := &internalgen.QueryResultResult{
46
+ ErrorMessage: err.Error(),
47
+ Videos: []internalgen.QueryResultVideo{},
48
+ }
49
+ if opts != nil {
50
+ result.ThreadID = strings.TrimSpace(opts.ThreadID)
51
+ result.RunID = strings.TrimSpace(opts.RunID)
52
+ }
53
+ return result
54
+ }
@@ -384,30 +384,64 @@ func TestQueryResultIgnoresVideoDataWithoutVideoSubType(t *testing.T) {
384
384
  "--download-dir", t.TempDir(),
385
385
  })
386
386
 
387
- err := root.Execute()
388
- if err == nil {
389
- t.Fatal("Execute() error = nil, want no downloadable video error")
387
+ if err := root.Execute(); err != nil {
388
+ t.Fatalf("Execute() error = %v, stderr = %s", err, stderr.String())
389
+ }
390
+ got := decodeJSON(t, stdout.Bytes())
391
+ if got["completed"] != false {
392
+ t.Fatalf("completed = %v, want false", got["completed"])
393
+ }
394
+ if got["thread_id"] != "thread_123" || got["run_id"] != "run_456" {
395
+ t.Fatalf("ids = (%v, %v), want thread/run ids", got["thread_id"], got["run_id"])
390
396
  }
391
- if !strings.Contains(err.Error(), "下载失败:未找到可下载的视频产物") {
392
- t.Fatalf("error = %q, want no downloadable video error", err)
397
+ if got["error_message"] != "下载失败:未找到可下载的视频产物" {
398
+ t.Fatalf("error_message = %v, want no downloadable video error", got["error_message"])
393
399
  }
394
- if stdout.Len() != 0 {
395
- t.Fatalf("stdout = %q, want empty", stdout.String())
400
+ videos, ok := got["videos"].([]any)
401
+ if !ok || len(videos) != 0 {
402
+ t.Fatalf("videos = %#v, want empty", got["videos"])
396
403
  }
397
404
  }
398
405
 
399
- func TestQueryResultErrorLogIncludesLogID(t *testing.T) {
406
+ func TestQueryResultValidationErrorReturnsJSON(t *testing.T) {
407
+ var stdout, stderr bytes.Buffer
408
+ root := newTestRootCommand(t, &stdout, &stderr, "http://127.0.0.1")
409
+ root.SetArgs([]string{
410
+ "query-result",
411
+ "--run-id", "run_456",
412
+ "--download-dir", t.TempDir(),
413
+ })
414
+
415
+ if err := root.Execute(); err != nil {
416
+ t.Fatalf("Execute() error = %v, stderr = %s", err, stderr.String())
417
+ }
418
+ got := decodeJSON(t, stdout.Bytes())
419
+ if got["completed"] != false {
420
+ t.Fatalf("completed = %v, want false", got["completed"])
421
+ }
422
+ if got["thread_id"] != "" || got["run_id"] != "run_456" {
423
+ t.Fatalf("ids = (%v, %v), want empty thread_id and run_id", got["thread_id"], got["run_id"])
424
+ }
425
+ if got["error_message"] != "查询失败:缺少必填参数 --thread-id" {
426
+ t.Fatalf("error_message = %v, want validation error", got["error_message"])
427
+ }
428
+ videos, ok := got["videos"].([]any)
429
+ if !ok || len(videos) != 0 {
430
+ t.Fatalf("videos = %#v, want empty", got["videos"])
431
+ }
432
+ }
433
+
434
+ func TestQueryResultGetThreadBusinessErrorReturnsErrorMessage(t *testing.T) {
400
435
  server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
401
436
  switch r.URL.Path {
402
437
  case "/api/biz/v1/skill/get_thread":
403
- _, _ = w.Write([]byte(`{"ret":"5","errmsg":"创作失败","log_id":"log_456"}`))
438
+ _, _ = w.Write([]byte(`{"ret":"5","errmsg":"创作失败:暂时无法生成","log_id":"log_456"}`))
404
439
  default:
405
440
  t.Fatalf("unexpected path %s", r.URL.Path)
406
441
  }
407
442
  }))
408
443
  defer server.Close()
409
444
 
410
- clearDailyErrorLog(t)
411
445
  var stdout, stderr bytes.Buffer
412
446
  root := newTestRootCommand(t, &stdout, &stderr, server.URL)
413
447
  root.SetArgs([]string{
@@ -417,23 +451,22 @@ func TestQueryResultErrorLogIncludesLogID(t *testing.T) {
417
451
  "--download-dir", t.TempDir(),
418
452
  })
419
453
 
420
- err := root.Execute()
421
- if err == nil {
422
- t.Fatal("Execute() error = nil, want get_thread error")
454
+ if err := root.Execute(); err != nil {
455
+ t.Fatalf("Execute() error = %v, stderr = %s", err, stderr.String())
423
456
  }
424
- entries := readDailyErrorLog(t)
425
- if len(entries) != 1 {
426
- t.Fatalf("log entries = %d, want 1: %#v", len(entries), entries)
457
+ got := decodeJSON(t, stdout.Bytes())
458
+ if got["completed"] != true {
459
+ t.Fatalf("completed = %v, want true", got["completed"])
427
460
  }
428
- fields, ok := entries[0]["fields"].(map[string]any)
429
- if !ok {
430
- t.Fatalf("fields = %#v, want object", entries[0]["fields"])
461
+ if got["thread_id"] != "thread_123" || got["run_id"] != "run_456" {
462
+ t.Fatalf("ids = (%v, %v), want thread/run ids", got["thread_id"], got["run_id"])
431
463
  }
432
- if fields["log_id"] != "log_456" {
433
- t.Fatalf("log_id = %v, want log_456", fields["log_id"])
464
+ if got["error_message"] != "创作失败:暂时无法生成 log_id=log_456" {
465
+ t.Fatalf("error_message = %v, want get_thread business error", got["error_message"])
434
466
  }
435
- if fields["thread_id"] != "thread_123" || fields["run_id"] != "run_456" {
436
- t.Fatalf("fields = %#v, want thread/run ids", fields)
467
+ videos, ok := got["videos"].([]any)
468
+ if !ok || len(videos) != 0 {
469
+ t.Fatalf("videos = %#v, want empty", got["videos"])
437
470
  }
438
471
  }
439
472
 
@@ -89,9 +89,6 @@ func UploadFile(ctx context.Context, opts UploadFileOptions, runner *Runner) (*U
89
89
  }
90
90
 
91
91
  assetID := strings.TrimSpace(resp.Data.PippitAssetID)
92
- if assetID == "" {
93
- assetID = strings.TrimSpace(resp.Data.AssetID)
94
- }
95
92
  if assetID == "" {
96
93
  return nil, fmt.Errorf("上传文件响应缺少 pippit_asset_id")
97
94
  }
@@ -3,6 +3,7 @@ package generate_video
3
3
  import (
4
4
  "context"
5
5
  "encoding/json"
6
+ "errors"
6
7
  "fmt"
7
8
  "path/filepath"
8
9
  "strconv"
@@ -89,6 +90,9 @@ func QueryResult(ctx context.Context, opts *QueryResultOptions, runner *common.R
89
90
  RunID: opts.RunID,
90
91
  }, runner)
91
92
  if err != nil {
93
+ if result, ok := queryResultFromGetThreadBusinessError(err, opts); ok {
94
+ return result, nil
95
+ }
92
96
  return nil, fmt.Errorf("查询失败:%w", err)
93
97
  }
94
98
 
@@ -159,6 +163,35 @@ func QueryResult(ctx context.Context, opts *QueryResultOptions, runner *common.R
159
163
  }, nil
160
164
  }
161
165
 
166
+ func queryResultFromGetThreadBusinessError(err error, opts *QueryResultOptions) (*QueryResultResult, bool) {
167
+ var logErr *common.LogIDError
168
+ if !errors.As(err, &logErr) {
169
+ return nil, false
170
+ }
171
+ message := getThreadBusinessErrorMessage(logErr.Message)
172
+ if message == "" {
173
+ message = "查询失败"
174
+ }
175
+ if logID := logErr.LogID(); logID != "" {
176
+ message = fmt.Sprintf("%s log_id=%s", message, logID)
177
+ }
178
+ return &QueryResultResult{
179
+ Completed: true,
180
+ ThreadID: opts.ThreadID,
181
+ RunID: opts.RunID,
182
+ ErrorMessage: message,
183
+ Videos: []QueryResultVideo{},
184
+ }, true
185
+ }
186
+
187
+ func getThreadBusinessErrorMessage(message string) string {
188
+ message = strings.TrimSpace(message)
189
+ if idx := strings.Index(message, "errmsg="); idx >= 0 {
190
+ return strings.TrimSpace(message[idx+len("errmsg="):])
191
+ }
192
+ return message
193
+ }
194
+
162
195
  func validateQueryResultOptions(opts *QueryResultOptions) error {
163
196
  if opts == nil {
164
197
  return fmt.Errorf("查询失败:缺少必填参数 --thread-id")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pippit-dev/cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Pippit CLI",
5
5
  "bin": {
6
6
  "pippit-tool-cli": "scripts/run.js"