@sogni-ai/sogni-client 5.0.0-alpha.7 → 5.0.0-alpha.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/CHANGELOG.md +7 -0
- package/dist/CreativeWorkflows/Templates/index.d.ts +23 -0
- package/dist/CreativeWorkflows/Templates/index.js +57 -24
- package/dist/CreativeWorkflows/Templates/index.js.map +1 -1
- package/dist-esm/CreativeWorkflows/Templates/index.js +56 -24
- package/dist-esm/CreativeWorkflows/Templates/index.js.map +1 -1
- package/package.json +2 -1
- package/src/CreativeWorkflows/Templates/index.ts +63 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [5.0.0-alpha.8](https://github.com/Sogni-AI/sogni-client/compare/v5.0.0-alpha.7...v5.0.0-alpha.8) (2026-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **workflows:** unwrap templates api `{status,data}` envelope ([61480b5](https://github.com/Sogni-AI/sogni-client/commit/61480b5d741bcbd45f82d09f3246dafbd95bb718))
|
|
7
|
+
|
|
1
8
|
# [5.0.0-alpha.7](https://github.com/Sogni-AI/sogni-client/compare/v5.0.0-alpha.6...v5.0.0-alpha.7) (2026-05-19)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -18,6 +18,24 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import ApiGroup, { ApiConfig } from '../../ApiGroup';
|
|
20
20
|
import { ForkWorkflowTemplateBody, ListWorkflowTemplatesOptions, ListWorkflowTemplatesResult, WorkflowTemplate, WorkflowTemplateRequestOptions } from './types';
|
|
21
|
+
interface TemplateEnvelope {
|
|
22
|
+
template?: WorkflowTemplate;
|
|
23
|
+
templates?: WorkflowTemplate[];
|
|
24
|
+
next?: number | null;
|
|
25
|
+
deleted?: boolean;
|
|
26
|
+
id?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
interface RawJsonBody {
|
|
30
|
+
status?: string;
|
|
31
|
+
data?: unknown;
|
|
32
|
+
message?: string;
|
|
33
|
+
errorCode?: number;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
declare function parseSuccessEnvelope(text: string): TemplateEnvelope;
|
|
37
|
+
declare function parseErrorEnvelope(text: string): RawJsonBody;
|
|
38
|
+
declare function isWorkflowTemplate(value: unknown): value is WorkflowTemplate;
|
|
21
39
|
declare class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
22
40
|
constructor(config: ApiConfig);
|
|
23
41
|
list(options?: ListWorkflowTemplatesOptions): Promise<ListWorkflowTemplatesResult>;
|
|
@@ -30,5 +48,10 @@ declare class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
30
48
|
private fetch;
|
|
31
49
|
private toApiError;
|
|
32
50
|
}
|
|
51
|
+
export declare const __envelopeInternals: {
|
|
52
|
+
parseSuccessEnvelope: typeof parseSuccessEnvelope;
|
|
53
|
+
parseErrorEnvelope: typeof parseErrorEnvelope;
|
|
54
|
+
isWorkflowTemplate: typeof isWorkflowTemplate;
|
|
55
|
+
};
|
|
33
56
|
export default CreativeWorkflowTemplatesApi;
|
|
34
57
|
export * from './types';
|
|
@@ -44,16 +44,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
44
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
45
|
};
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.__envelopeInternals = void 0;
|
|
47
48
|
const ApiGroup_1 = __importDefault(require("../../ApiGroup"));
|
|
48
49
|
const ApiClient_1 = require("../../ApiClient");
|
|
49
|
-
|
|
50
|
+
// The api always wraps 2xx responses as `{ status: 'success', data: {...} }`.
|
|
51
|
+
// `toApiError` handles non-2xx, so this only runs on success — strip the
|
|
52
|
+
// envelope and surface the inner `data` object.
|
|
53
|
+
function parseSuccessEnvelope(text) {
|
|
50
54
|
if (!text)
|
|
51
55
|
return {};
|
|
56
|
+
let parsed;
|
|
52
57
|
try {
|
|
53
|
-
|
|
58
|
+
parsed = JSON.parse(text);
|
|
54
59
|
}
|
|
55
60
|
catch (_a) {
|
|
56
|
-
return {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
64
|
+
return {};
|
|
65
|
+
const record = parsed;
|
|
66
|
+
if (record.status === 'success' && record.data && typeof record.data === 'object'
|
|
67
|
+
&& !Array.isArray(record.data)) {
|
|
68
|
+
return record.data;
|
|
69
|
+
}
|
|
70
|
+
return record;
|
|
71
|
+
}
|
|
72
|
+
function parseErrorEnvelope(text) {
|
|
73
|
+
if (!text)
|
|
74
|
+
return {};
|
|
75
|
+
try {
|
|
76
|
+
const parsed = JSON.parse(text);
|
|
77
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
78
|
+
return parsed;
|
|
79
|
+
}
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
catch (_a) {
|
|
83
|
+
return { message: text };
|
|
57
84
|
}
|
|
58
85
|
}
|
|
59
86
|
function isWorkflowTemplate(value) {
|
|
@@ -80,61 +107,61 @@ class CreativeWorkflowTemplatesApi extends ApiGroup_1.default {
|
|
|
80
107
|
const path = query.toString()
|
|
81
108
|
? `/v1/creative-agent/workflows/templates?${query.toString()}`
|
|
82
109
|
: '/v1/creative-agent/workflows/templates';
|
|
83
|
-
const
|
|
84
|
-
const templates = Array.isArray(
|
|
85
|
-
?
|
|
110
|
+
const data = yield this.request(path, { method: 'GET', signal: options.signal });
|
|
111
|
+
const templates = Array.isArray(data.templates)
|
|
112
|
+
? data.templates.filter(isWorkflowTemplate)
|
|
86
113
|
: [];
|
|
87
|
-
const nextCursor = typeof
|
|
114
|
+
const nextCursor = typeof data.next === 'number' ? data.next : null;
|
|
88
115
|
return { templates, nextCursor };
|
|
89
116
|
});
|
|
90
117
|
}
|
|
91
118
|
get(id_1) {
|
|
92
119
|
return __awaiter(this, arguments, void 0, function* (id, options = {}) {
|
|
93
|
-
const
|
|
94
|
-
if (!isWorkflowTemplate(
|
|
120
|
+
const data = yield this.request(`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}`, { method: 'GET', signal: options.signal });
|
|
121
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
95
122
|
throw new ApiClient_1.ApiError(500, {
|
|
96
123
|
status: 'error',
|
|
97
124
|
message: 'Workflow template response missing template field',
|
|
98
125
|
errorCode: 0
|
|
99
126
|
});
|
|
100
127
|
}
|
|
101
|
-
return
|
|
128
|
+
return data.template;
|
|
102
129
|
});
|
|
103
130
|
}
|
|
104
131
|
create(template_1) {
|
|
105
132
|
return __awaiter(this, arguments, void 0, function* (template, options = {}) {
|
|
106
|
-
const
|
|
133
|
+
const data = yield this.request('/v1/creative-agent/workflows/templates', {
|
|
107
134
|
method: 'POST',
|
|
108
135
|
headers: { 'Content-Type': 'application/json' },
|
|
109
136
|
body: JSON.stringify(template),
|
|
110
137
|
signal: options.signal
|
|
111
138
|
});
|
|
112
|
-
if (!isWorkflowTemplate(
|
|
139
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
113
140
|
throw new ApiClient_1.ApiError(500, {
|
|
114
141
|
status: 'error',
|
|
115
142
|
message: 'Workflow template create response missing template field',
|
|
116
143
|
errorCode: 0
|
|
117
144
|
});
|
|
118
145
|
}
|
|
119
|
-
return
|
|
146
|
+
return data.template;
|
|
120
147
|
});
|
|
121
148
|
}
|
|
122
149
|
update(id_1, patch_1) {
|
|
123
150
|
return __awaiter(this, arguments, void 0, function* (id, patch, options = {}) {
|
|
124
|
-
const
|
|
151
|
+
const data = yield this.request(`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}`, {
|
|
125
152
|
method: 'PATCH',
|
|
126
153
|
headers: { 'Content-Type': 'application/json' },
|
|
127
154
|
body: JSON.stringify(patch),
|
|
128
155
|
signal: options.signal
|
|
129
156
|
});
|
|
130
|
-
if (!isWorkflowTemplate(
|
|
157
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
131
158
|
throw new ApiClient_1.ApiError(500, {
|
|
132
159
|
status: 'error',
|
|
133
160
|
message: 'Workflow template update response missing template field',
|
|
134
161
|
errorCode: 0
|
|
135
162
|
});
|
|
136
163
|
}
|
|
137
|
-
return
|
|
164
|
+
return data.template;
|
|
138
165
|
});
|
|
139
166
|
}
|
|
140
167
|
delete(id_1) {
|
|
@@ -147,20 +174,20 @@ class CreativeWorkflowTemplatesApi extends ApiGroup_1.default {
|
|
|
147
174
|
}
|
|
148
175
|
fork(id_1) {
|
|
149
176
|
return __awaiter(this, arguments, void 0, function* (id, body = {}, options = {}) {
|
|
150
|
-
const
|
|
177
|
+
const data = yield this.request(`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}/fork`, {
|
|
151
178
|
method: 'POST',
|
|
152
179
|
headers: { 'Content-Type': 'application/json' },
|
|
153
180
|
body: JSON.stringify(body),
|
|
154
181
|
signal: options.signal
|
|
155
182
|
});
|
|
156
|
-
if (!isWorkflowTemplate(
|
|
183
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
157
184
|
throw new ApiClient_1.ApiError(500, {
|
|
158
185
|
status: 'error',
|
|
159
186
|
message: 'Workflow template fork response missing template field',
|
|
160
187
|
errorCode: 0
|
|
161
188
|
});
|
|
162
189
|
}
|
|
163
|
-
return
|
|
190
|
+
return data.template;
|
|
164
191
|
});
|
|
165
192
|
}
|
|
166
193
|
request(path_1) {
|
|
@@ -170,7 +197,7 @@ class CreativeWorkflowTemplatesApi extends ApiGroup_1.default {
|
|
|
170
197
|
throw yield this.toApiError(response);
|
|
171
198
|
}
|
|
172
199
|
const text = yield response.text();
|
|
173
|
-
return
|
|
200
|
+
return parseSuccessEnvelope(text);
|
|
174
201
|
});
|
|
175
202
|
}
|
|
176
203
|
fetch(path_1) {
|
|
@@ -185,14 +212,20 @@ class CreativeWorkflowTemplatesApi extends ApiGroup_1.default {
|
|
|
185
212
|
if (response.status === 401 && this.client.auth.isAuthenticated) {
|
|
186
213
|
this.client.auth.clear();
|
|
187
214
|
}
|
|
188
|
-
const body =
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
const errorCode = typeof payload.errorCode === 'number' ? payload.errorCode : 0;
|
|
215
|
+
const body = parseErrorEnvelope(yield response.text());
|
|
216
|
+
const message = typeof body.message === 'string' ? body.message : response.statusText;
|
|
217
|
+
const errorCode = typeof body.errorCode === 'number' ? body.errorCode : 0;
|
|
192
218
|
return new ApiClient_1.ApiError(response.status, { status: 'error', message, errorCode });
|
|
193
219
|
});
|
|
194
220
|
}
|
|
195
221
|
}
|
|
222
|
+
// Internal: re-exported for the regression script under `scripts/`. Not part
|
|
223
|
+
// of the public API surface — direct callers should use the class methods.
|
|
224
|
+
exports.__envelopeInternals = {
|
|
225
|
+
parseSuccessEnvelope,
|
|
226
|
+
parseErrorEnvelope,
|
|
227
|
+
isWorkflowTemplate
|
|
228
|
+
};
|
|
196
229
|
exports.default = CreativeWorkflowTemplatesApi;
|
|
197
230
|
__exportStar(require("./types"), exports);
|
|
198
231
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/CreativeWorkflows/Templates/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/CreativeWorkflows/Templates/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,8DAAqD;AACrD,+CAA2C;AA0B3C,8EAA8E;AAC9E,yEAAyE;AACzE,gDAAgD;AAChD,SAAS,oBAAoB,CAAC,IAAY;IACxC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,G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,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,CAAC;YACD,MAAM,IAAI,GAAG,kBAAkB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YACvD,MAAM,OAAO,GAAG,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;YACtF,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1E,OAAO,IAAI,oBAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QAChF,CAAC;KAAA;CACF;AAED,6EAA6E;AAC7E,2EAA2E;AAC9D,QAAA,mBAAmB,GAAG;IACjC,oBAAoB;IACpB,kBAAkB;IAClB,kBAAkB;CACnB,CAAC;AAEF,kBAAe,4BAA4B,CAAC;AAC5C,0CAAwB"}
|
|
@@ -27,14 +27,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
};
|
|
28
28
|
import ApiGroup from '../../ApiGroup';
|
|
29
29
|
import { ApiError } from '../../ApiClient';
|
|
30
|
-
|
|
30
|
+
// The api always wraps 2xx responses as `{ status: 'success', data: {...} }`.
|
|
31
|
+
// `toApiError` handles non-2xx, so this only runs on success — strip the
|
|
32
|
+
// envelope and surface the inner `data` object.
|
|
33
|
+
function parseSuccessEnvelope(text) {
|
|
31
34
|
if (!text)
|
|
32
35
|
return {};
|
|
36
|
+
let parsed;
|
|
33
37
|
try {
|
|
34
|
-
|
|
38
|
+
parsed = JSON.parse(text);
|
|
35
39
|
}
|
|
36
40
|
catch (_a) {
|
|
37
|
-
return {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
44
|
+
return {};
|
|
45
|
+
const record = parsed;
|
|
46
|
+
if (record.status === 'success' && record.data && typeof record.data === 'object'
|
|
47
|
+
&& !Array.isArray(record.data)) {
|
|
48
|
+
return record.data;
|
|
49
|
+
}
|
|
50
|
+
return record;
|
|
51
|
+
}
|
|
52
|
+
function parseErrorEnvelope(text) {
|
|
53
|
+
if (!text)
|
|
54
|
+
return {};
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(text);
|
|
57
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
58
|
+
return parsed;
|
|
59
|
+
}
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
catch (_a) {
|
|
63
|
+
return { message: text };
|
|
38
64
|
}
|
|
39
65
|
}
|
|
40
66
|
function isWorkflowTemplate(value) {
|
|
@@ -61,61 +87,61 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
61
87
|
const path = query.toString()
|
|
62
88
|
? `/v1/creative-agent/workflows/templates?${query.toString()}`
|
|
63
89
|
: '/v1/creative-agent/workflows/templates';
|
|
64
|
-
const
|
|
65
|
-
const templates = Array.isArray(
|
|
66
|
-
?
|
|
90
|
+
const data = yield this.request(path, { method: 'GET', signal: options.signal });
|
|
91
|
+
const templates = Array.isArray(data.templates)
|
|
92
|
+
? data.templates.filter(isWorkflowTemplate)
|
|
67
93
|
: [];
|
|
68
|
-
const nextCursor = typeof
|
|
94
|
+
const nextCursor = typeof data.next === 'number' ? data.next : null;
|
|
69
95
|
return { templates, nextCursor };
|
|
70
96
|
});
|
|
71
97
|
}
|
|
72
98
|
get(id_1) {
|
|
73
99
|
return __awaiter(this, arguments, void 0, function* (id, options = {}) {
|
|
74
|
-
const
|
|
75
|
-
if (!isWorkflowTemplate(
|
|
100
|
+
const data = yield this.request(`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}`, { method: 'GET', signal: options.signal });
|
|
101
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
76
102
|
throw new ApiError(500, {
|
|
77
103
|
status: 'error',
|
|
78
104
|
message: 'Workflow template response missing template field',
|
|
79
105
|
errorCode: 0
|
|
80
106
|
});
|
|
81
107
|
}
|
|
82
|
-
return
|
|
108
|
+
return data.template;
|
|
83
109
|
});
|
|
84
110
|
}
|
|
85
111
|
create(template_1) {
|
|
86
112
|
return __awaiter(this, arguments, void 0, function* (template, options = {}) {
|
|
87
|
-
const
|
|
113
|
+
const data = yield this.request('/v1/creative-agent/workflows/templates', {
|
|
88
114
|
method: 'POST',
|
|
89
115
|
headers: { 'Content-Type': 'application/json' },
|
|
90
116
|
body: JSON.stringify(template),
|
|
91
117
|
signal: options.signal
|
|
92
118
|
});
|
|
93
|
-
if (!isWorkflowTemplate(
|
|
119
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
94
120
|
throw new ApiError(500, {
|
|
95
121
|
status: 'error',
|
|
96
122
|
message: 'Workflow template create response missing template field',
|
|
97
123
|
errorCode: 0
|
|
98
124
|
});
|
|
99
125
|
}
|
|
100
|
-
return
|
|
126
|
+
return data.template;
|
|
101
127
|
});
|
|
102
128
|
}
|
|
103
129
|
update(id_1, patch_1) {
|
|
104
130
|
return __awaiter(this, arguments, void 0, function* (id, patch, options = {}) {
|
|
105
|
-
const
|
|
131
|
+
const data = yield this.request(`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}`, {
|
|
106
132
|
method: 'PATCH',
|
|
107
133
|
headers: { 'Content-Type': 'application/json' },
|
|
108
134
|
body: JSON.stringify(patch),
|
|
109
135
|
signal: options.signal
|
|
110
136
|
});
|
|
111
|
-
if (!isWorkflowTemplate(
|
|
137
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
112
138
|
throw new ApiError(500, {
|
|
113
139
|
status: 'error',
|
|
114
140
|
message: 'Workflow template update response missing template field',
|
|
115
141
|
errorCode: 0
|
|
116
142
|
});
|
|
117
143
|
}
|
|
118
|
-
return
|
|
144
|
+
return data.template;
|
|
119
145
|
});
|
|
120
146
|
}
|
|
121
147
|
delete(id_1) {
|
|
@@ -128,20 +154,20 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
128
154
|
}
|
|
129
155
|
fork(id_1) {
|
|
130
156
|
return __awaiter(this, arguments, void 0, function* (id, body = {}, options = {}) {
|
|
131
|
-
const
|
|
157
|
+
const data = yield this.request(`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}/fork`, {
|
|
132
158
|
method: 'POST',
|
|
133
159
|
headers: { 'Content-Type': 'application/json' },
|
|
134
160
|
body: JSON.stringify(body),
|
|
135
161
|
signal: options.signal
|
|
136
162
|
});
|
|
137
|
-
if (!isWorkflowTemplate(
|
|
163
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
138
164
|
throw new ApiError(500, {
|
|
139
165
|
status: 'error',
|
|
140
166
|
message: 'Workflow template fork response missing template field',
|
|
141
167
|
errorCode: 0
|
|
142
168
|
});
|
|
143
169
|
}
|
|
144
|
-
return
|
|
170
|
+
return data.template;
|
|
145
171
|
});
|
|
146
172
|
}
|
|
147
173
|
request(path_1) {
|
|
@@ -151,7 +177,7 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
151
177
|
throw yield this.toApiError(response);
|
|
152
178
|
}
|
|
153
179
|
const text = yield response.text();
|
|
154
|
-
return
|
|
180
|
+
return parseSuccessEnvelope(text);
|
|
155
181
|
});
|
|
156
182
|
}
|
|
157
183
|
fetch(path_1) {
|
|
@@ -166,14 +192,20 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
166
192
|
if (response.status === 401 && this.client.auth.isAuthenticated) {
|
|
167
193
|
this.client.auth.clear();
|
|
168
194
|
}
|
|
169
|
-
const body =
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
const errorCode = typeof payload.errorCode === 'number' ? payload.errorCode : 0;
|
|
195
|
+
const body = parseErrorEnvelope(yield response.text());
|
|
196
|
+
const message = typeof body.message === 'string' ? body.message : response.statusText;
|
|
197
|
+
const errorCode = typeof body.errorCode === 'number' ? body.errorCode : 0;
|
|
173
198
|
return new ApiError(response.status, { status: 'error', message, errorCode });
|
|
174
199
|
});
|
|
175
200
|
}
|
|
176
201
|
}
|
|
202
|
+
// Internal: re-exported for the regression script under `scripts/`. Not part
|
|
203
|
+
// of the public API surface — direct callers should use the class methods.
|
|
204
|
+
export const __envelopeInternals = {
|
|
205
|
+
parseSuccessEnvelope,
|
|
206
|
+
parseErrorEnvelope,
|
|
207
|
+
isWorkflowTemplate
|
|
208
|
+
};
|
|
177
209
|
export default CreativeWorkflowTemplatesApi;
|
|
178
210
|
export * from './types';
|
|
179
211
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/CreativeWorkflows/Templates/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;AAEH,OAAO,QAAuB,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/CreativeWorkflows/Templates/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;AAEH,OAAO,QAAuB,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA0B3C,8EAA8E;AAC9E,yEAAyE;AACzE,gDAAgD;AAChD,SAAS,oBAAoB,CAAC,IAAY;IACxC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAC,MA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AAM,OAAO,GAAG,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;YACtF,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1E,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;QAChF,CAAC;KAAA;CACF;AAED,6EAA6E;AAC7E,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,oBAAoB;IACpB,kBAAkB;IAClB,kBAAkB;CACnB,CAAC;AAEF,eAAe,4BAA4B,CAAC;AAC5C,cAAc,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "5.0.0-alpha.
|
|
6
|
+
"version": "5.0.0-alpha.8",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=22"
|
|
9
9
|
},
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"prepublishOnly": "npm run build",
|
|
60
60
|
"build": "npm run clean && npm run codegen && tsc --project tsconfig.json && tsc --project tsconfig.esm.json && node scripts/write-dist-esm-package-json.mjs",
|
|
61
61
|
"test:chat-routing": "npm run build && node scripts/check-chat-model-routing.cjs",
|
|
62
|
+
"test:workflow-template-envelope": "npm run build && node scripts/check-workflow-template-envelope.cjs",
|
|
62
63
|
"watch": "npm run clean && npm run codegen && tsc --watch --project tsconfig.json",
|
|
63
64
|
"watch:esm": "npm run codegen && tsc --watch --project tsconfig.esm.json",
|
|
64
65
|
"prettier": "prettier --check ./src",
|
|
@@ -30,19 +30,50 @@ import {
|
|
|
30
30
|
interface TemplateEnvelope {
|
|
31
31
|
template?: WorkflowTemplate;
|
|
32
32
|
templates?: WorkflowTemplate[];
|
|
33
|
-
|
|
33
|
+
next?: number | null;
|
|
34
|
+
deleted?: boolean;
|
|
35
|
+
id?: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface RawJsonBody {
|
|
34
40
|
status?: string;
|
|
41
|
+
data?: unknown;
|
|
35
42
|
message?: string;
|
|
36
43
|
errorCode?: number;
|
|
37
44
|
[key: string]: unknown;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
// The api always wraps 2xx responses as `{ status: 'success', data: {...} }`.
|
|
48
|
+
// `toApiError` handles non-2xx, so this only runs on success — strip the
|
|
49
|
+
// envelope and surface the inner `data` object.
|
|
50
|
+
function parseSuccessEnvelope(text: string): TemplateEnvelope {
|
|
51
|
+
if (!text) return {};
|
|
52
|
+
let parsed: unknown;
|
|
53
|
+
try {
|
|
54
|
+
parsed = JSON.parse(text);
|
|
55
|
+
} catch {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
|
59
|
+
const record = parsed as RawJsonBody;
|
|
60
|
+
if (record.status === 'success' && record.data && typeof record.data === 'object'
|
|
61
|
+
&& !Array.isArray(record.data)) {
|
|
62
|
+
return record.data as TemplateEnvelope;
|
|
63
|
+
}
|
|
64
|
+
return record as TemplateEnvelope;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseErrorEnvelope(text: string): RawJsonBody {
|
|
41
68
|
if (!text) return {};
|
|
42
69
|
try {
|
|
43
|
-
|
|
70
|
+
const parsed = JSON.parse(text) as unknown;
|
|
71
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
72
|
+
return parsed as RawJsonBody;
|
|
73
|
+
}
|
|
74
|
+
return {};
|
|
44
75
|
} catch {
|
|
45
|
-
return {
|
|
76
|
+
return { message: text };
|
|
46
77
|
}
|
|
47
78
|
}
|
|
48
79
|
|
|
@@ -70,47 +101,47 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
70
101
|
? `/v1/creative-agent/workflows/templates?${query.toString()}`
|
|
71
102
|
: '/v1/creative-agent/workflows/templates';
|
|
72
103
|
|
|
73
|
-
const
|
|
74
|
-
const templates = Array.isArray(
|
|
75
|
-
?
|
|
104
|
+
const data = await this.request(path, { method: 'GET', signal: options.signal });
|
|
105
|
+
const templates = Array.isArray(data.templates)
|
|
106
|
+
? data.templates.filter(isWorkflowTemplate)
|
|
76
107
|
: [];
|
|
77
|
-
const nextCursor = typeof
|
|
108
|
+
const nextCursor = typeof data.next === 'number' ? data.next : null;
|
|
78
109
|
return { templates, nextCursor };
|
|
79
110
|
}
|
|
80
111
|
|
|
81
112
|
async get(id: string, options: WorkflowTemplateRequestOptions = {}): Promise<WorkflowTemplate> {
|
|
82
|
-
const
|
|
113
|
+
const data = await this.request(
|
|
83
114
|
`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}`,
|
|
84
115
|
{ method: 'GET', signal: options.signal }
|
|
85
116
|
);
|
|
86
|
-
if (!isWorkflowTemplate(
|
|
117
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
87
118
|
throw new ApiError(500, {
|
|
88
119
|
status: 'error',
|
|
89
120
|
message: 'Workflow template response missing template field',
|
|
90
121
|
errorCode: 0
|
|
91
122
|
});
|
|
92
123
|
}
|
|
93
|
-
return
|
|
124
|
+
return data.template;
|
|
94
125
|
}
|
|
95
126
|
|
|
96
127
|
async create(
|
|
97
128
|
template: WorkflowTemplate,
|
|
98
129
|
options: WorkflowTemplateRequestOptions = {}
|
|
99
130
|
): Promise<WorkflowTemplate> {
|
|
100
|
-
const
|
|
131
|
+
const data = await this.request('/v1/creative-agent/workflows/templates', {
|
|
101
132
|
method: 'POST',
|
|
102
133
|
headers: { 'Content-Type': 'application/json' },
|
|
103
134
|
body: JSON.stringify(template),
|
|
104
135
|
signal: options.signal
|
|
105
136
|
});
|
|
106
|
-
if (!isWorkflowTemplate(
|
|
137
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
107
138
|
throw new ApiError(500, {
|
|
108
139
|
status: 'error',
|
|
109
140
|
message: 'Workflow template create response missing template field',
|
|
110
141
|
errorCode: 0
|
|
111
142
|
});
|
|
112
143
|
}
|
|
113
|
-
return
|
|
144
|
+
return data.template;
|
|
114
145
|
}
|
|
115
146
|
|
|
116
147
|
async update(
|
|
@@ -118,7 +149,7 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
118
149
|
patch: Partial<WorkflowTemplate>,
|
|
119
150
|
options: WorkflowTemplateRequestOptions = {}
|
|
120
151
|
): Promise<WorkflowTemplate> {
|
|
121
|
-
const
|
|
152
|
+
const data = await this.request(
|
|
122
153
|
`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}`,
|
|
123
154
|
{
|
|
124
155
|
method: 'PATCH',
|
|
@@ -127,14 +158,14 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
127
158
|
signal: options.signal
|
|
128
159
|
}
|
|
129
160
|
);
|
|
130
|
-
if (!isWorkflowTemplate(
|
|
161
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
131
162
|
throw new ApiError(500, {
|
|
132
163
|
status: 'error',
|
|
133
164
|
message: 'Workflow template update response missing template field',
|
|
134
165
|
errorCode: 0
|
|
135
166
|
});
|
|
136
167
|
}
|
|
137
|
-
return
|
|
168
|
+
return data.template;
|
|
138
169
|
}
|
|
139
170
|
|
|
140
171
|
async delete(id: string, options: WorkflowTemplateRequestOptions = {}): Promise<void> {
|
|
@@ -149,7 +180,7 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
149
180
|
body: ForkWorkflowTemplateBody = {},
|
|
150
181
|
options: WorkflowTemplateRequestOptions = {}
|
|
151
182
|
): Promise<WorkflowTemplate> {
|
|
152
|
-
const
|
|
183
|
+
const data = await this.request(
|
|
153
184
|
`/v1/creative-agent/workflows/templates/${encodeURIComponent(id)}/fork`,
|
|
154
185
|
{
|
|
155
186
|
method: 'POST',
|
|
@@ -158,14 +189,14 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
158
189
|
signal: options.signal
|
|
159
190
|
}
|
|
160
191
|
);
|
|
161
|
-
if (!isWorkflowTemplate(
|
|
192
|
+
if (!isWorkflowTemplate(data.template)) {
|
|
162
193
|
throw new ApiError(500, {
|
|
163
194
|
status: 'error',
|
|
164
195
|
message: 'Workflow template fork response missing template field',
|
|
165
196
|
errorCode: 0
|
|
166
197
|
});
|
|
167
198
|
}
|
|
168
|
-
return
|
|
199
|
+
return data.template;
|
|
169
200
|
}
|
|
170
201
|
|
|
171
202
|
private async request(path: string, options: RequestInit = {}): Promise<TemplateEnvelope> {
|
|
@@ -174,7 +205,7 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
174
205
|
throw await this.toApiError(response);
|
|
175
206
|
}
|
|
176
207
|
const text = await response.text();
|
|
177
|
-
return
|
|
208
|
+
return parseSuccessEnvelope(text);
|
|
178
209
|
}
|
|
179
210
|
|
|
180
211
|
private async fetch(path: string, options: RequestInit = {}): Promise<Response> {
|
|
@@ -187,13 +218,20 @@ class CreativeWorkflowTemplatesApi extends ApiGroup {
|
|
|
187
218
|
if (response.status === 401 && this.client.auth.isAuthenticated) {
|
|
188
219
|
this.client.auth.clear();
|
|
189
220
|
}
|
|
190
|
-
const body =
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const errorCode = typeof payload.errorCode === 'number' ? payload.errorCode : 0;
|
|
221
|
+
const body = parseErrorEnvelope(await response.text());
|
|
222
|
+
const message = typeof body.message === 'string' ? body.message : response.statusText;
|
|
223
|
+
const errorCode = typeof body.errorCode === 'number' ? body.errorCode : 0;
|
|
194
224
|
return new ApiError(response.status, { status: 'error', message, errorCode });
|
|
195
225
|
}
|
|
196
226
|
}
|
|
197
227
|
|
|
228
|
+
// Internal: re-exported for the regression script under `scripts/`. Not part
|
|
229
|
+
// of the public API surface — direct callers should use the class methods.
|
|
230
|
+
export const __envelopeInternals = {
|
|
231
|
+
parseSuccessEnvelope,
|
|
232
|
+
parseErrorEnvelope,
|
|
233
|
+
isWorkflowTemplate
|
|
234
|
+
};
|
|
235
|
+
|
|
198
236
|
export default CreativeWorkflowTemplatesApi;
|
|
199
237
|
export * from './types';
|