@band-ai/sdk 0.1.2
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/CodexAdapter-A1k_LMdZ.d.ts +1278 -0
- package/dist/CodexAdapter-BbZD-nBd.d.cts +1278 -0
- package/dist/adapters.cjs +10643 -0
- package/dist/adapters.d.cts +217 -0
- package/dist/adapters.d.ts +217 -0
- package/dist/adapters.js +92 -0
- package/dist/backends-BnOLsG7w.d.cts +20 -0
- package/dist/backends-C4n6cKOf.d.ts +20 -0
- package/dist/chunk-3BKAC4OZ.js +44 -0
- package/dist/chunk-5CXIMAH2.js +52 -0
- package/dist/chunk-6AJA2OPC.js +3682 -0
- package/dist/chunk-A3TDK6GP.js +6674 -0
- package/dist/chunk-AVVDPXP4.js +39 -0
- package/dist/chunk-EDPKUUJL.js +177 -0
- package/dist/chunk-FUODYQRE.js +2562 -0
- package/dist/chunk-GVEQ3RAH.js +373 -0
- package/dist/chunk-INA6YZTZ.js +88 -0
- package/dist/chunk-IZPV6QS6.js +115 -0
- package/dist/chunk-LY55KYVI.js +0 -0
- package/dist/chunk-NIAQBANR.js +577 -0
- package/dist/chunk-OD2G5LFQ.js +78 -0
- package/dist/chunk-SFVKOEQH.js +103 -0
- package/dist/chunk-SG4WLD2H.js +1093 -0
- package/dist/chunk-YR3BOQNW.js +39 -0
- package/dist/chunk-ZZJRRBPQ.js +82 -0
- package/dist/claude-CcnQ5OUC.d.ts +53 -0
- package/dist/claude-CwTAxhwI.d.cts +53 -0
- package/dist/config.cjs +164 -0
- package/dist/config.d.cts +19 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +9 -0
- package/dist/converters.cjs +1086 -0
- package/dist/converters.d.cts +143 -0
- package/dist/converters.d.ts +143 -0
- package/dist/converters.js +468 -0
- package/dist/core.cjs +185 -0
- package/dist/core.d.cts +22 -0
- package/dist/core.d.ts +22 -0
- package/dist/core.js +24 -0
- package/dist/customTools-BzF0IISO.d.cts +10 -0
- package/dist/customTools-BzF0IISO.d.ts +10 -0
- package/dist/dtos-DUpbIu8k.d.cts +163 -0
- package/dist/dtos-DUpbIu8k.d.ts +163 -0
- package/dist/history-ByessXNq.d.ts +24 -0
- package/dist/history-i6yN7neC.d.cts +24 -0
- package/dist/index.cjs +13914 -0
- package/dist/index.d.cts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +198 -0
- package/dist/linear.cjs +2207 -0
- package/dist/linear.d.cts +167 -0
- package/dist/linear.d.ts +167 -0
- package/dist/linear.js +2139 -0
- package/dist/logger-CABQOnlR.d.cts +21 -0
- package/dist/logger-CABQOnlR.d.ts +21 -0
- package/dist/mcp-claude.cjs +584 -0
- package/dist/mcp-claude.d.cts +4 -0
- package/dist/mcp-claude.d.ts +4 -0
- package/dist/mcp-claude.js +11 -0
- package/dist/mcp.cjs +1247 -0
- package/dist/mcp.d.cts +97 -0
- package/dist/mcp.d.ts +97 -0
- package/dist/mcp.js +27 -0
- package/dist/opencode-BBcDchcN.d.cts +159 -0
- package/dist/opencode-DthQQUsZ.d.ts +159 -0
- package/dist/pagination-BPiys10t.d.cts +25 -0
- package/dist/pagination-CcDkVFxK.d.ts +25 -0
- package/dist/protocols-CInhtFpA.d.cts +116 -0
- package/dist/protocols-DrhzOH6K.d.ts +116 -0
- package/dist/rest.cjs +1159 -0
- package/dist/rest.d.cts +144 -0
- package/dist/rest.d.ts +144 -0
- package/dist/rest.js +18 -0
- package/dist/runtime.cjs +5353 -0
- package/dist/runtime.d.cts +276 -0
- package/dist/runtime.d.ts +276 -0
- package/dist/runtime.js +274 -0
- package/dist/schemas-BpEBkq5V.d.cts +592 -0
- package/dist/schemas-vos1AaBc.d.ts +592 -0
- package/dist/sdk-HJUVSSWA.js +10 -0
- package/dist/simpleAdapter-9OE_p6QW.d.ts +29 -0
- package/dist/simpleAdapter-DqhvjsGr.d.cts +29 -0
- package/dist/testing.cjs +217 -0
- package/dist/testing.d.cts +126 -0
- package/dist/testing.d.ts +126 -0
- package/dist/testing.js +186 -0
- package/dist/types-7jVzOeOP.d.ts +446 -0
- package/dist/types-CSHFipIc.d.cts +331 -0
- package/dist/types-CovcHpYf.d.cts +446 -0
- package/dist/types-CxII3XkA.d.ts +331 -0
- package/package.json +189 -0
package/dist/rest.cjs
ADDED
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/rest/index.ts
|
|
21
|
+
var rest_exports = {};
|
|
22
|
+
__export(rest_exports, {
|
|
23
|
+
DEFAULT_REQUEST_OPTIONS: () => DEFAULT_REQUEST_OPTIONS,
|
|
24
|
+
FernRestAdapter: () => FernRestAdapter,
|
|
25
|
+
RestFacade: () => RestFacade,
|
|
26
|
+
fetchPaginated: () => fetchPaginated,
|
|
27
|
+
normalizePaginationMetadata: () => normalizePaginationMetadata
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(rest_exports);
|
|
30
|
+
|
|
31
|
+
// src/core/errors.ts
|
|
32
|
+
var ThenvoiSdkError = class extends Error {
|
|
33
|
+
constructor(message, cause) {
|
|
34
|
+
super(message, cause !== void 0 ? { cause } : void 0);
|
|
35
|
+
this.name = "ThenvoiSdkError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var UnsupportedFeatureError = class extends ThenvoiSdkError {
|
|
39
|
+
constructor(message) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = "UnsupportedFeatureError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var ValidationError = class extends ThenvoiSdkError {
|
|
45
|
+
constructor(message, cause) {
|
|
46
|
+
super(message, cause);
|
|
47
|
+
this.name = "ValidationError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/client/rest/pagination.ts
|
|
52
|
+
var DEFAULT_PAGE_SIZE = 100;
|
|
53
|
+
var DEFAULT_MAX_PAGES = 100;
|
|
54
|
+
var VALID_PAGINATION_STRATEGIES = /* @__PURE__ */ new Set([
|
|
55
|
+
"auto",
|
|
56
|
+
"total_pages",
|
|
57
|
+
"until_empty"
|
|
58
|
+
]);
|
|
59
|
+
function normalizePaginationMetadata(metadata, options) {
|
|
60
|
+
if (!metadata) {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
const mode = options?.mode ?? "strict";
|
|
64
|
+
const snakeCaseMetadata = metadata;
|
|
65
|
+
const pageRaw = metadata.page ?? snakeCaseMetadata.page;
|
|
66
|
+
const pageSizeRaw = metadata.pageSize ?? snakeCaseMetadata.page_size;
|
|
67
|
+
const totalPagesRaw = metadata.totalPages ?? snakeCaseMetadata.total_pages;
|
|
68
|
+
const totalCountRaw = metadata.totalCount ?? snakeCaseMetadata.total_count;
|
|
69
|
+
const PAGINATION_KEYS = /* @__PURE__ */ new Set([
|
|
70
|
+
"page",
|
|
71
|
+
"pageSize",
|
|
72
|
+
"totalPages",
|
|
73
|
+
"totalCount",
|
|
74
|
+
"page_size",
|
|
75
|
+
"total_pages",
|
|
76
|
+
"total_count"
|
|
77
|
+
]);
|
|
78
|
+
const passthrough = {};
|
|
79
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
80
|
+
if (!PAGINATION_KEYS.has(key)) {
|
|
81
|
+
passthrough[key] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const page = toPositiveInteger(pageRaw);
|
|
85
|
+
const pageSize = toPositiveInteger(pageSizeRaw);
|
|
86
|
+
const totalPages = toNonNegativeInteger(totalPagesRaw);
|
|
87
|
+
const totalCount = toNonNegativeInteger(totalCountRaw);
|
|
88
|
+
if (mode === "strict") {
|
|
89
|
+
assertValidMetadataField("page", pageRaw, page);
|
|
90
|
+
assertValidMetadataField("pageSize", pageSizeRaw, pageSize);
|
|
91
|
+
assertValidMetadataField("totalPages", totalPagesRaw, totalPages);
|
|
92
|
+
assertValidMetadataField("totalCount", totalCountRaw, totalCount);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
...passthrough,
|
|
96
|
+
...page !== void 0 ? { page } : {},
|
|
97
|
+
...pageSize !== void 0 ? { pageSize } : {},
|
|
98
|
+
...totalPages !== void 0 ? { totalPages } : {},
|
|
99
|
+
...totalCount !== void 0 ? { totalCount } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function assertValidMetadataField(field, rawValue, normalizedValue) {
|
|
103
|
+
if (rawValue === void 0) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (normalizedValue === void 0) {
|
|
107
|
+
throw new ValidationError(
|
|
108
|
+
`Invalid pagination metadata '${field}': expected an integer with valid bounds`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function fetchPaginated(options) {
|
|
113
|
+
const pageSize = resolvePositiveInteger("pageSize", options.pageSize, DEFAULT_PAGE_SIZE);
|
|
114
|
+
const maxPages = resolvePositiveInteger("maxPages", options.maxPages, DEFAULT_MAX_PAGES);
|
|
115
|
+
const strategy = resolvePaginationStrategy(options.strategy);
|
|
116
|
+
const metadataValidation = options.metadataValidation ?? "strategy_aware";
|
|
117
|
+
const allItems = [];
|
|
118
|
+
let completed = false;
|
|
119
|
+
for (let page = 1; page <= maxPages; page += 1) {
|
|
120
|
+
const response = await options.fetchPage({ page, pageSize });
|
|
121
|
+
if (!Array.isArray(response.data)) {
|
|
122
|
+
throw new ValidationError("Paginated response.data must be an array");
|
|
123
|
+
}
|
|
124
|
+
const items = response.data;
|
|
125
|
+
allItems.push(...items);
|
|
126
|
+
const metadata = normalizePaginationMetadata(response.metadata, {
|
|
127
|
+
mode: resolveMetadataMode(strategy, metadataValidation)
|
|
128
|
+
});
|
|
129
|
+
const totalPages = metadata.totalPages;
|
|
130
|
+
if (strategy === "total_pages") {
|
|
131
|
+
if (typeof totalPages !== "number" || totalPages <= 0) {
|
|
132
|
+
throw new ValidationError(
|
|
133
|
+
"Pagination strategy 'total_pages' requires metadata.totalPages to be a positive number"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
if (page >= totalPages) {
|
|
137
|
+
completed = true;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (strategy === "until_empty" && items.length === 0) {
|
|
143
|
+
completed = true;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (strategy === "auto") {
|
|
147
|
+
if (typeof totalPages === "number" && totalPages > 0) {
|
|
148
|
+
if (page >= totalPages) {
|
|
149
|
+
completed = true;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (items.length === 0) {
|
|
155
|
+
completed = true;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!completed) {
|
|
161
|
+
throw new ValidationError(
|
|
162
|
+
`Pagination stopped after maxPages=${maxPages} before reaching a terminal condition`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return allItems;
|
|
166
|
+
}
|
|
167
|
+
function resolveMetadataMode(strategy, validation) {
|
|
168
|
+
if (validation === "strict") {
|
|
169
|
+
return "strict";
|
|
170
|
+
}
|
|
171
|
+
if (validation === "lossy") {
|
|
172
|
+
return "lossy";
|
|
173
|
+
}
|
|
174
|
+
return strategy === "until_empty" ? "lossy" : "strict";
|
|
175
|
+
}
|
|
176
|
+
function resolvePositiveInteger(name, value, fallback) {
|
|
177
|
+
if (value === void 0) {
|
|
178
|
+
return fallback;
|
|
179
|
+
}
|
|
180
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
181
|
+
throw new ValidationError(`${name} must be a positive integer`);
|
|
182
|
+
}
|
|
183
|
+
return value;
|
|
184
|
+
}
|
|
185
|
+
function resolvePaginationStrategy(value) {
|
|
186
|
+
if (value === void 0) {
|
|
187
|
+
return "auto";
|
|
188
|
+
}
|
|
189
|
+
if (VALID_PAGINATION_STRATEGIES.has(value)) {
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
throw new ValidationError(
|
|
193
|
+
`strategy must be one of: ${[...VALID_PAGINATION_STRATEGIES].join(", ")}`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
function toInteger(value) {
|
|
197
|
+
if (typeof value === "number" && Number.isInteger(value)) {
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
201
|
+
const parsed = Number(value);
|
|
202
|
+
if (Number.isInteger(parsed)) {
|
|
203
|
+
return parsed;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return void 0;
|
|
207
|
+
}
|
|
208
|
+
function toPositiveInteger(value) {
|
|
209
|
+
const normalized = toInteger(value);
|
|
210
|
+
if (normalized === void 0 || normalized <= 0) {
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
return normalized;
|
|
214
|
+
}
|
|
215
|
+
function toNonNegativeInteger(value) {
|
|
216
|
+
const normalized = toInteger(value);
|
|
217
|
+
if (normalized === void 0 || normalized < 0) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
return normalized;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/client/rest/requestOptions.ts
|
|
224
|
+
var DEFAULT_REQUEST_OPTIONS = {
|
|
225
|
+
maxRetries: 3
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/core/logger.ts
|
|
229
|
+
var noop = () => void 0;
|
|
230
|
+
var NoopLogger = class {
|
|
231
|
+
debug = noop;
|
|
232
|
+
info = noop;
|
|
233
|
+
warn = noop;
|
|
234
|
+
error = noop;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/adapters/shared/coercion.ts
|
|
238
|
+
function asOptionalRecord(value) {
|
|
239
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
240
|
+
return void 0;
|
|
241
|
+
}
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
function asString(value) {
|
|
245
|
+
return typeof value === "string" ? value : void 0;
|
|
246
|
+
}
|
|
247
|
+
function asNullableString(value) {
|
|
248
|
+
if (value === void 0) {
|
|
249
|
+
return void 0;
|
|
250
|
+
}
|
|
251
|
+
if (value === null) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
return asString(value);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/client/rest/responseNormalization.ts
|
|
258
|
+
function asMetadataMap(value) {
|
|
259
|
+
return asOptionalRecord(value);
|
|
260
|
+
}
|
|
261
|
+
function normalizeContactRequestDirection(value) {
|
|
262
|
+
const direction = asMetadataMap(value);
|
|
263
|
+
if (!direction) {
|
|
264
|
+
return void 0;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
total: typeof direction.total === "number" ? direction.total : typeof direction.total_count === "number" ? direction.total_count : void 0,
|
|
268
|
+
totalPages: typeof direction.totalPages === "number" ? direction.totalPages : typeof direction.total_pages === "number" ? direction.total_pages : void 0
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function normalizeContactRequestsResult(result) {
|
|
272
|
+
const metadata = asMetadataMap(result.metadata);
|
|
273
|
+
return {
|
|
274
|
+
received: Array.isArray(result.received) ? result.received : [],
|
|
275
|
+
sent: Array.isArray(result.sent) ? result.sent : [],
|
|
276
|
+
metadata: metadata ? {
|
|
277
|
+
page: typeof metadata.page === "number" ? metadata.page : typeof metadata.page_number === "number" ? metadata.page_number : void 0,
|
|
278
|
+
pageSize: typeof metadata.pageSize === "number" ? metadata.pageSize : typeof metadata.page_size === "number" ? metadata.page_size : void 0,
|
|
279
|
+
received: normalizeContactRequestDirection(metadata.received),
|
|
280
|
+
sent: normalizeContactRequestDirection(metadata.sent)
|
|
281
|
+
} : void 0
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/client/rest/FernRestAdapter.ts
|
|
286
|
+
function mergeOptions(options) {
|
|
287
|
+
return {
|
|
288
|
+
...DEFAULT_REQUEST_OPTIONS,
|
|
289
|
+
...options
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
var AGENT_ME_RETRY_LIMIT = 4;
|
|
293
|
+
var AGENT_ME_RETRY_BASE_DELAY_MS = 2e3;
|
|
294
|
+
var MESSAGE_SEND_RETRY_LIMIT = 3;
|
|
295
|
+
var MESSAGE_SEND_RETRY_BASE_DELAY_MS = 500;
|
|
296
|
+
function asMetadataMap2(value) {
|
|
297
|
+
return asOptionalRecord(value);
|
|
298
|
+
}
|
|
299
|
+
function extractHttpStatus(error) {
|
|
300
|
+
const record = asOptionalRecord(error);
|
|
301
|
+
if (!record) {
|
|
302
|
+
return void 0;
|
|
303
|
+
}
|
|
304
|
+
const response = asOptionalRecord(record.response);
|
|
305
|
+
const status = record.statusCode ?? record.status ?? response?.statusCode ?? response?.status;
|
|
306
|
+
return typeof status === "number" ? status : void 0;
|
|
307
|
+
}
|
|
308
|
+
function isFernRateLimitError(error) {
|
|
309
|
+
return extractHttpStatus(error) === 429;
|
|
310
|
+
}
|
|
311
|
+
async function sleep(ms) {
|
|
312
|
+
await new Promise((resolveDelay) => setTimeout(resolveDelay, ms));
|
|
313
|
+
}
|
|
314
|
+
function computeRetryDelayMs(baseDelayMs, attempt) {
|
|
315
|
+
const backoff = baseDelayMs * 2 ** (attempt - 1);
|
|
316
|
+
const jitter = Math.floor(Math.random() * Math.max(1, Math.floor(backoff / 4)));
|
|
317
|
+
return backoff + jitter;
|
|
318
|
+
}
|
|
319
|
+
async function withRateLimitRetry(operation, options) {
|
|
320
|
+
let lastError;
|
|
321
|
+
for (let attempt = 1; attempt <= options.retryLimit; attempt += 1) {
|
|
322
|
+
try {
|
|
323
|
+
return await operation();
|
|
324
|
+
} catch (error) {
|
|
325
|
+
lastError = error;
|
|
326
|
+
if (!isFernRateLimitError(error) || attempt === options.retryLimit) {
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
await sleep(computeRetryDelayMs(options.baseDelayMs, attempt));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
throw lastError instanceof Error ? lastError : new Error("Rate-limit retry exhausted without a terminal error.");
|
|
333
|
+
}
|
|
334
|
+
function requireNonEmptyStringField(value, field, source) {
|
|
335
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
336
|
+
throw new Error(`Invalid ${source} response: expected non-empty string AgentIdentity.${field}`);
|
|
337
|
+
}
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
function normalizeOptionalStringField(value, field, source) {
|
|
341
|
+
if (value === void 0 || value === null) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
if (typeof value !== "string") {
|
|
345
|
+
throw new Error(`Invalid ${source} response: expected string or null AgentIdentity.${field}`);
|
|
346
|
+
}
|
|
347
|
+
return value;
|
|
348
|
+
}
|
|
349
|
+
function normalizeAgentIdentityRecord(record, source) {
|
|
350
|
+
return {
|
|
351
|
+
id: requireNonEmptyStringField(record.id, "id", source),
|
|
352
|
+
name: requireNonEmptyStringField(record.name, "name", source),
|
|
353
|
+
description: normalizeOptionalStringField(record.description, "description", source),
|
|
354
|
+
handle: normalizeOptionalStringField(record.handle, "handle", source),
|
|
355
|
+
ownerUuid: normalizeOptionalStringField(record.owner_uuid, "ownerUuid", source)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function normalizeAgentIdentityEnvelope(value, source) {
|
|
359
|
+
const payload = asMetadataMap2(extractEnvelopeData(value));
|
|
360
|
+
if (!payload) {
|
|
361
|
+
throw new Error(`Invalid ${source} response: expected object payload for AgentIdentity`);
|
|
362
|
+
}
|
|
363
|
+
return normalizeAgentIdentityRecord(payload, source);
|
|
364
|
+
}
|
|
365
|
+
function normalizeLegacyProfileIdentity(profile, source) {
|
|
366
|
+
const id = requireNonEmptyStringField(profile.id, "id", source);
|
|
367
|
+
const derivedName = profile.name ?? ([profile.first_name, profile.last_name].filter(Boolean).join(" ").trim() || void 0) ?? profile.username ?? profile.id;
|
|
368
|
+
const name = requireNonEmptyStringField(derivedName, "name", source);
|
|
369
|
+
return {
|
|
370
|
+
id,
|
|
371
|
+
name,
|
|
372
|
+
description: profile.description ?? null,
|
|
373
|
+
handle: null,
|
|
374
|
+
ownerUuid: null
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function normalizeLegacyProfileEnvelope(value) {
|
|
378
|
+
const payload = asMetadataMap2(extractEnvelopeData(value));
|
|
379
|
+
if (!payload) {
|
|
380
|
+
throw new Error("Invalid profile.getMyProfile response: expected object payload");
|
|
381
|
+
}
|
|
382
|
+
return payload;
|
|
383
|
+
}
|
|
384
|
+
function asRecordArray(value) {
|
|
385
|
+
if (!Array.isArray(value)) {
|
|
386
|
+
return void 0;
|
|
387
|
+
}
|
|
388
|
+
return value.filter((entry) => asOptionalRecord(entry) !== void 0);
|
|
389
|
+
}
|
|
390
|
+
function extractEnvelopeData(value) {
|
|
391
|
+
const record = asMetadataMap2(value);
|
|
392
|
+
if (!record || record.data === void 0) {
|
|
393
|
+
return value;
|
|
394
|
+
}
|
|
395
|
+
return record.data;
|
|
396
|
+
}
|
|
397
|
+
function extractEnvelopeMetadata(value) {
|
|
398
|
+
const record = asMetadataMap2(value);
|
|
399
|
+
if (!record) {
|
|
400
|
+
return void 0;
|
|
401
|
+
}
|
|
402
|
+
return asMetadataMap2(record.metadata) ?? asMetadataMap2(record.meta);
|
|
403
|
+
}
|
|
404
|
+
function normalizeFernPaginatedResponse(response, normalizeItem) {
|
|
405
|
+
const topLevelData = extractEnvelopeData(response);
|
|
406
|
+
const nestedData = extractEnvelopeData(topLevelData);
|
|
407
|
+
const rawItems = asRecordArray(topLevelData) ?? asRecordArray(nestedData) ?? [];
|
|
408
|
+
return {
|
|
409
|
+
data: rawItems.map((item) => normalizeItem(item)).filter((item) => item !== null),
|
|
410
|
+
metadata: normalizePaginationMetadata(
|
|
411
|
+
extractEnvelopeMetadata(response) ?? extractEnvelopeMetadata(topLevelData)
|
|
412
|
+
)
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function normalizeFernContactRequestsResponse(response) {
|
|
416
|
+
const payload = asMetadataMap2(extractEnvelopeData(response));
|
|
417
|
+
return normalizeContactRequestsResult({
|
|
418
|
+
received: asRecordArray(payload?.received) ?? [],
|
|
419
|
+
sent: asRecordArray(payload?.sent) ?? [],
|
|
420
|
+
metadata: extractEnvelopeMetadata(response) ?? extractEnvelopeMetadata(payload)
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
function normalizeToolOperationResult(response) {
|
|
424
|
+
return asMetadataMap2(extractEnvelopeData(response)) ?? {};
|
|
425
|
+
}
|
|
426
|
+
function normalizeMemoryRecord(response) {
|
|
427
|
+
const payload = asMetadataMap2(extractEnvelopeData(response));
|
|
428
|
+
return payload ? normalizeMemoryRecordItem(payload) ?? {} : {};
|
|
429
|
+
}
|
|
430
|
+
function extractChatId(response) {
|
|
431
|
+
const payload = asMetadataMap2(extractEnvelopeData(response));
|
|
432
|
+
return typeof payload?.id === "string" ? payload.id : void 0;
|
|
433
|
+
}
|
|
434
|
+
function isChatParticipant(value) {
|
|
435
|
+
const record = asMetadataMap2(value);
|
|
436
|
+
if (!record) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
return typeof record.id === "string" && typeof record.name === "string" && typeof record.type === "string" && (record.handle === void 0 || record.handle === null || typeof record.handle === "string");
|
|
440
|
+
}
|
|
441
|
+
function normalizeChatParticipantsResponse(response) {
|
|
442
|
+
const payload = extractEnvelopeData(response);
|
|
443
|
+
return Array.isArray(payload) ? payload.filter(isChatParticipant) : [];
|
|
444
|
+
}
|
|
445
|
+
function normalizeMetadataRecord(value) {
|
|
446
|
+
return value;
|
|
447
|
+
}
|
|
448
|
+
function hasInvalidString(value) {
|
|
449
|
+
return value !== void 0 && typeof value !== "string";
|
|
450
|
+
}
|
|
451
|
+
function hasInvalidNullableString(value) {
|
|
452
|
+
return value !== void 0 && value !== null && typeof value !== "string";
|
|
453
|
+
}
|
|
454
|
+
function hasInvalidNullableBoolean(value) {
|
|
455
|
+
return value !== void 0 && value !== null && typeof value !== "boolean";
|
|
456
|
+
}
|
|
457
|
+
function normalizePeerRecord(value) {
|
|
458
|
+
if (hasInvalidString(value.id) || hasInvalidString(value.name) || hasInvalidString(value.type) || hasInvalidNullableString(value.handle) || hasInvalidNullableString(value.description)) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
...typeof value.id === "string" ? { id: value.id } : {},
|
|
463
|
+
...typeof value.name === "string" ? { name: value.name } : {},
|
|
464
|
+
...typeof value.type === "string" ? { type: value.type } : {},
|
|
465
|
+
...value.handle !== void 0 ? { handle: value.handle } : {},
|
|
466
|
+
...value.description !== void 0 ? { description: value.description } : {}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function normalizeContactRecord(value) {
|
|
470
|
+
if (hasInvalidString(value.id) || hasInvalidString(value.handle) || hasInvalidNullableString(value.name) || hasInvalidString(value.type) || hasInvalidNullableString(value.description) || hasInvalidNullableBoolean(value.is_external) || hasInvalidString(value.inserted_at)) {
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
...typeof value.id === "string" ? { id: value.id } : {},
|
|
475
|
+
...typeof value.handle === "string" ? { handle: value.handle } : {},
|
|
476
|
+
...value.name !== void 0 ? { name: value.name } : {},
|
|
477
|
+
...typeof value.type === "string" ? { type: value.type } : {},
|
|
478
|
+
...value.description !== void 0 ? { description: value.description } : {},
|
|
479
|
+
...value.is_external !== void 0 ? { is_external: value.is_external } : {},
|
|
480
|
+
...typeof value.inserted_at === "string" ? { inserted_at: value.inserted_at } : {}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function normalizeMemoryRecordItem(value) {
|
|
484
|
+
if (hasInvalidString(value.id) || hasInvalidString(value.content) || hasInvalidString(value.system) || hasInvalidString(value.type) || hasInvalidString(value.segment) || hasInvalidNullableString(value.thought) || hasInvalidNullableString(value.subject_id) || hasInvalidNullableString(value.source_agent_id) || hasInvalidNullableString(value.organization_id) || hasInvalidString(value.scope) || hasInvalidString(value.status) || value.metadata !== void 0 && value.metadata !== null && asMetadataMap2(value.metadata) === void 0 || hasInvalidNullableString(value.inserted_at)) {
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
...typeof value.id === "string" ? { id: value.id } : {},
|
|
489
|
+
...typeof value.content === "string" ? { content: value.content } : {},
|
|
490
|
+
...typeof value.system === "string" ? { system: value.system } : {},
|
|
491
|
+
...typeof value.type === "string" ? { type: value.type } : {},
|
|
492
|
+
...typeof value.segment === "string" ? { segment: value.segment } : {},
|
|
493
|
+
...value.thought !== void 0 ? { thought: value.thought } : {},
|
|
494
|
+
...value.subject_id !== void 0 ? { subject_id: value.subject_id } : {},
|
|
495
|
+
...value.source_agent_id !== void 0 ? { source_agent_id: value.source_agent_id } : {},
|
|
496
|
+
...value.organization_id !== void 0 ? { organization_id: value.organization_id } : {},
|
|
497
|
+
...typeof value.scope === "string" ? { scope: value.scope } : {},
|
|
498
|
+
...typeof value.status === "string" ? { status: value.status } : {},
|
|
499
|
+
...value.metadata !== void 0 ? { metadata: value.metadata === null ? null : asMetadataMap2(value.metadata) ?? null } : {},
|
|
500
|
+
...value.inserted_at !== void 0 ? { inserted_at: value.inserted_at } : {}
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function normalizePlatformMessageRecord(value) {
|
|
504
|
+
return normalizePlatformChatMessage(value);
|
|
505
|
+
}
|
|
506
|
+
function normalizePlatformChatMessage(value) {
|
|
507
|
+
const payload = asMetadataMap2(value);
|
|
508
|
+
if (!payload) {
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
const id = asString(payload.id);
|
|
512
|
+
const content = asString(payload.content);
|
|
513
|
+
const senderId = asString(payload.sender_id) ?? asString(payload.senderId);
|
|
514
|
+
const senderType = asString(payload.sender_type) ?? asString(payload.senderType);
|
|
515
|
+
const messageType = asString(payload.message_type) ?? asString(payload.messageType);
|
|
516
|
+
const insertedAt = asString(payload.inserted_at) ?? asString(payload.insertedAt);
|
|
517
|
+
if (!id || !content || !senderId || !senderType || !messageType || !insertedAt) {
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
520
|
+
const senderName = asNullableString(payload.sender_name ?? payload.senderName);
|
|
521
|
+
const updatedAt = asNullableString(payload.updated_at ?? payload.updatedAt);
|
|
522
|
+
const metadata = payload.metadata === null ? null : asMetadataMap2(payload.metadata);
|
|
523
|
+
return {
|
|
524
|
+
id,
|
|
525
|
+
content,
|
|
526
|
+
sender_id: senderId,
|
|
527
|
+
sender_type: senderType,
|
|
528
|
+
sender_name: senderName,
|
|
529
|
+
message_type: messageType,
|
|
530
|
+
metadata: payload.metadata === null ? null : metadata,
|
|
531
|
+
inserted_at: insertedAt,
|
|
532
|
+
updated_at: updatedAt
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
var FernRestAdapter = class {
|
|
536
|
+
client;
|
|
537
|
+
constructor(client) {
|
|
538
|
+
this.client = client;
|
|
539
|
+
}
|
|
540
|
+
async getAgentMe(options) {
|
|
541
|
+
return withRateLimitRetry(
|
|
542
|
+
async () => {
|
|
543
|
+
if (this.client.agentApiIdentity?.getAgentMe) {
|
|
544
|
+
const response = await this.client.agentApiIdentity.getAgentMe(mergeOptions(options));
|
|
545
|
+
return normalizeAgentIdentityEnvelope(response, "agentApiIdentity.getAgentMe");
|
|
546
|
+
}
|
|
547
|
+
const profileClient = this.client.myProfile ?? this.client.humanApiProfile;
|
|
548
|
+
if (!profileClient?.getMyProfile) {
|
|
549
|
+
throw new UnsupportedFeatureError(
|
|
550
|
+
"Fern client missing agentApiIdentity.getAgentMe or humanApiProfile.getMyProfile"
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
const profile = await profileClient.getMyProfile(mergeOptions(options));
|
|
554
|
+
return normalizeLegacyProfileIdentity(
|
|
555
|
+
normalizeLegacyProfileEnvelope(profile),
|
|
556
|
+
"profile.getMyProfile"
|
|
557
|
+
);
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
retryLimit: AGENT_ME_RETRY_LIMIT,
|
|
561
|
+
baseDelayMs: AGENT_ME_RETRY_BASE_DELAY_MS
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
async createChatMessage(chatId, message, options) {
|
|
566
|
+
const api = this.client.chatMessages?.createChatMessage?.bind(this.client.chatMessages) ?? this.client.agentApiMessages?.createAgentChatMessage?.bind(this.client.agentApiMessages) ?? this.client.myChatMessages?.createMyChatMessage?.bind(this.client.myChatMessages);
|
|
567
|
+
if (!api) {
|
|
568
|
+
throw new UnsupportedFeatureError("Fern client missing chat message creation endpoint");
|
|
569
|
+
}
|
|
570
|
+
const response = await withRateLimitRetry(
|
|
571
|
+
async () => await api(
|
|
572
|
+
chatId,
|
|
573
|
+
{
|
|
574
|
+
message: {
|
|
575
|
+
content: message.content,
|
|
576
|
+
message_type: message.messageType,
|
|
577
|
+
metadata: message.metadata,
|
|
578
|
+
mentions: message.mentions
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
mergeOptions(options)
|
|
582
|
+
),
|
|
583
|
+
{
|
|
584
|
+
retryLimit: MESSAGE_SEND_RETRY_LIMIT,
|
|
585
|
+
baseDelayMs: MESSAGE_SEND_RETRY_BASE_DELAY_MS
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
return normalizeToolOperationResult(response);
|
|
589
|
+
}
|
|
590
|
+
async createChatEvent(chatId, event, options) {
|
|
591
|
+
const createAgentChatEvent = this.client.agentApiEvents?.createAgentChatEvent?.bind(this.client.agentApiEvents);
|
|
592
|
+
if (createAgentChatEvent) {
|
|
593
|
+
const response = await withRateLimitRetry(
|
|
594
|
+
async () => await createAgentChatEvent(
|
|
595
|
+
chatId,
|
|
596
|
+
{
|
|
597
|
+
event: {
|
|
598
|
+
content: event.content,
|
|
599
|
+
message_type: event.messageType,
|
|
600
|
+
metadata: event.metadata
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
mergeOptions(options)
|
|
604
|
+
),
|
|
605
|
+
{
|
|
606
|
+
retryLimit: MESSAGE_SEND_RETRY_LIMIT,
|
|
607
|
+
baseDelayMs: MESSAGE_SEND_RETRY_BASE_DELAY_MS
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
return normalizeToolOperationResult(response);
|
|
611
|
+
}
|
|
612
|
+
return this.createChatMessage(chatId, event, options);
|
|
613
|
+
}
|
|
614
|
+
async createChat(taskId, options) {
|
|
615
|
+
const api = this.client.chatRooms?.createChat?.bind(this.client.chatRooms) ?? this.client.agentApiChats?.createAgentChat?.bind(this.client.agentApiChats);
|
|
616
|
+
if (!api) {
|
|
617
|
+
throw new UnsupportedFeatureError("Fern client missing chat creation endpoint");
|
|
618
|
+
}
|
|
619
|
+
const response = await api(
|
|
620
|
+
{
|
|
621
|
+
chat: {
|
|
622
|
+
task_id: taskId
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
mergeOptions(options)
|
|
626
|
+
);
|
|
627
|
+
const roomId = extractChatId(response);
|
|
628
|
+
if (!roomId) {
|
|
629
|
+
throw new UnsupportedFeatureError("Chat create response did not include id");
|
|
630
|
+
}
|
|
631
|
+
return { id: roomId };
|
|
632
|
+
}
|
|
633
|
+
async listChatParticipants(chatId, options) {
|
|
634
|
+
const requestOptions = mergeOptions(options);
|
|
635
|
+
const listChatParticipantsApi = this.client.chatParticipants?.listChatParticipants?.bind(this.client.chatParticipants);
|
|
636
|
+
if (listChatParticipantsApi) {
|
|
637
|
+
return normalizeChatParticipantsResponse(
|
|
638
|
+
await listChatParticipantsApi(chatId, {}, requestOptions)
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
const listAgentChatParticipantsApi = this.client.agentApiParticipants?.listAgentChatParticipants?.bind(this.client.agentApiParticipants);
|
|
642
|
+
if (!listAgentChatParticipantsApi) {
|
|
643
|
+
throw new UnsupportedFeatureError("Fern client missing chat participant list endpoint");
|
|
644
|
+
}
|
|
645
|
+
return normalizeChatParticipantsResponse(
|
|
646
|
+
await listAgentChatParticipantsApi(chatId, requestOptions)
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
async addChatParticipant(chatId, participant, options) {
|
|
650
|
+
const api = this.client.chatParticipants?.addChatParticipant?.bind(this.client.chatParticipants) ?? this.client.agentApiParticipants?.addAgentChatParticipant?.bind(this.client.agentApiParticipants);
|
|
651
|
+
if (!api) {
|
|
652
|
+
throw new UnsupportedFeatureError("Fern client missing chat participant add endpoint");
|
|
653
|
+
}
|
|
654
|
+
const response = await api(
|
|
655
|
+
chatId,
|
|
656
|
+
{
|
|
657
|
+
participant: {
|
|
658
|
+
participant_id: participant.participantId,
|
|
659
|
+
role: participant.role
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
mergeOptions(options)
|
|
663
|
+
);
|
|
664
|
+
return normalizeToolOperationResult(response);
|
|
665
|
+
}
|
|
666
|
+
async removeChatParticipant(chatId, participantId, options) {
|
|
667
|
+
const api = this.client.chatParticipants?.removeChatParticipant?.bind(this.client.chatParticipants) ?? this.client.agentApiParticipants?.removeAgentChatParticipant?.bind(this.client.agentApiParticipants);
|
|
668
|
+
if (!api) {
|
|
669
|
+
throw new UnsupportedFeatureError("Fern client missing chat participant remove endpoint");
|
|
670
|
+
}
|
|
671
|
+
const response = await api(chatId, participantId, mergeOptions(options));
|
|
672
|
+
return normalizeToolOperationResult(response);
|
|
673
|
+
}
|
|
674
|
+
async markMessageProcessing(chatId, messageId, options) {
|
|
675
|
+
const api = this.client.chatMessages?.markMessageProcessing?.bind(this.client.chatMessages) ?? this.client.agentApiMessages?.markAgentMessageProcessing?.bind(this.client.agentApiMessages);
|
|
676
|
+
if (!api) {
|
|
677
|
+
throw new UnsupportedFeatureError("Fern client missing mark message processing endpoint");
|
|
678
|
+
}
|
|
679
|
+
const response = await api(chatId, messageId, mergeOptions(options));
|
|
680
|
+
return normalizeToolOperationResult(response);
|
|
681
|
+
}
|
|
682
|
+
async markMessageProcessed(chatId, messageId, options) {
|
|
683
|
+
const api = this.client.chatMessages?.markMessageProcessed?.bind(this.client.chatMessages) ?? this.client.agentApiMessages?.markAgentMessageProcessed?.bind(this.client.agentApiMessages);
|
|
684
|
+
if (!api) {
|
|
685
|
+
throw new UnsupportedFeatureError("Fern client missing mark message processed endpoint");
|
|
686
|
+
}
|
|
687
|
+
const response = await api(chatId, messageId, mergeOptions(options));
|
|
688
|
+
return normalizeToolOperationResult(response);
|
|
689
|
+
}
|
|
690
|
+
async markMessageFailed(chatId, messageId, error, options) {
|
|
691
|
+
const api = this.client.chatMessages?.markMessageFailed?.bind(this.client.chatMessages) ?? this.client.agentApiMessages?.markAgentMessageFailed?.bind(this.client.agentApiMessages);
|
|
692
|
+
if (!api) {
|
|
693
|
+
throw new UnsupportedFeatureError("Fern client missing mark message failed endpoint");
|
|
694
|
+
}
|
|
695
|
+
const response = await api(
|
|
696
|
+
chatId,
|
|
697
|
+
messageId,
|
|
698
|
+
{ error },
|
|
699
|
+
mergeOptions(options)
|
|
700
|
+
);
|
|
701
|
+
return normalizeToolOperationResult(response);
|
|
702
|
+
}
|
|
703
|
+
async getNextMessage(request, options) {
|
|
704
|
+
const api = this.client.chatMessages?.getNextMessage?.bind(this.client.chatMessages) ?? this.client.agentApiMessages?.getAgentNextMessage?.bind(this.client.agentApiMessages);
|
|
705
|
+
if (!api) {
|
|
706
|
+
throw new UnsupportedFeatureError("Fern client missing next-message endpoint");
|
|
707
|
+
}
|
|
708
|
+
const response = await api(request.chatId, mergeOptions(options));
|
|
709
|
+
return normalizePlatformChatMessage(extractEnvelopeData(response));
|
|
710
|
+
}
|
|
711
|
+
async listPeers(request, options) {
|
|
712
|
+
const api = this.client.agentPeers?.listAgentPeers?.bind(this.client.agentPeers) ?? this.client.agentApiPeers?.listAgentPeers?.bind(this.client.agentApiPeers);
|
|
713
|
+
if (!api) {
|
|
714
|
+
throw new UnsupportedFeatureError("Fern client missing peer list endpoint");
|
|
715
|
+
}
|
|
716
|
+
const response = await api(
|
|
717
|
+
{
|
|
718
|
+
page: request.page,
|
|
719
|
+
page_size: request.pageSize,
|
|
720
|
+
...request.notInChat ? { not_in_chat: request.notInChat } : {}
|
|
721
|
+
},
|
|
722
|
+
mergeOptions(options)
|
|
723
|
+
);
|
|
724
|
+
return normalizeFernPaginatedResponse(response, normalizePeerRecord);
|
|
725
|
+
}
|
|
726
|
+
async listChats(request, options) {
|
|
727
|
+
const api = this.client.chatRooms?.listChats?.bind(this.client.chatRooms) ?? this.client.agentApiChats?.listAgentChats?.bind(this.client.agentApiChats);
|
|
728
|
+
if (!api) {
|
|
729
|
+
throw new UnsupportedFeatureError("Fern client missing chat list endpoint");
|
|
730
|
+
}
|
|
731
|
+
const response = await api(
|
|
732
|
+
{
|
|
733
|
+
page: request.page,
|
|
734
|
+
page_size: request.pageSize
|
|
735
|
+
},
|
|
736
|
+
mergeOptions(options)
|
|
737
|
+
);
|
|
738
|
+
return normalizeFernPaginatedResponse(response, normalizeMetadataRecord);
|
|
739
|
+
}
|
|
740
|
+
async listContacts(request, options) {
|
|
741
|
+
const api = this.client.agentContacts?.listAgentContacts?.bind(this.client.agentContacts) ?? this.client.agentApiContacts?.listAgentContacts?.bind(this.client.agentApiContacts);
|
|
742
|
+
if (!api) {
|
|
743
|
+
throw new UnsupportedFeatureError("Fern client missing contact list endpoint");
|
|
744
|
+
}
|
|
745
|
+
const page = request.page ?? 1;
|
|
746
|
+
const pageSize = request.pageSize ?? 50;
|
|
747
|
+
const response = await api(
|
|
748
|
+
{
|
|
749
|
+
page,
|
|
750
|
+
page_size: pageSize
|
|
751
|
+
},
|
|
752
|
+
mergeOptions(options)
|
|
753
|
+
);
|
|
754
|
+
return normalizeFernPaginatedResponse(response, normalizeContactRecord);
|
|
755
|
+
}
|
|
756
|
+
async addContact(request, options) {
|
|
757
|
+
const api = this.client.agentContacts?.addAgentContact?.bind(this.client.agentContacts) ?? this.client.agentApiContacts?.addAgentContact?.bind(this.client.agentApiContacts);
|
|
758
|
+
if (!api) {
|
|
759
|
+
throw new UnsupportedFeatureError("Fern client missing add contact endpoint");
|
|
760
|
+
}
|
|
761
|
+
return normalizeToolOperationResult(
|
|
762
|
+
await api(
|
|
763
|
+
{ handle: request.handle, ...request.message ? { message: request.message } : {} },
|
|
764
|
+
mergeOptions(options)
|
|
765
|
+
)
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
async removeContact(request, options) {
|
|
769
|
+
const api = this.client.agentContacts?.removeAgentContact?.bind(this.client.agentContacts) ?? this.client.agentApiContacts?.removeAgentContact?.bind(this.client.agentApiContacts);
|
|
770
|
+
if (!api) {
|
|
771
|
+
throw new UnsupportedFeatureError("Fern client missing remove contact endpoint");
|
|
772
|
+
}
|
|
773
|
+
return normalizeToolOperationResult(
|
|
774
|
+
await api(
|
|
775
|
+
request.target === "handle" ? { handle: request.handle } : { contact_id: request.contactId },
|
|
776
|
+
mergeOptions(options)
|
|
777
|
+
)
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
async listContactRequests(request, options) {
|
|
781
|
+
const api = this.client.agentContacts?.listAgentContactRequests?.bind(this.client.agentContacts) ?? this.client.agentApiContacts?.listAgentContactRequests?.bind(this.client.agentApiContacts);
|
|
782
|
+
if (!api) {
|
|
783
|
+
throw new UnsupportedFeatureError("Fern client missing contact request list endpoint");
|
|
784
|
+
}
|
|
785
|
+
const page = request.page ?? 1;
|
|
786
|
+
const pageSize = request.pageSize ?? 50;
|
|
787
|
+
const sentStatus = request.sentStatus ?? "pending";
|
|
788
|
+
const response = await api(
|
|
789
|
+
{
|
|
790
|
+
page,
|
|
791
|
+
page_size: pageSize,
|
|
792
|
+
sent_status: sentStatus
|
|
793
|
+
},
|
|
794
|
+
mergeOptions(options)
|
|
795
|
+
);
|
|
796
|
+
return normalizeFernContactRequestsResponse(response);
|
|
797
|
+
}
|
|
798
|
+
async respondContactRequest(request, options) {
|
|
799
|
+
const api = this.client.agentContacts?.respondToAgentContactRequest?.bind(this.client.agentContacts) ?? this.client.agentApiContacts?.respondToAgentContactRequest?.bind(this.client.agentApiContacts);
|
|
800
|
+
if (!api) {
|
|
801
|
+
throw new UnsupportedFeatureError("Fern client missing contact request response endpoint");
|
|
802
|
+
}
|
|
803
|
+
return normalizeToolOperationResult(
|
|
804
|
+
await api(
|
|
805
|
+
request.target === "handle" ? { action: request.action, handle: request.handle } : { action: request.action, request_id: request.requestId },
|
|
806
|
+
mergeOptions(options)
|
|
807
|
+
)
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
async listMemories(request, options) {
|
|
811
|
+
const api = this.client.agentMemories?.listAgentMemories?.bind(this.client.agentMemories) ?? this.client.agentApiMemories?.listAgentMemories?.bind(this.client.agentApiMemories);
|
|
812
|
+
if (!api) {
|
|
813
|
+
throw new UnsupportedFeatureError("Fern client missing memory list endpoint");
|
|
814
|
+
}
|
|
815
|
+
const response = await api(request, mergeOptions(options));
|
|
816
|
+
return normalizeFernPaginatedResponse(response, normalizeMemoryRecordItem);
|
|
817
|
+
}
|
|
818
|
+
async storeMemory(request, options) {
|
|
819
|
+
const api = this.client.agentMemories?.createAgentMemory?.bind(this.client.agentMemories) ?? this.client.agentApiMemories?.createAgentMemory?.bind(this.client.agentApiMemories);
|
|
820
|
+
if (!api) {
|
|
821
|
+
throw new UnsupportedFeatureError("Fern client missing create memory endpoint");
|
|
822
|
+
}
|
|
823
|
+
return normalizeMemoryRecord(
|
|
824
|
+
await api(
|
|
825
|
+
{ memory: request },
|
|
826
|
+
mergeOptions(options)
|
|
827
|
+
)
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
async getMemory(memoryId, options) {
|
|
831
|
+
const api = this.client.agentMemories?.getAgentMemory?.bind(this.client.agentMemories) ?? this.client.agentApiMemories?.getAgentMemory?.bind(this.client.agentApiMemories);
|
|
832
|
+
if (!api) {
|
|
833
|
+
throw new UnsupportedFeatureError("Fern client missing get memory endpoint");
|
|
834
|
+
}
|
|
835
|
+
return normalizeMemoryRecord(
|
|
836
|
+
await api(memoryId, mergeOptions(options))
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
async supersedeMemory(memoryId, options) {
|
|
840
|
+
const api = this.client.agentMemories?.supersedeAgentMemory?.bind(this.client.agentMemories) ?? this.client.agentApiMemories?.supersedeAgentMemory?.bind(this.client.agentApiMemories);
|
|
841
|
+
if (!api) {
|
|
842
|
+
throw new UnsupportedFeatureError("Fern client missing supersede memory endpoint");
|
|
843
|
+
}
|
|
844
|
+
return normalizeToolOperationResult(
|
|
845
|
+
await api(memoryId, mergeOptions(options))
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
async archiveMemory(memoryId, options) {
|
|
849
|
+
const api = this.client.agentMemories?.archiveAgentMemory?.bind(this.client.agentMemories) ?? this.client.agentApiMemories?.archiveAgentMemory?.bind(this.client.agentApiMemories);
|
|
850
|
+
if (!api) {
|
|
851
|
+
throw new UnsupportedFeatureError("Fern client missing archive memory endpoint");
|
|
852
|
+
}
|
|
853
|
+
return normalizeToolOperationResult(
|
|
854
|
+
await api(memoryId, mergeOptions(options))
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
async listMessages(request, options) {
|
|
858
|
+
const requestOptions = mergeOptions(options);
|
|
859
|
+
const listRequest = {
|
|
860
|
+
page: request.page,
|
|
861
|
+
page_size: request.pageSize,
|
|
862
|
+
status: request.status
|
|
863
|
+
};
|
|
864
|
+
const listMessagesApi = this.client.chatMessages?.listMessages?.bind(this.client.chatMessages);
|
|
865
|
+
if (listMessagesApi) {
|
|
866
|
+
return normalizeFernPaginatedResponse(
|
|
867
|
+
await listMessagesApi(request.chatId, listRequest, requestOptions),
|
|
868
|
+
normalizePlatformMessageRecord
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
const listAgentMessagesApi = this.client.agentApiMessages?.listAgentMessages?.bind(this.client.agentApiMessages);
|
|
872
|
+
if (!listAgentMessagesApi) {
|
|
873
|
+
throw new UnsupportedFeatureError("Fern client missing message list endpoint");
|
|
874
|
+
}
|
|
875
|
+
return normalizeFernPaginatedResponse(
|
|
876
|
+
await listAgentMessagesApi(request.chatId, listRequest, requestOptions),
|
|
877
|
+
normalizePlatformMessageRecord
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
async getChatContext(request, options) {
|
|
881
|
+
const requestOptions = mergeOptions(options);
|
|
882
|
+
const contextRequest = {
|
|
883
|
+
page: request.page,
|
|
884
|
+
page_size: request.pageSize
|
|
885
|
+
};
|
|
886
|
+
const getChatContextApi = this.client.chatContext?.getChatContext?.bind(this.client.chatContext);
|
|
887
|
+
if (getChatContextApi) {
|
|
888
|
+
return normalizeFernPaginatedResponse(
|
|
889
|
+
await getChatContextApi(request.chatId, contextRequest, requestOptions),
|
|
890
|
+
normalizePlatformMessageRecord
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
const getAgentChatContextApi = this.client.agentApiContext?.getAgentChatContext?.bind(this.client.agentApiContext);
|
|
894
|
+
if (!getAgentChatContextApi) {
|
|
895
|
+
throw new UnsupportedFeatureError("Fern client missing chat context endpoint");
|
|
896
|
+
}
|
|
897
|
+
return normalizeFernPaginatedResponse(
|
|
898
|
+
await getAgentChatContextApi(request.chatId, contextRequest, requestOptions),
|
|
899
|
+
normalizePlatformMessageRecord
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
// src/client/rest/RestFacade.ts
|
|
905
|
+
var OPTIONAL_UNSUPPORTED_MESSAGES = {
|
|
906
|
+
listChats: "Chat listing is not available in current REST adapter",
|
|
907
|
+
getChatContext: "Context hydration is not available in current REST adapter",
|
|
908
|
+
listMessages: "Message queue listing is not available in current REST adapter",
|
|
909
|
+
getNextMessage: "Message queue next-item lookup is not available in current REST adapter",
|
|
910
|
+
addContact: "Contact creation is not available in current REST adapter",
|
|
911
|
+
removeContact: "Contact removal is not available in current REST adapter",
|
|
912
|
+
respondContactRequest: "Contact request responses are not available in current REST adapter",
|
|
913
|
+
storeMemory: "Memory creation is not available in current REST adapter",
|
|
914
|
+
getMemory: "Memory lookup is not available in current REST adapter",
|
|
915
|
+
supersedeMemory: "Memory supersede is not available in current REST adapter",
|
|
916
|
+
archiveMemory: "Memory archive is not available in current REST adapter",
|
|
917
|
+
listContacts: "Contact listing is not available in current REST adapter",
|
|
918
|
+
listMemories: "Memory listing is not available in current REST adapter",
|
|
919
|
+
listPeers: "Peer listing is not available in current REST adapter",
|
|
920
|
+
listContactRequests: "Contact request listing is not available in current REST adapter"
|
|
921
|
+
};
|
|
922
|
+
var RestFacade = class {
|
|
923
|
+
api;
|
|
924
|
+
logger;
|
|
925
|
+
constructor(options) {
|
|
926
|
+
this.api = options.api;
|
|
927
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
928
|
+
}
|
|
929
|
+
async getAgentMe(options) {
|
|
930
|
+
return this.forward("getAgentMe", () => this.api.getAgentMe(options));
|
|
931
|
+
}
|
|
932
|
+
async createChatMessage(chatId, message, options) {
|
|
933
|
+
return this.forward("createChatMessage", () => this.api.createChatMessage(chatId, message, options), {
|
|
934
|
+
chatId,
|
|
935
|
+
messageType: message.messageType ?? "text",
|
|
936
|
+
mentionCount: message.mentions?.length ?? 0
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
async createChatEvent(chatId, event, options) {
|
|
940
|
+
return this.forward("createChatEvent", () => this.api.createChatEvent(chatId, event, options), {
|
|
941
|
+
chatId,
|
|
942
|
+
messageType: event.messageType
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
async createChat(taskId, options) {
|
|
946
|
+
return this.forward("createChat", () => this.api.createChat(taskId, options), {
|
|
947
|
+
taskId: taskId ?? null
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
async listChatParticipants(chatId, options) {
|
|
951
|
+
return this.forward(
|
|
952
|
+
"listChatParticipants",
|
|
953
|
+
() => this.api.listChatParticipants(chatId, options),
|
|
954
|
+
{ chatId }
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
async addChatParticipant(chatId, participant, options) {
|
|
958
|
+
return this.forward("addChatParticipant", () => this.api.addChatParticipant(chatId, participant, options), {
|
|
959
|
+
chatId,
|
|
960
|
+
participantId: participant.participantId,
|
|
961
|
+
role: participant.role
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
async removeChatParticipant(chatId, participantId, options) {
|
|
965
|
+
return this.forward(
|
|
966
|
+
"removeChatParticipant",
|
|
967
|
+
() => this.api.removeChatParticipant(chatId, participantId, options),
|
|
968
|
+
{ chatId, participantId }
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
async markMessageProcessing(chatId, messageId, options) {
|
|
972
|
+
return this.forward(
|
|
973
|
+
"markMessageProcessing",
|
|
974
|
+
() => this.api.markMessageProcessing(chatId, messageId, options),
|
|
975
|
+
{ chatId, messageId }
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
async markMessageProcessed(chatId, messageId, options) {
|
|
979
|
+
return this.forward(
|
|
980
|
+
"markMessageProcessed",
|
|
981
|
+
() => this.api.markMessageProcessed(chatId, messageId, options),
|
|
982
|
+
{ chatId, messageId }
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
async markMessageFailed(chatId, messageId, error, options) {
|
|
986
|
+
return this.forward(
|
|
987
|
+
"markMessageFailed",
|
|
988
|
+
() => this.api.markMessageFailed(chatId, messageId, error, options),
|
|
989
|
+
{ chatId, messageId }
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
async listChats(request, options) {
|
|
993
|
+
return this.callOptional(
|
|
994
|
+
"listChats",
|
|
995
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.listChats,
|
|
996
|
+
(method) => method(request, options),
|
|
997
|
+
request
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
async getChatContext(request, options) {
|
|
1001
|
+
return this.callOptional(
|
|
1002
|
+
"getChatContext",
|
|
1003
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.getChatContext,
|
|
1004
|
+
(method) => method(request, options),
|
|
1005
|
+
request
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
async listMessages(request, options) {
|
|
1009
|
+
return this.callOptional(
|
|
1010
|
+
"listMessages",
|
|
1011
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.listMessages,
|
|
1012
|
+
(method) => method(request, options),
|
|
1013
|
+
request
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
async getNextMessage(request, options) {
|
|
1017
|
+
return this.callOptional(
|
|
1018
|
+
"getNextMessage",
|
|
1019
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.getNextMessage,
|
|
1020
|
+
(method) => method(request, options),
|
|
1021
|
+
request
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
async addContact(request, options) {
|
|
1025
|
+
return this.callOptional(
|
|
1026
|
+
"addContact",
|
|
1027
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.addContact,
|
|
1028
|
+
(method) => method(request, options),
|
|
1029
|
+
request
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
async removeContact(request, options) {
|
|
1033
|
+
return this.callOptional(
|
|
1034
|
+
"removeContact",
|
|
1035
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.removeContact,
|
|
1036
|
+
(method) => method(request, options),
|
|
1037
|
+
request
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
async respondContactRequest(request, options) {
|
|
1041
|
+
return this.callOptional(
|
|
1042
|
+
"respondContactRequest",
|
|
1043
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.respondContactRequest,
|
|
1044
|
+
(method) => method(request, options),
|
|
1045
|
+
request
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
async storeMemory(request, options) {
|
|
1049
|
+
return this.callOptional(
|
|
1050
|
+
"storeMemory",
|
|
1051
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.storeMemory,
|
|
1052
|
+
(method) => method(request, options),
|
|
1053
|
+
request
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
async getMemory(memoryId, options) {
|
|
1057
|
+
return this.callOptional(
|
|
1058
|
+
"getMemory",
|
|
1059
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.getMemory,
|
|
1060
|
+
(method) => method(memoryId, options),
|
|
1061
|
+
{ memoryId }
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
async supersedeMemory(memoryId, options) {
|
|
1065
|
+
return this.callOptional(
|
|
1066
|
+
"supersedeMemory",
|
|
1067
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.supersedeMemory,
|
|
1068
|
+
(method) => method(memoryId, options),
|
|
1069
|
+
{ memoryId }
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
async archiveMemory(memoryId, options) {
|
|
1073
|
+
return this.callOptional(
|
|
1074
|
+
"archiveMemory",
|
|
1075
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.archiveMemory,
|
|
1076
|
+
(method) => method(memoryId, options),
|
|
1077
|
+
{ memoryId }
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
async listContacts(request, options) {
|
|
1081
|
+
return this.callOptional(
|
|
1082
|
+
"listContacts",
|
|
1083
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.listContacts,
|
|
1084
|
+
async (method) => {
|
|
1085
|
+
const response = await method(request, options);
|
|
1086
|
+
return {
|
|
1087
|
+
data: response.data ?? [],
|
|
1088
|
+
metadata: normalizePaginationMetadata(response.metadata)
|
|
1089
|
+
};
|
|
1090
|
+
},
|
|
1091
|
+
request
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
async listMemories(request, options) {
|
|
1095
|
+
return this.callOptional(
|
|
1096
|
+
"listMemories",
|
|
1097
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.listMemories,
|
|
1098
|
+
async (method) => {
|
|
1099
|
+
const response = await method(request, options);
|
|
1100
|
+
return {
|
|
1101
|
+
data: response.data ?? [],
|
|
1102
|
+
metadata: normalizePaginationMetadata(response.metadata)
|
|
1103
|
+
};
|
|
1104
|
+
},
|
|
1105
|
+
request
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
async listPeers(request, options) {
|
|
1109
|
+
return this.callOptional(
|
|
1110
|
+
"listPeers",
|
|
1111
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.listPeers,
|
|
1112
|
+
async (method) => {
|
|
1113
|
+
const response = await method(request, options);
|
|
1114
|
+
return {
|
|
1115
|
+
data: response.data ?? [],
|
|
1116
|
+
metadata: normalizePaginationMetadata(response.metadata)
|
|
1117
|
+
};
|
|
1118
|
+
},
|
|
1119
|
+
request
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
async listContactRequests(request, options) {
|
|
1123
|
+
return this.callOptional(
|
|
1124
|
+
"listContactRequests",
|
|
1125
|
+
OPTIONAL_UNSUPPORTED_MESSAGES.listContactRequests,
|
|
1126
|
+
async (method) => normalizeContactRequestsResult(await method(request, options)),
|
|
1127
|
+
request
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
async listAllChats(options, requestOptions) {
|
|
1131
|
+
return fetchPaginated({
|
|
1132
|
+
fetchPage: ({ page, pageSize }) => this.listChats({ page, pageSize }, requestOptions),
|
|
1133
|
+
pageSize: options?.pageSize,
|
|
1134
|
+
maxPages: options?.maxPages,
|
|
1135
|
+
strategy: options?.strategy,
|
|
1136
|
+
metadataValidation: options?.metadataValidation
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
callOptional(operation, unsupportedMessage, invoke, metadata) {
|
|
1140
|
+
const method = this.api[operation];
|
|
1141
|
+
if (!method) {
|
|
1142
|
+
throw new UnsupportedFeatureError(unsupportedMessage);
|
|
1143
|
+
}
|
|
1144
|
+
const boundMethod = method.bind(this.api);
|
|
1145
|
+
return this.forward(String(operation), () => invoke(boundMethod), metadata);
|
|
1146
|
+
}
|
|
1147
|
+
forward(operation, call, metadata) {
|
|
1148
|
+
this.logger.debug(`REST ${operation}`, metadata);
|
|
1149
|
+
return call();
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1153
|
+
0 && (module.exports = {
|
|
1154
|
+
DEFAULT_REQUEST_OPTIONS,
|
|
1155
|
+
FernRestAdapter,
|
|
1156
|
+
RestFacade,
|
|
1157
|
+
fetchPaginated,
|
|
1158
|
+
normalizePaginationMetadata
|
|
1159
|
+
});
|