@clickraft/cli 0.8.7 → 0.8.8

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
@@ -813,6 +813,44 @@ function matchesPrefix(content, prefix) {
813
813
  }
814
814
  return true;
815
815
  }
816
+ function waitForGeneration(params) {
817
+ return longPoll({
818
+ // Forward the iteration signal so the in-flight server hold is aborted as
819
+ // soon as the overall deadline expires — otherwise `--timeout 1` would still
820
+ // block for the full server long-poll round.
821
+ fetcher: (args) => params.client.request({
822
+ method: "GET",
823
+ path: `/jobs/${encodeURIComponent(params.jobId)}`,
824
+ query: { wait: params.serverWaitSeconds },
825
+ responseSchema: params.resultSchema,
826
+ signal: args?.signal
827
+ }),
828
+ isTerminal: params.isTerminal,
829
+ timeoutMs: params.timeoutMs,
830
+ signal: params.signal
831
+ });
832
+ }
833
+ async function createGeneration(params) {
834
+ const created = await params.client.request({
835
+ method: "POST",
836
+ path: "/jobs",
837
+ body: params.body,
838
+ responseSchema: params.createSchema,
839
+ signal: params.signal
840
+ });
841
+ if (!params.wait) {
842
+ return params.projectCreated(created, params.modelSlug);
843
+ }
844
+ return waitForGeneration({
845
+ client: params.client,
846
+ jobId: created.jobId,
847
+ timeoutMs: params.timeoutMs,
848
+ serverWaitSeconds: params.serverWaitSeconds,
849
+ signal: params.signal,
850
+ resultSchema: params.resultSchema,
851
+ isTerminal: params.isTerminal
852
+ });
853
+ }
816
854
 
817
855
  // src/errors/codes.ts
818
856
  var LOGIN_HINT = "Run `clickraft login` to authenticate.";
@@ -1902,37 +1940,19 @@ function isUrlLike(value) {
1902
1940
  return value.startsWith("http://") || value.startsWith("https://");
1903
1941
  }
1904
1942
 
1905
- // src/commands/generate/get.ts
1906
- async function generateGet(opts) {
1907
- const client = opts.client ?? await buildGenerateClient(opts);
1908
- return client.request({
1909
- method: "GET",
1910
- path: `/jobs/${encodeURIComponent(opts.jobId)}`,
1911
- query: opts.waitSeconds && opts.waitSeconds > 0 ? { wait: opts.waitSeconds } : void 0,
1912
- responseSchema: GenerationResultSchema,
1913
- signal: opts.signal
1914
- });
1915
- }
1916
-
1917
1943
  // src/commands/generate/wait.ts
1918
1944
  var DEFAULT_WAIT_TIMEOUT_SECONDS = 120;
1919
1945
  var SERVER_LONG_POLL_SECONDS = 30;
1920
1946
  async function generateWait(opts) {
1921
1947
  const client = opts.client ?? await buildGenerateClient(opts);
1922
- const timeoutSeconds = opts.timeoutSeconds ?? DEFAULT_WAIT_TIMEOUT_SECONDS;
1923
- return longPoll({
1924
- // Forward the iteration signal so the in-flight server hold is aborted
1925
- // as soon as the overall deadline expires — otherwise `--timeout 1` would
1926
- // still block for the full 30s server long-poll round.
1927
- fetcher: (args) => generateGet({
1928
- jobId: opts.jobId,
1929
- waitSeconds: SERVER_LONG_POLL_SECONDS,
1930
- client,
1931
- signal: args?.signal
1932
- }),
1933
- isTerminal: (r) => isTerminalStatus(r.status),
1934
- timeoutMs: timeoutSeconds * 1e3,
1935
- signal: opts.signal
1948
+ return waitForGeneration({
1949
+ client,
1950
+ jobId: opts.jobId,
1951
+ timeoutMs: (opts.timeoutSeconds ?? DEFAULT_WAIT_TIMEOUT_SECONDS) * 1e3,
1952
+ serverWaitSeconds: SERVER_LONG_POLL_SECONDS,
1953
+ signal: opts.signal,
1954
+ resultSchema: GenerationResultSchema,
1955
+ isTerminal: (r) => isTerminalStatus(r.status)
1936
1956
  });
1937
1957
  }
1938
1958
 
@@ -1950,22 +1970,18 @@ async function generateCreate(opts) {
1950
1970
  signal: opts.signal
1951
1971
  });
1952
1972
  const body = buildRequestBody({ ...opts, referenceImages });
1953
- const created = await client.request({
1954
- method: "POST",
1955
- path: "/jobs",
1956
- body,
1957
- responseSchema: GenerateCreateResponseSchema,
1958
- signal: opts.signal
1959
- });
1960
- const wait = opts.wait ?? true;
1961
- if (!wait) {
1962
- return projectCreateToResult(created, opts.modelSlug);
1963
- }
1964
- return generateWait({
1965
- jobId: created.jobId,
1966
- timeoutSeconds: opts.timeoutSeconds ?? DEFAULT_WAIT_TIMEOUT_SECONDS,
1973
+ return createGeneration({
1967
1974
  client,
1968
- signal: opts.signal
1975
+ body,
1976
+ modelSlug: opts.modelSlug,
1977
+ wait: opts.wait ?? true,
1978
+ timeoutMs: (opts.timeoutSeconds ?? DEFAULT_WAIT_TIMEOUT_SECONDS) * 1e3,
1979
+ serverWaitSeconds: SERVER_LONG_POLL_SECONDS,
1980
+ signal: opts.signal,
1981
+ createSchema: GenerateCreateResponseSchema,
1982
+ resultSchema: GenerationResultSchema,
1983
+ isTerminal: (r) => isTerminalStatus(r.status),
1984
+ projectCreated: projectCreateToResult
1969
1985
  });
1970
1986
  }
1971
1987
  async function resolveReferenceImages(args) {
@@ -2048,6 +2064,18 @@ function projectCreateToResult(response, modelSlug) {
2048
2064
  };
2049
2065
  }
2050
2066
 
2067
+ // src/commands/generate/get.ts
2068
+ async function generateGet(opts) {
2069
+ const client = opts.client ?? await buildGenerateClient(opts);
2070
+ return client.request({
2071
+ method: "GET",
2072
+ path: `/jobs/${encodeURIComponent(opts.jobId)}`,
2073
+ query: opts.waitSeconds && opts.waitSeconds > 0 ? { wait: opts.waitSeconds } : void 0,
2074
+ responseSchema: GenerationResultSchema,
2075
+ signal: opts.signal
2076
+ });
2077
+ }
2078
+
2051
2079
  // src/cli/args.ts
2052
2080
  var ArgError = class extends Error {
2053
2081
  constructor(message) {