@sogni-ai/sogni-client 5.56.2 → 5.57.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/CHANGELOG.md +14 -0
- package/README.md +24 -0
- package/dist/Projects/index.d.ts +137 -0
- package/dist/Projects/index.js +170 -0
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/utils/index.js +4 -1
- package/dist/Projects/utils/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist-esm/Projects/index.js +170 -0
- package/dist-esm/Projects/index.js.map +1 -1
- package/dist-esm/Projects/utils/index.js +4 -1
- package/dist-esm/Projects/utils/index.js.map +1 -1
- package/dist-esm/index.js +3 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/version.js +1 -1
- package/package.json +2 -1
- package/src/Projects/index.ts +296 -0
- package/src/Projects/utils/index.ts +6 -1
- package/src/index.ts +16 -1
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -125,6 +125,9 @@ class SogniClient {
|
|
|
125
125
|
constructor(config) {
|
|
126
126
|
this.account = new index_js_1.default(config);
|
|
127
127
|
this.projects = new index_js_4.default(config);
|
|
128
|
+
// An API-key session learns its address from the socket's authenticated
|
|
129
|
+
// frame; before that arrives, `me()` answers it.
|
|
130
|
+
this.projects._setAccountAddressResolver(() => __awaiter(this, void 0, void 0, function* () { return this.account.currentAccount.walletAddress || (yield this.account.me()).walletAddress; }));
|
|
128
131
|
this.stats = new index_js_8.default(config);
|
|
129
132
|
this.chat = new index_js_5.default(config, this.projects);
|
|
130
133
|
this.workflows = new index_js_6.default(config);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,aAAa;aACpC,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,yBAAY,CAAC;gBAC9B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU;gBAC9C,OAAO,EAAE,GAAG;gBACZ,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;aACtC,CAAC,CAAC;YACH,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAExD,6CAA6C;YAC7C,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAyB,CAAC;gBAC9C,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzC,CAAC;YAED,OAAO,WAAW,CAAC;QACrB,CAAC;KAAA;CACF;AAzLD,kCAyLC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "5.
|
|
1
|
+
export declare const LIB_VERSION = "5.57.0";
|
package/dist/version.js
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LIB_VERSION = void 0;
|
|
4
4
|
// AUTO-GENERATED by scripts/generate-version.mjs — do not edit.
|
|
5
5
|
// Source of truth: package.json version.
|
|
6
|
-
exports.LIB_VERSION = '5.
|
|
6
|
+
exports.LIB_VERSION = '5.57.0';
|
|
7
7
|
//# sourceMappingURL=version.js.map
|
|
@@ -275,6 +275,18 @@ const RESUBMIT_RECONNECT_TIMEOUT_MS = 60000;
|
|
|
275
275
|
const MISSING_PROJECT_ATTEMPTS = 4;
|
|
276
276
|
const MISSING_PROJECT_RETRY_MS = 2500;
|
|
277
277
|
const IN_FLIGHT_LOOKUP_STATUSES = new Set(['pending', 'queued', 'processing']);
|
|
278
|
+
const RECENT_PROJECTS_DEFAULT_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
279
|
+
// The history API refuses a media-only lookup reaching back more than 7 days;
|
|
280
|
+
// stay a minute inside it so a slow clock cannot turn a 7-day request into a 400.
|
|
281
|
+
const RECENT_PROJECTS_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1000 - 60 * 1000;
|
|
282
|
+
/** A worker job's status in the names {@link ProjectResultJob} uses. */
|
|
283
|
+
function resultJobStatus(job) {
|
|
284
|
+
if (job.status === 'jobCompleted')
|
|
285
|
+
return 'completed';
|
|
286
|
+
if (job.status === 'jobError')
|
|
287
|
+
return job.reason === 'artistCanceled' ? 'canceled' : 'failed';
|
|
288
|
+
return job.status || 'unknown';
|
|
289
|
+
}
|
|
278
290
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
279
291
|
class ProjectsApi extends ApiGroup {
|
|
280
292
|
/** Import, inspect, discover, and remove the signed-in account's personal LoRAs. */
|
|
@@ -2094,6 +2106,164 @@ class ProjectsApi extends ApiGroup {
|
|
|
2094
2106
|
return data.project;
|
|
2095
2107
|
});
|
|
2096
2108
|
}
|
|
2109
|
+
/**
|
|
2110
|
+
* State and results of one of this account's projects by id, whenever it is
|
|
2111
|
+
* asked: while it is queued or rendering, and after it finished, including
|
|
2112
|
+
* one that finished while this client was offline, or after it stopped
|
|
2113
|
+
* waiting, or long after the socket stopped holding it for a reconnect.
|
|
2114
|
+
*
|
|
2115
|
+
* Completed renders come back with signed download URLs, minted the same way
|
|
2116
|
+
* a live result's are. A queued project carries the server's `waitingReason`,
|
|
2117
|
+
* which says whether it is held by the account's own plan concurrency or is
|
|
2118
|
+
* waiting for a worker. Needs an authenticated client; another account's or
|
|
2119
|
+
* an unknown project rejects with a 404 `ApiError`.
|
|
2120
|
+
*
|
|
2121
|
+
* @example
|
|
2122
|
+
* ```ts
|
|
2123
|
+
* const result = await sogni.projects.getResult(projectId);
|
|
2124
|
+
* if (result.finished) {
|
|
2125
|
+
* for (const job of result.jobs) if (job.url) console.log(job.url);
|
|
2126
|
+
* } else {
|
|
2127
|
+
* console.log(result.status, result.waitingReason?.message);
|
|
2128
|
+
* }
|
|
2129
|
+
* ```
|
|
2130
|
+
* @param projectId
|
|
2131
|
+
* @param options.kind - What the project produces, when the caller knows it
|
|
2132
|
+
* (`image`, `video`, `audio`, `model`). Used only when neither the model
|
|
2133
|
+
* catalog nor the stored result says, so a URL is never minted from the
|
|
2134
|
+
* wrong endpoint.
|
|
2135
|
+
*/
|
|
2136
|
+
getResult(projectId_1) {
|
|
2137
|
+
return __awaiter(this, arguments, void 0, function* (projectId, options = {}) {
|
|
2138
|
+
var _a, _b, _c, _d, _e;
|
|
2139
|
+
const assertSession = captureRequestSession(this.client.auth);
|
|
2140
|
+
const snapshot = yield this.getStatus(projectId);
|
|
2141
|
+
assertSession();
|
|
2142
|
+
const modelId = (_a = snapshot.model) === null || _a === void 0 ? void 0 : _a.id;
|
|
2143
|
+
// The stored record's model carries its media type even though ProjectModel does not declare it.
|
|
2144
|
+
const recordType = (_b = snapshot.model) === null || _b === void 0 ? void 0 : _b.type;
|
|
2145
|
+
const projectType = typeof recordType === 'string' ? recordType : undefined;
|
|
2146
|
+
const jobs = [];
|
|
2147
|
+
const seen = new Set();
|
|
2148
|
+
for (const job of [...(snapshot.completedWorkerJobs || []), ...(snapshot.workerJobs || [])]) {
|
|
2149
|
+
const id = job.imgID || job.id;
|
|
2150
|
+
if (!id || seen.has(id))
|
|
2151
|
+
continue;
|
|
2152
|
+
seen.add(id);
|
|
2153
|
+
const status = resultJobStatus(job);
|
|
2154
|
+
const entry = { id, status };
|
|
2155
|
+
if (status !== 'completed' && job.reason)
|
|
2156
|
+
entry.reason = job.reason;
|
|
2157
|
+
if (typeof job.seedUsed === 'number' && job.seedUsed >= 0)
|
|
2158
|
+
entry.seed = job.seedUsed;
|
|
2159
|
+
if (status === 'completed') {
|
|
2160
|
+
// Same rule as a live result: withheld only when the filter fired and
|
|
2161
|
+
// no advisory label says the media was delivered anyway.
|
|
2162
|
+
if (job.triggeredNSFWFilter === true && job.nsfwDetected !== true) {
|
|
2163
|
+
entry.urlUnavailable = 'sensitiveContent';
|
|
2164
|
+
}
|
|
2165
|
+
else if (typeof job.resultUrl === 'string' && job.resultUrl) {
|
|
2166
|
+
entry.url = job.resultUrl;
|
|
2167
|
+
}
|
|
2168
|
+
else {
|
|
2169
|
+
const result = resultMediaEvidence(Object.assign(Object.assign({}, (job.result || {})), { outputFormat: (_c = job.outputFormat) !== null && _c !== void 0 ? _c : (_d = job.result) === null || _d === void 0 ? void 0 : _d.outputFormat }));
|
|
2170
|
+
const kind = (_e = this._resultMediaKind({ modelId, projectType, result })) !== null && _e !== void 0 ? _e : options.kind;
|
|
2171
|
+
if (!kind) {
|
|
2172
|
+
entry.urlUnavailable = 'unknownMediaKind';
|
|
2173
|
+
}
|
|
2174
|
+
else {
|
|
2175
|
+
entry.kind = kind;
|
|
2176
|
+
try {
|
|
2177
|
+
entry.url = yield this._mintResultUrl({
|
|
2178
|
+
projectId: snapshot.id,
|
|
2179
|
+
jobId: id,
|
|
2180
|
+
kind,
|
|
2181
|
+
audioContentType: result === null || result === void 0 ? void 0 : result.contentType
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
catch (error) {
|
|
2185
|
+
this.client.logger.error(`Failed to sign a download URL for ${snapshot.id}/${id}`);
|
|
2186
|
+
this.client.logger.error(error);
|
|
2187
|
+
entry.urlUnavailable = 'downloadUrlFailed';
|
|
2188
|
+
}
|
|
2189
|
+
assertSession();
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
jobs.push(entry);
|
|
2194
|
+
}
|
|
2195
|
+
return Object.assign(Object.assign(Object.assign({ id: snapshot.id, status: snapshot.status, finished: snapshot.finished }, (modelId ? { modelId } : {})), (snapshot.waitingReason !== undefined ? { waitingReason: snapshot.waitingReason } : {})), { jobs });
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
/**
|
|
2199
|
+
* This account's recently completed projects that produced media, newest
|
|
2200
|
+
* first, read from the durable history rather than the socket. It includes
|
|
2201
|
+
* projects that finished while no client was connected, and ones the socket
|
|
2202
|
+
* has stopped holding for a reconnect (it keeps a finished project for one
|
|
2203
|
+
* hour). Pass a project's id to {@link getResult} for its download URLs.
|
|
2204
|
+
*
|
|
2205
|
+
* Reaches back at most 7 days. Needs a signed-in account.
|
|
2206
|
+
*
|
|
2207
|
+
* @example
|
|
2208
|
+
* ```ts
|
|
2209
|
+
* const recent = await sogni.projects.listRecent({ since: Date.now() - 6 * 3600_000 });
|
|
2210
|
+
* for (const project of recent) {
|
|
2211
|
+
* const result = await sogni.projects.getResult(project.id);
|
|
2212
|
+
* }
|
|
2213
|
+
* ```
|
|
2214
|
+
*/
|
|
2215
|
+
listRecent() {
|
|
2216
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
2217
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2218
|
+
const assertSession = captureRequestSession(this.client.auth);
|
|
2219
|
+
const address = yield this._resolveAccountAddress();
|
|
2220
|
+
assertSession();
|
|
2221
|
+
if (!address) {
|
|
2222
|
+
throw new Error('listRecent needs a signed-in account');
|
|
2223
|
+
}
|
|
2224
|
+
const now = Date.now();
|
|
2225
|
+
const requestedSince = options.since instanceof Date
|
|
2226
|
+
? options.since.getTime()
|
|
2227
|
+
: typeof options.since === 'number'
|
|
2228
|
+
? options.since
|
|
2229
|
+
: now - RECENT_PROJECTS_DEFAULT_WINDOW_MS;
|
|
2230
|
+
const since = Math.max(requestedSince, now - RECENT_PROJECTS_MAX_WINDOW_MS);
|
|
2231
|
+
const limit = Math.min(100, Math.max(1, Math.floor((_a = options.limit) !== null && _a !== void 0 ? _a : 50)));
|
|
2232
|
+
const { data } = yield this.client.rest.get('/v1/jobs/list', Object.assign({ role: 'artist', address, state: 'completed', mediaOnly: true, since,
|
|
2233
|
+
limit }, (options.appSource ? { appSource: options.appSource } : {})));
|
|
2234
|
+
assertSession();
|
|
2235
|
+
const projects = new Map();
|
|
2236
|
+
for (const job of (data === null || data === void 0 ? void 0 : data.jobs) || []) {
|
|
2237
|
+
const projectId = (_b = job.parentRequest) === null || _b === void 0 ? void 0 : _b.id;
|
|
2238
|
+
if (!projectId)
|
|
2239
|
+
continue;
|
|
2240
|
+
let project = projects.get(projectId);
|
|
2241
|
+
if (!project) {
|
|
2242
|
+
project = Object.assign(Object.assign(Object.assign(Object.assign({ id: projectId }, (((_d = (_c = job.parentRequest) === null || _c === void 0 ? void 0 : _c.model) === null || _d === void 0 ? void 0 : _d.id) ? { modelId: job.parentRequest.model.id } : {})), (((_f = (_e = job.parentRequest) === null || _e === void 0 ? void 0 : _e.model) === null || _f === void 0 ? void 0 : _f.name) ? { modelName: job.parentRequest.model.name } : {})), (((_g = job.parentRequest) === null || _g === void 0 ? void 0 : _g.appSource) ? { appSource: job.parentRequest.appSource } : {})), { jobs: [] });
|
|
2243
|
+
projects.set(projectId, project);
|
|
2244
|
+
}
|
|
2245
|
+
const finishedAt = typeof job.endTime === 'number' && job.endTime > 0 ? job.endTime : undefined;
|
|
2246
|
+
project.jobs.push(Object.assign({ id: job.imgID || job.id, status: resultJobStatus(job), sensitiveContentWithheld: job.triggeredNSFWFilter === true && job.nsfwDetected !== true }, (finishedAt ? { finishedAt } : {})));
|
|
2247
|
+
if (finishedAt && (!project.finishedAt || finishedAt > project.finishedAt)) {
|
|
2248
|
+
project.finishedAt = finishedAt;
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
return [...projects.values()].sort((a, b) => { var _a, _b; return ((_a = b.finishedAt) !== null && _a !== void 0 ? _a : 0) - ((_b = a.finishedAt) !== null && _b !== void 0 ? _b : 0); });
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* How {@link listRecent} learns the signed-in account's address. Set by
|
|
2256
|
+
* `SogniClient`, which owns the account.
|
|
2257
|
+
* @internal
|
|
2258
|
+
*/
|
|
2259
|
+
_setAccountAddressResolver(resolve) {
|
|
2260
|
+
this._accountAddress = resolve;
|
|
2261
|
+
}
|
|
2262
|
+
_resolveAccountAddress() {
|
|
2263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2264
|
+
return this._accountAddress ? this._accountAddress() : undefined;
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2097
2267
|
/**
|
|
2098
2268
|
* Ids of this account's projects that are currently live on the socket,
|
|
2099
2269
|
* including ones still queued with no worker assigned.
|