@artillect/cli 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,6 +3,11 @@
3
3
  // src/index.ts
4
4
  import { Command } from "commander";
5
5
 
6
+ // src/config.ts
7
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
8
+ import { homedir } from "node:os";
9
+ import { dirname, join } from "node:path";
10
+
6
11
  // ../artillect-sdk/dist/uploadMime.js
7
12
  import { basename, isAbsolute, resolve } from "node:path";
8
13
  import { access, readFile } from "node:fs/promises";
@@ -176,6 +181,8 @@ async function publicApiFetch(config, method, path, body, extraHeaders) {
176
181
  Authorization: `Bearer ${config.apiKey}`,
177
182
  Accept: "application/json"
178
183
  };
184
+ if (config.clientSource)
185
+ headers["X-Artillect-Client-Source"] = config.clientSource;
179
186
  let payload;
180
187
  if (body !== void 0) {
181
188
  headers["Content-Type"] = "application/json";
@@ -201,7 +208,8 @@ async function publicApiUploadFile(config, file) {
201
208
  method: "POST",
202
209
  headers: {
203
210
  Authorization: `Bearer ${config.apiKey}`,
204
- Accept: "application/json"
211
+ Accept: "application/json",
212
+ ...config.clientSource ? { "X-Artillect-Client-Source": config.clientSource } : {}
205
213
  },
206
214
  body: form
207
215
  });
@@ -288,7 +296,11 @@ function createClient(opts) {
288
296
  if (!apiKey)
289
297
  throw new Error("apiKey is required");
290
298
  const baseUrl = String(opts.baseUrl || "https://app.artillect.pro").trim().replace(/\/+$/, "");
291
- const config = { apiKey, baseUrl };
299
+ const config = {
300
+ apiKey,
301
+ baseUrl,
302
+ ...opts.clientSource ? { clientSource: opts.clientSource } : {}
303
+ };
292
304
  return {
293
305
  config,
294
306
  getHealth: () => publicApiFetch(config, "GET", "/api/v1/health"),
@@ -335,9 +347,6 @@ function createClient(opts) {
335
347
  }
336
348
 
337
349
  // src/config.ts
338
- import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
339
- import { homedir } from "node:os";
340
- import { dirname, join } from "node:path";
341
350
  var DEFAULT_BASE = "https://app.artillect.pro";
342
351
  function configPath() {
343
352
  const xdg = String(process.env.XDG_CONFIG_HOME || "").trim();
@@ -371,6 +380,14 @@ function requireApiKey() {
371
380
  }
372
381
  return cfg;
373
382
  }
383
+ function createCliClient(cfg) {
384
+ const resolved = cfg ?? requireApiKey();
385
+ return createClient({
386
+ apiKey: resolved.apiKey,
387
+ baseUrl: resolved.baseUrl,
388
+ clientSource: "cli"
389
+ });
390
+ }
374
391
  function saveCliConfig(cfg) {
375
392
  const path = configPath();
376
393
  mkdirSync(dirname(path), { recursive: true });
@@ -746,7 +763,7 @@ async function authStatus() {
746
763
  const envKey = Boolean(String(process.env.ARTILLECT_API_KEY || "").trim());
747
764
  try {
748
765
  const cfg = requireApiKey();
749
- const client = createClient({ apiKey: cfg.apiKey, baseUrl: cfg.baseUrl });
766
+ const client = createCliClient(cfg);
750
767
  const me = await client.getMe();
751
768
  if (!me.ok) {
752
769
  console.log(
@@ -767,7 +784,7 @@ async function authStatus() {
767
784
  // src/generate.ts
768
785
  async function cmdBalance(jsonMode) {
769
786
  const cfg = requireApiKey();
770
- const client = createClient(cfg);
787
+ const client = createCliClient(cfg);
771
788
  const res = await client.getBalance();
772
789
  if (!res.ok) fail(res);
773
790
  const body = asRecord(res.body);
@@ -822,7 +839,7 @@ async function cmdModelsGet(slug, jsonMode) {
822
839
  }
823
840
  async function cmdUpload(opts) {
824
841
  const cfg = requireApiKey();
825
- const client = createClient(cfg);
842
+ const client = createCliClient(cfg);
826
843
  const projectId = opts.projectId ? parseProjectId(opts.projectId) : void 0;
827
844
  const uploaded = await uploadLocal(
828
845
  client,
@@ -836,7 +853,7 @@ async function cmdUpload(opts) {
836
853
  }
837
854
  async function cmdEstimate(opts) {
838
855
  const cfg = requireApiKey();
839
- const client = createClient(cfg);
856
+ const client = createCliClient(cfg);
840
857
  const body = {
841
858
  type: opts.type,
842
859
  prompt: opts.prompt
@@ -849,7 +866,7 @@ async function cmdEstimate(opts) {
849
866
  }
850
867
  async function cmdGenerateImage(opts) {
851
868
  const cfg = requireApiKey();
852
- const client = createClient(cfg);
869
+ const client = createCliClient(cfg);
853
870
  const projectId = opts.projectId ? parseProjectId(opts.projectId) : void 0;
854
871
  const inputUrls = [];
855
872
  for (const ref of opts.input ?? []) {
@@ -880,7 +897,7 @@ async function cmdGenerateImage(opts) {
880
897
  }
881
898
  async function cmdGenerateVideo(opts) {
882
899
  const cfg = requireApiKey();
883
- const client = createClient(cfg);
900
+ const client = createCliClient(cfg);
884
901
  const projectId = opts.projectId ? parseProjectId(opts.projectId) : void 0;
885
902
  const body = { model: opts.model, prompt: opts.prompt };
886
903
  if (projectId != null) body.project_id = projectId;
@@ -916,7 +933,7 @@ async function cmdGenerateVideo(opts) {
916
933
  }
917
934
  async function cmdGenerateGet(taskId, jsonMode) {
918
935
  const cfg = requireApiKey();
919
- const client = createClient(cfg);
936
+ const client = createCliClient(cfg);
920
937
  const res = await client.getTask(taskId);
921
938
  if (!res.ok) fail(res);
922
939
  const body = asRecord(res.body);
@@ -924,7 +941,7 @@ async function cmdGenerateGet(taskId, jsonMode) {
924
941
  }
925
942
  async function cmdGenerateWait(opts) {
926
943
  const cfg = requireApiKey();
927
- const client = createClient(cfg);
944
+ const client = createCliClient(cfg);
928
945
  await finishAndSave(client, opts.taskId, {
929
946
  json: opts.json,
930
947
  out: opts.out,
@@ -934,7 +951,7 @@ async function cmdGenerateWait(opts) {
934
951
  }
935
952
  async function cmdGenerateCancel(taskId, jsonMode) {
936
953
  const cfg = requireApiKey();
937
- const client = createClient(cfg);
954
+ const client = createCliClient(cfg);
938
955
  const kind = inferJobKind(taskId);
939
956
  const res = kind === "image" ? await client.cancelImageGeneration(taskId) : kind === "video" ? await client.cancelVideoGeneration(taskId) : kind === "upscale" ? await client.cancelUpscaleGeneration(taskId) : kind === "mesh" ? await client.cancelMeshGeneration(taskId) : kind === "switchx" ? await client.cancelSwitchxGeneration(taskId) : null;
940
957
  if (!res) {
@@ -945,7 +962,7 @@ async function cmdGenerateCancel(taskId, jsonMode) {
945
962
  }
946
963
  async function cmdGenerateList(opts) {
947
964
  const cfg = requireApiKey();
948
- const client = createClient(cfg);
965
+ const client = createCliClient(cfg);
949
966
  const params = {
950
967
  limit: opts.limit,
951
968
  ...opts.cursor ? { cursor: opts.cursor } : {}
@@ -979,7 +996,7 @@ function itemsOf(body) {
979
996
  }
980
997
  async function cmdAssetsList(opts) {
981
998
  const cfg = requireApiKey();
982
- const client = createClient(cfg);
999
+ const client = createCliClient(cfg);
983
1000
  const res = await client.listAssets({
984
1001
  limit: opts.limit,
985
1002
  ...opts.kind ? { kind: opts.kind } : {},
@@ -1005,7 +1022,7 @@ async function cmdAssetsGet(assetId, json) {
1005
1022
  const id = assetId.trim();
1006
1023
  if (!isAssetId(id)) throw new Error(`\u043D\u0435 \u043F\u043E\u0445\u043E\u0436\u0435 \u043D\u0430 asset id: ${assetId} (\u043E\u0436\u0438\u0434\u0430\u044E ast_\u2026)`);
1007
1024
  const cfg = requireApiKey();
1008
- const client = createClient(cfg);
1025
+ const client = createCliClient(cfg);
1009
1026
  const res = await client.getAsset(id);
1010
1027
  if (!res.ok) fail(res);
1011
1028
  const body = asRecord(res.body);
@@ -1026,7 +1043,7 @@ async function cmdAssetsCopy(opts) {
1026
1043
  throw new Error("\u0443\u043A\u0430\u0436\u0438\u0442\u0435 --project <id> \u0438\u043B\u0438 --personal");
1027
1044
  }
1028
1045
  const cfg = requireApiKey();
1029
- const client = createClient(cfg);
1046
+ const client = createCliClient(cfg);
1030
1047
  const res = await client.copyAsset(
1031
1048
  id,
1032
1049
  opts.personal ? { target: "personal" } : { target: "project", project_id: parseProjectId(String(opts.projectId)) }
@@ -1046,7 +1063,7 @@ async function cmdAssetsCopy(opts) {
1046
1063
  }
1047
1064
  async function cmdProjectsList(opts) {
1048
1065
  const cfg = requireApiKey();
1049
- const client = createClient(cfg);
1066
+ const client = createCliClient(cfg);
1050
1067
  const res = await client.listProjects({
1051
1068
  limit: opts.limit,
1052
1069
  ...opts.cursor ? { cursor: opts.cursor } : {}
@@ -1063,7 +1080,7 @@ async function cmdProjectsList(opts) {
1063
1080
  async function cmdElementsList(opts) {
1064
1081
  const projectId = parseProjectId(opts.projectId);
1065
1082
  const cfg = requireApiKey();
1066
- const client = createClient(cfg);
1083
+ const client = createCliClient(cfg);
1067
1084
  const res = await client.listProjectElements(projectId, {
1068
1085
  limit: opts.limit,
1069
1086
  ...opts.kinds ? { kinds: opts.kinds } : {},
@@ -1100,7 +1117,7 @@ async function cmdElementsCreate(opts) {
1100
1117
  if (!name) throw new Error("\u0443\u043A\u0430\u0436\u0438\u0442\u0435 --name \u0431\u0435\u0437 \u043F\u0443\u0441\u0442\u043E\u0433\u043E \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F");
1101
1118
  const projectId = parseProjectId(opts.projectId);
1102
1119
  const cfg = requireApiKey();
1103
- const client = createClient(cfg);
1120
+ const client = createCliClient(cfg);
1104
1121
  let assetId = "";
1105
1122
  let imageUrl = "";
1106
1123
  let kind = String(opts.kind || "").toLowerCase();
@@ -1167,7 +1184,7 @@ function parse(raw) {
1167
1184
  return [Number(m[1]), Number(m[2]), Number(m[3])];
1168
1185
  }
1169
1186
  function cliVersion() {
1170
- return String("0.1.2");
1187
+ return String("0.1.3");
1171
1188
  }
1172
1189
  function updateAvailableMessage(local, latest) {
1173
1190
  return `\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u0430 \u043D\u043E\u0432\u0430\u044F \u0432\u0435\u0440\u0441\u0438\u044F @artillect/cli (${latest}, \u0443 \u0432\u0430\u0441 ${local}).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artillect/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Artillect CLI — генерация картинок и видео из терминала.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",