@agentforge-io/sdk-server 4.51.0 → 4.53.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/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export type { AgentForgeClientOptions, RequestOptions } from './client';
3
3
  export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, } from './errors';
4
4
  export { APP_WEBHOOK_HEADERS, TOOL_CALLBACK_HEADERS, ToolCallbackSignatureError, signToolCallbackPayload, verifyAppWebhook, verifyToolCallbackSignature, } from './webhooks';
5
5
  export { WebhookResource, type SetAppWebhookInput } from './resources/webhook';
6
- export type { AppWebhook, AppWebhookEvent, AppWebhookEventName, AgentMe, AgentSummary, AppUserConnectorStatus, ApprovalCopyBundle, ChannelContext, ChatStreamChunk, ChatStreamEvent, ChatTokenRecord, ConnectorDefaultsResult, ConnectorDefaultsSource, ConnectorResourceItem, ConnectorStatus, ConnectorToolInfo, ConversationHistory, ConversationStatus, CreateAgentInput, CreateClickupTaskInput, CreateClickupTaskResult, ExternalToolSummary, IssueChatTokenInput, ListAgentsResult, ListConnectorResourcesResult, McpServerConfig, MessageRecord, MessageRole, PublicAppBranding, PublicProfileBlock, PublicProfileTemplate, PublicTeamLanding, CreateTeamInput, UpdateTeamInput, TeamSummary, TeamDetail, TeamTheme, TeamBusinessHours, TeamWeekday, TeamProfileBlock, AppInstallation, TemplateConfigField, TemplateSummary, TemplateDetail, TemplateCategoryRef, MarketplaceCategory, MarketplaceCategoryGroup, MarketplaceLocale, TemplateInstallResult, TemplateReview, TemplateRatingSummary, TemplateReviewsPage, BusinessReview, BusinessReviewsPage, ListTemplateReviewsInput, SaveTemplateReviewInput, TemplateReportKind, CreateTemplateReportInput, TenantConfigEntry, Place, PlaceSuggestion, SearchPlacesInput, AutocompletePlacesInput, PlacesScope, CaseField, CaseBusinessState, CaseType, CaseState, CasePayment, CasePaymentAccount, CasePaymentStatus, CaseReceiptPayment, CaseDestination, CaseView, CaseStateStep, CreateDirectOrderInput, CreateDirectBookingInput, MoveCaseSlotInput, CaseSlot, CatalogAttendedAt, CatalogBookingRule, CaseOrigin, CaseOriginChannel, DirectOrderForm, DirectPaymentOption, CaseClosingMethod, CaseClosingOrder, CaseClosingReport, CaseReceipt, CaseReceiptLine, ListCasesInput, AddressValue, DeliveryLocalPricing, DeliverySettings, PaymentMethodKind, PaymentSettings, PaymentSettingsInput, PaymentAccount, PaymentCountry, PaymentFieldDef, PaymentMethodDef, StructuredConfigInput, StructuredConfigEntry, DeliveryQuoteStatus, DeliveryQuoteInput, DeliveryRoute, DeliveryRouteInput, DeliveryQuote, AppSelf, AppSelfConnector, AppSelfConnectors, AppSelfConnectorTools, AppSelfConnectorToolsResponse, RegisterToolInput, RegisterToolsInput, BusinessRoleEntry, Catalog, CatalogCheckoutCta, CatalogCategory, CatalogProduct, CatalogProductPhoto, CatalogProductKind, CatalogProductStatus, CatalogPriceKind, CatalogAvailability, CatalogLockableField, CatalogProductPage, UpsertCatalogInput, CreateCatalogCategoryInput, UpdateCatalogCategoryInput, CreateCatalogProductInput, UpdateCatalogProductInput, ListCatalogProductsInput, CatalogPhotoUploadTarget, SignCatalogPhotoUploadInput, AttachCatalogPhotoInput, CatalogImportItem, CatalogImportPreview, CatalogImportApplyResult, CatalogFileMapping, CatalogFilePlan, CatalogFilePreview, CatalogFileApplyResult, CatalogFileInput, CatalogFilePreviewInput, CatalogMenuItem, CatalogMenuRead, CatalogMenuReadInput, CatalogMenuAttachInput, CatalogMenuChatFile, CatalogMenuKeepInSyncInput, CatalogMenuKeepInSyncResult, CatalogOption, CatalogOptionGroup, SaveCatalogOptionGroupInput, CatalogOptionChoice, CatalogOptionChange, CatalogOptionChangesPlan, CatalogUnit, SaveCatalogUnitInput, CatalogSaleRule, CatalogFileApplyInput, CatalogFileErrorCode, CatalogImportSourceStatus, CatalogImportColumnMapping, CatalogImportRunResult, CatalogImportSource, CreateCatalogImportSourceInput, UpdateCatalogImportSourceInput, PreviewCatalogImportSourceInput, CatalogImportSourcePreview, CatalogSheetTab, CatalogTemplateSheet, CreateCatalogTemplateSheetInput, GoogleSheetsPickerInput, GoogleSheetsPickerSession, GoogleSheetsPickerErrorCode, GoogleSheetsPickerResult, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
6
+ export type { AppWebhook, AppWebhookEvent, AppWebhookEventName, AgentMe, AgentSummary, AppUserConnectorStatus, ApprovalCopyBundle, ChannelContext, ChatStreamChunk, ChatStreamEvent, ChatTokenRecord, ConnectorDefaultsResult, ConnectorDefaultsSource, ConnectorResourceItem, ConnectorStatus, ConnectorToolInfo, ConversationHistory, ConversationStatus, CreateAgentInput, CreateClickupTaskInput, CreateClickupTaskResult, ExternalToolSummary, IssueChatTokenInput, ListAgentsResult, ListConnectorResourcesResult, McpServerConfig, MessageRecord, MessageRole, PublicAppBranding, PublicProfileBlock, PublicProfileTemplate, PublicTeamLanding, CreateTeamInput, UpdateTeamInput, TeamSummary, TeamDetail, TeamTheme, TeamBusinessHours, TeamWeekday, TeamProfileBlock, AppInstallation, TemplateConfigField, TemplateSummary, TemplateDetail, TemplateCategoryRef, MarketplaceCategory, MarketplaceCategoryGroup, MarketplaceLocale, TemplateInstallResult, TemplateReview, TemplateRatingSummary, TemplateReviewsPage, BusinessReview, BusinessReviewsPage, ListTemplateReviewsInput, SaveTemplateReviewInput, TemplateReportKind, CreateTemplateReportInput, TenantConfigEntry, Place, PlaceSuggestion, SearchPlacesInput, AutocompletePlacesInput, PlacesScope, CaseField, CaseBusinessState, CaseType, CaseState, CasePayment, CasePaymentAccount, CasePaymentStatus, CaseReceiptPayment, CaseDestination, CaseView, CaseStateStep, CreateDirectOrderInput, CreateDirectBookingInput, MoveCaseSlotInput, CaseSlot, CatalogAttendedAt, CatalogBookingRule, CaseOrigin, CaseOriginChannel, DirectOrderForm, DirectPaymentOption, CaseClosingMethod, CaseClosingOrder, CaseClosingReport, CaseReportPage, CaseReceipt, CaseReceiptLine, ListCasesInput, AddressValue, DeliveryLocalPricing, DeliverySettings, PaymentMethodKind, PaymentSettings, PaymentSettingsInput, PaymentAccount, PaymentCountry, PaymentFieldDef, PaymentMethodDef, StructuredConfigInput, StructuredConfigEntry, DeliveryQuoteStatus, DeliveryQuoteInput, DeliveryRoute, DeliveryRouteInput, DeliveryQuote, AppSelf, AppSelfConnector, AppSelfConnectors, AppSelfConnectorTools, AppSelfConnectorToolsResponse, RegisterToolInput, RegisterToolsInput, BusinessRoleEntry, Catalog, CatalogCheckoutCta, CatalogCategory, CatalogProduct, CatalogProductPhoto, CatalogProductKind, CatalogProductStatus, CatalogPriceKind, CatalogAvailability, CatalogLockableField, CatalogProductPage, UpsertCatalogInput, CreateCatalogCategoryInput, UpdateCatalogCategoryInput, CreateCatalogProductInput, UpdateCatalogProductInput, ListCatalogProductsInput, CatalogPhotoUploadTarget, SignCatalogPhotoUploadInput, AttachCatalogPhotoInput, CatalogImportItem, CatalogImportPreview, CatalogImportApplyResult, CatalogFileMapping, CatalogFilePlan, CatalogFilePreview, CatalogFileApplyResult, CatalogFileInput, CatalogFilePreviewInput, CatalogMenuItem, CatalogMenuRead, CatalogMenuReadInput, CatalogMenuAttachInput, CatalogMenuChatFile, CatalogMenuKeepInSyncInput, CatalogMenuKeepInSyncResult, CatalogOption, CatalogOptionGroup, SaveCatalogOptionGroupInput, CatalogOptionChoice, CatalogOptionChange, CatalogOptionChangesPlan, CatalogUnit, SaveCatalogUnitInput, CatalogSaleRule, CatalogFileApplyInput, CatalogFileErrorCode, CatalogImportSourceStatus, CatalogImportColumnMapping, CatalogImportRunResult, CatalogImportSource, CreateCatalogImportSourceInput, UpdateCatalogImportSourceInput, PreviewCatalogImportSourceInput, CatalogImportSourcePreview, CatalogSheetTab, CatalogTemplateSheet, CreateCatalogTemplateSheetInput, GoogleSheetsPickerInput, GoogleSheetsPickerSession, GoogleSheetsPickerErrorCode, GoogleSheetsPickerResult, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
7
7
  export { AgentsResource } from './resources/agents';
8
8
  export { AnalyticsResource } from './resources/analytics';
9
9
  export type { GetSupportKpisInput, GetAgentAttentionLogInput, } from './resources/analytics';
@@ -11,7 +11,7 @@ export { AppsResource } from './resources/apps';
11
11
  export { ChatResource } from './resources/chat';
12
12
  export type { AnthropicClientOptions, AppCallerClaims, StreamMessageInput, StreamMessageForAppUserInput, } from './resources/chat';
13
13
  export { ConnectorsResource, parseGoogleSheetsPickerResult } from './resources/connectors';
14
- export type { InboxChannelView } from './resources/connectors';
14
+ export type { AppCreateInboxChannelInput, CreateInboxChannelInput, InboxChannelLinkMethod, InboxChannelReplyMode, InboxChannelView, RelinkInboxChannelInput, StartWhatsAppCloudLinkInput, WhatsAppCloudConnectionType, WhatsAppCloudLinkResult, WhatsAppCloudLinkStart, WhatsAppCloudNumber, } from './resources/connectors';
15
15
  export { InboxResource } from './resources/inbox';
16
16
  export { InstallationsResource } from './resources/installations';
17
17
  export type { InstallAppInput } from './resources/installations';
@@ -1,5 +1,5 @@
1
1
  import type { AgentForgeClient } from '../client';
2
- import type { CaseClosingReport, CasePaymentStatus, CaseReceipt, CaseState, CaseView, CreateDirectBookingInput, CreateDirectOrderInput, DirectOrderForm, ListCasesInput, MoveCaseSlotInput } from '../types';
2
+ import type { CaseClosingReport, CaseReportPage, CasePaymentStatus, CaseReceipt, CaseState, CaseView, CreateDirectBookingInput, CreateDirectOrderInput, DirectOrderForm, ListCasesInput, MoveCaseSlotInput } from '../types';
3
3
  export declare class CasesResource {
4
4
  private readonly client;
5
5
  constructor(client: AgentForgeClient);
@@ -14,6 +14,17 @@ export declare class CasesResource {
14
14
  from: string | Date;
15
15
  to: string | Date;
16
16
  }): Promise<CaseClosingReport>;
17
+ /**
18
+ * `GET /api/v1/cases/reports/orders` — AGF-CASH-REGISTER: the cases sent between two
19
+ * instants, (`from`, `to`], oldest first, with what each receipt says. A report of any
20
+ * size, page by page (`limit` ≤ 500): one call a page, never one per case.
21
+ */
22
+ ordersReport(input: {
23
+ from: string | Date;
24
+ to: string | Date;
25
+ cursor?: string;
26
+ limit?: number;
27
+ }): Promise<CaseReportPage>;
17
28
  /** `GET /api/v1/cases/:id` — 404 when it is not this workspace's. */
18
29
  get(caseId: string): Promise<CaseView>;
19
30
  /**
@@ -42,6 +42,20 @@ class CasesResource {
42
42
  const qs = new URLSearchParams({ from: at(input.from), to: at(input.to) });
43
43
  return this.client.request('GET', `/api/v1/cases/reports/closing?${qs}`);
44
44
  }
45
+ /**
46
+ * `GET /api/v1/cases/reports/orders` — AGF-CASH-REGISTER: the cases sent between two
47
+ * instants, (`from`, `to`], oldest first, with what each receipt says. A report of any
48
+ * size, page by page (`limit` ≤ 500): one call a page, never one per case.
49
+ */
50
+ async ordersReport(input) {
51
+ const at = (v) => (v instanceof Date ? v.toISOString() : v);
52
+ const qs = new URLSearchParams({ from: at(input.from), to: at(input.to) });
53
+ if (input.cursor)
54
+ qs.set('cursor', input.cursor);
55
+ if (input.limit !== undefined)
56
+ qs.set('limit', String(input.limit));
57
+ return this.client.request('GET', `/api/v1/cases/reports/orders?${qs}`);
58
+ }
45
59
  /** `GET /api/v1/cases/:id` — 404 when it is not this workspace's. */
46
60
  async get(caseId) {
47
61
  return this.client.request('GET', `/api/v1/cases/${encodeURIComponent(caseId)}`);
@@ -195,10 +195,15 @@ export declare class ConnectorsResource {
195
195
  * `ak_live_` tenant-wide alcanza — el server valida que `agentId`
196
196
  * pertenezca a este tenant).
197
197
  *
198
+ * `includeDisconnected` adds the disconnected channels that still have
199
+ * threads to read, with `status: 'destroyed'`.
200
+ *
198
201
  * @example
199
202
  * const { items } = await af.connectors.listInboxChannels(agentId);
200
203
  */
201
- listInboxChannels(agentId: string): Promise<{
204
+ listInboxChannels(agentId: string, opts?: {
205
+ includeDisconnected?: boolean;
206
+ }): Promise<{
202
207
  items: InboxChannelView[];
203
208
  }>;
204
209
  /**
@@ -208,22 +213,114 @@ export declare class ConnectorsResource {
208
213
  * `SlackBotProvider.credentialsForm` en agentforge-platform para el shape
209
214
  * exacto de cada provider).
210
215
  *
216
+ * With an App secret (`sk_live_`, usually through `forTenant`) leave
217
+ * `credentials` out: the platform provides the gateway and refuses them
218
+ * with a 400. Only `whatsapp-web` is accepted on that path, `label` is
219
+ * required, and `replyMode` defaults to `human`. An official number comes
220
+ * from `startWhatsAppCloudLink` or `connectWhatsAppCloudNumber` instead.
221
+ *
222
+ * Throws `AgentForgeError` with `code`: `channel_number_in_use` (409),
223
+ * `whatsapp_gateway_unavailable` (503).
224
+ *
211
225
  * @example
212
226
  * await af.connectors.createInboxChannel(agentId, {
213
227
  * providerId: 'slack-bot',
214
228
  * credentials: { signingSecret: '8f742...' },
215
229
  * });
230
+ *
231
+ * @example
232
+ * const channel = await af.forTenant(tenantId).connectors.createInboxChannel(agentId, {
233
+ * providerId: 'whatsapp-web',
234
+ * label: 'Tienda',
235
+ * linkMethod: 'phone',
236
+ * phoneNumber: '573001234567',
237
+ * });
216
238
  */
217
- createInboxChannel(agentId: string, input: {
218
- providerId: string;
219
- label?: string;
220
- credentials: Record<string, unknown>;
221
- }): Promise<InboxChannelView>;
239
+ createInboxChannel(agentId: string, input: CreateInboxChannelInput): Promise<InboxChannelView>;
240
+ createInboxChannel(agentId: string, input: AppCreateInboxChannelInput): Promise<InboxChannelView>;
222
241
  /**
223
242
  * `DELETE /connectors/inbox/agents/:agentId/inbox/channels/:channelId` —
224
243
  * desconecta un canal del inbox omnicanal.
225
244
  */
226
245
  destroyInboxChannel(agentId: string, channelId: string): Promise<void>;
246
+ /**
247
+ * `GET …/inbox/channels/:channelId` — a channel, with a fresh status. Poll it
248
+ * while a number links.
249
+ */
250
+ getInboxChannel(agentId: string, channelId: string): Promise<InboxChannelView>;
251
+ /**
252
+ * `GET …/inbox/channels/:channelId/qr.png` — the current QR as PNG bytes. It
253
+ * rotates: fetch it again rather than keep it.
254
+ *
255
+ * Throws `AgentForgeNotFoundError` with `code` `qr_not_ready` (poll again), or
256
+ * `AgentForgeError` with `whatsapp_gateway_unavailable` (503).
257
+ */
258
+ inboxChannelQrPng(agentId: string, channelId: string): Promise<Uint8Array>;
259
+ /**
260
+ * `GET …/inbox/channels/:channelId/pairing-code` — the 8-character code the
261
+ * owner types on their phone.
262
+ *
263
+ * Throws `AgentForgeNotFoundError` with `code` `pairing_code_not_ready` (poll
264
+ * again), or `AgentForgeError` with `whatsapp_gateway_unavailable` (503).
265
+ */
266
+ inboxChannelPairingCode(agentId: string, channelId: string): Promise<{
267
+ pairingCode: string;
268
+ }>;
269
+ /**
270
+ * `POST …/inbox/channels/:channelId/relink` — starts linking again, by QR or
271
+ * phone. `phoneNumber` goes with `linkMethod: 'phone'` only.
272
+ *
273
+ * Throws `AgentForgeError` with `code`: `channel_number_in_use`,
274
+ * `channel_already_linked` (disconnect it first), `channel_session_gone`
275
+ * (delete it and connect again), all 409; `whatsapp_gateway_unavailable` (503).
276
+ */
277
+ relinkInboxChannel(agentId: string, channelId: string, input: RelinkInboxChannelInput): Promise<InboxChannelView>;
278
+ /**
279
+ * `PATCH …/inbox/channels/:channelId` — who answers this channel. Accepted on
280
+ * `whatsapp-web` and `whatsapp-cloud` channels; 400 on any other provider.
281
+ */
282
+ setInboxChannelReplyMode(agentId: string, channelId: string, replyMode: InboxChannelReplyMode): Promise<InboxChannelView>;
283
+ /**
284
+ * `POST …/inbox/whatsapp-cloud/start` — starts linking an official number.
285
+ * Open `url`, then call `pollWhatsAppCloudLink` with `excludeIds`.
286
+ * `connectionTypes` defaults to `['coexistence']` on the platform.
287
+ *
288
+ * Throws `AgentForgeError` with `code`: `whatsapp_cloud_link_busy` (409,
289
+ * another agent or App of this business is connecting),
290
+ * `whatsapp_cloud_number_limit` (409), `whatsapp_cloud_unavailable` (503).
291
+ */
292
+ startWhatsAppCloudLink(agentId: string, input?: StartWhatsAppCloudLinkInput): Promise<WhatsAppCloudLinkStart>;
293
+ /**
294
+ * `POST …/inbox/whatsapp-cloud/poll` — `{ channel }` once the number is
295
+ * connected, with `replyMode: 'human'`, else `{ channel: null }`. Safe to repeat.
296
+ *
297
+ * Throws `AgentForgeError` with `code`: `whatsapp_cloud_number_limit` (409),
298
+ * `whatsapp_cloud_unavailable` (503).
299
+ */
300
+ pollWhatsAppCloudLink(agentId: string, input?: {
301
+ excludeIds?: string[];
302
+ }): Promise<WhatsAppCloudLinkResult>;
303
+ /**
304
+ * `GET …/inbox/whatsapp-cloud/numbers` — the numbers already on Kapso that
305
+ * this business can connect: its own, free and connected.
306
+ *
307
+ * Throws `AgentForgeError` with `code` `whatsapp_cloud_unavailable` (503).
308
+ */
309
+ listWhatsAppCloudNumbers(agentId: string): Promise<{
310
+ items: WhatsAppCloudNumber[];
311
+ }>;
312
+ /**
313
+ * `POST …/inbox/whatsapp-cloud/connect` — connects a number from
314
+ * `listWhatsAppCloudNumbers`. `{ channel: null }` means another call is
315
+ * finishing it: call again. Safe to repeat.
316
+ *
317
+ * Throws `AgentForgeNotFoundError` with `code` `whatsapp_cloud_number_not_found`,
318
+ * or `AgentForgeError` with `channel_number_in_use` (409),
319
+ * `whatsapp_cloud_number_limit` (409), `whatsapp_cloud_unavailable` (503).
320
+ */
321
+ connectWhatsAppCloudNumber(agentId: string, phoneNumberId: string): Promise<WhatsAppCloudLinkResult>;
322
+ /** The App secret on the wire, whatever else this client holds. */
323
+ private asApp;
227
324
  /**
228
325
  * `POST /connectors/oauth/:id/authorize-for-app-user` — starts the
229
326
  * connector OAuth flow on behalf of ONE end user of the `sk_live_`/
@@ -398,6 +495,8 @@ export declare class ConnectorsResource {
398
495
  connectorId: string;
399
496
  }>;
400
497
  }
498
+ /** Who answers a channel: `agent` (the AI) or `human` (only people). */
499
+ export type InboxChannelReplyMode = 'human' | 'agent';
401
500
  export interface InboxChannelView {
402
501
  id: string;
403
502
  tenantId: string;
@@ -408,12 +507,67 @@ export interface InboxChannelView {
408
507
  status: string;
409
508
  lastError?: string;
410
509
  lastSeenAt?: string;
510
+ replyMode: InboxChannelReplyMode;
411
511
  displayName?: string;
412
512
  username?: string;
413
513
  avatarUrl?: string;
414
514
  createdAt: string;
415
515
  updatedAt: string;
416
516
  }
517
+ /** How a `whatsapp-web` channel links: a QR, or a code typed on the phone. */
518
+ export type InboxChannelLinkMethod = 'qr' | 'phone';
519
+ export interface CreateInboxChannelInput {
520
+ providerId: string;
521
+ label?: string;
522
+ credentials: Record<string, unknown>;
523
+ linkMethod?: InboxChannelLinkMethod;
524
+ phoneNumber?: string;
525
+ /** Absent: `agent` with an `ak_live_`. */
526
+ replyMode?: InboxChannelReplyMode;
527
+ }
528
+ /** What an App sends: no credentials, the platform provides the gateway. */
529
+ export interface AppCreateInboxChannelInput {
530
+ /** `whatsapp-web` is the only one an App can create this way. */
531
+ providerId: string;
532
+ /** Up to 120 characters. */
533
+ label: string;
534
+ /** Default: QR. */
535
+ linkMethod?: InboxChannelLinkMethod;
536
+ /** Required with `linkMethod: 'phone'`: 7 to 15 digits with the country code. */
537
+ phoneNumber?: string;
538
+ /** Default: `human`. */
539
+ replyMode?: InboxChannelReplyMode;
540
+ credentials?: undefined;
541
+ }
542
+ export interface RelinkInboxChannelInput {
543
+ linkMethod: InboxChannelLinkMethod;
544
+ /** Required with `linkMethod: 'phone'`, refused with `qr`. */
545
+ phoneNumber?: string;
546
+ }
547
+ export type WhatsAppCloudConnectionType = 'coexistence' | 'dedicated';
548
+ export interface StartWhatsAppCloudLinkInput {
549
+ /** Non-empty when present. Absent: `['coexistence']`. */
550
+ connectionTypes?: WhatsAppCloudConnectionType[];
551
+ /** Origin of the page that opens `url`. */
552
+ openerOrigin?: string;
553
+ }
554
+ export interface WhatsAppCloudLinkStart {
555
+ /** Where the owner connects the number. */
556
+ url: string;
557
+ /** Numbers that existed before this link. Pass them to `pollWhatsAppCloudLink`. */
558
+ excludeIds: string[];
559
+ }
560
+ export interface WhatsAppCloudLinkResult {
561
+ channel: InboxChannelView | null;
562
+ }
563
+ export interface WhatsAppCloudNumber {
564
+ phoneNumberId: string;
565
+ displayPhoneNumber: string | null;
566
+ verifiedName: string | null;
567
+ connectionType: WhatsAppCloudConnectionType | null;
568
+ /** This tenant had it on a channel: connecting it brings those chats back. */
569
+ previouslyConnected: boolean;
570
+ }
417
571
  /**
418
572
  * Reads the Google Sheets Picker outcome from the `returnTo` URL the hosted
419
573
  * picker navigated to (`connectors.googleSheetsPicker()`). Accepts the full
@@ -208,34 +208,135 @@ class ConnectorsResource {
208
208
  * `ak_live_` tenant-wide alcanza — el server valida que `agentId`
209
209
  * pertenezca a este tenant).
210
210
  *
211
+ * `includeDisconnected` adds the disconnected channels that still have
212
+ * threads to read, with `status: 'destroyed'`.
213
+ *
211
214
  * @example
212
215
  * const { items } = await af.connectors.listInboxChannels(agentId);
213
216
  */
214
- async listInboxChannels(agentId) {
215
- return this.client.requestWithApiKey('GET', `/connectors/inbox/agents/${encodeURIComponent(agentId)}/inbox/channels`);
217
+ async listInboxChannels(agentId, opts = {}) {
218
+ return this.client.requestWithApiKey('GET', `${inboxPath(agentId)}/channels${opts.includeDisconnected ? '?includeDisconnected=true' : ''}`);
216
219
  }
217
- /**
218
- * `POST /connectors/inbox/agents/:agentId/inbox/channels` — conecta un
219
- * canal del inbox omnicanal para `agentId` (ej. `providerId: 'slack-bot'`
220
- * con `credentials: { signingSecret, botUserId? }` — ver
221
- * `SlackBotProvider.credentialsForm` en agentforge-platform para el shape
222
- * exacto de cada provider).
223
- *
224
- * @example
225
- * await af.connectors.createInboxChannel(agentId, {
226
- * providerId: 'slack-bot',
227
- * credentials: { signingSecret: '8f742...' },
228
- * });
229
- */
230
220
  async createInboxChannel(agentId, input) {
231
- return this.client.requestWithApiKey('POST', `/connectors/inbox/agents/${encodeURIComponent(agentId)}/inbox/channels`, input);
221
+ // No credentials is the App path, even on a client that also has an ak_live_.
222
+ return input.credentials === undefined && this.client.getAppSecret()
223
+ ? this.client.request('POST', `${inboxPath(agentId)}/channels`, input, this.asApp('createInboxChannel'))
224
+ : this.client.requestWithApiKey('POST', `${inboxPath(agentId)}/channels`, input);
232
225
  }
233
226
  /**
234
227
  * `DELETE /connectors/inbox/agents/:agentId/inbox/channels/:channelId` —
235
228
  * desconecta un canal del inbox omnicanal.
236
229
  */
237
230
  async destroyInboxChannel(agentId, channelId) {
238
- await this.client.requestWithApiKey('DELETE', `/connectors/inbox/agents/${encodeURIComponent(agentId)}/inbox/channels/${encodeURIComponent(channelId)}`);
231
+ await this.client.requestWithApiKey('DELETE', `${inboxPath(agentId)}/channels/${encodeURIComponent(channelId)}`);
232
+ }
233
+ // ─── Inbox channels an App links from its own UI (AGF-101h) ─────────────
234
+ //
235
+ // The routes below take an App secret only (`sk_live_`/`sk_test_`, usually
236
+ // through `forTenant`): the server answers 401 to an `ak_live_`, and these
237
+ // throw early on a client without a secret. Same rule as the App-user scope
238
+ // further down, except the secret is forced with `asApp`, so a client that
239
+ // also holds an `ak_live_` or a ChatToken still authenticates as the App.
240
+ //
241
+ // Every one answers 404 when the agent is not this App's in this tenant.
242
+ /**
243
+ * `GET …/inbox/channels/:channelId` — a channel, with a fresh status. Poll it
244
+ * while a number links.
245
+ */
246
+ async getInboxChannel(agentId, channelId) {
247
+ return this.client.request('GET', `${inboxPath(agentId)}/channels/${encodeURIComponent(channelId)}`, undefined, this.asApp('getInboxChannel'));
248
+ }
249
+ /**
250
+ * `GET …/inbox/channels/:channelId/qr.png` — the current QR as PNG bytes. It
251
+ * rotates: fetch it again rather than keep it.
252
+ *
253
+ * Throws `AgentForgeNotFoundError` with `code` `qr_not_ready` (poll again), or
254
+ * `AgentForgeError` with `whatsapp_gateway_unavailable` (503).
255
+ */
256
+ async inboxChannelQrPng(agentId, channelId) {
257
+ const app = this.asApp('inboxChannelQrPng');
258
+ const res = await this.client.requestRaw('GET', `${inboxPath(agentId)}/channels/${encodeURIComponent(channelId)}/qr.png`, { ...app, headers: { ...app.headers, accept: 'image/png' } });
259
+ return new Uint8Array(await res.arrayBuffer());
260
+ }
261
+ /**
262
+ * `GET …/inbox/channels/:channelId/pairing-code` — the 8-character code the
263
+ * owner types on their phone.
264
+ *
265
+ * Throws `AgentForgeNotFoundError` with `code` `pairing_code_not_ready` (poll
266
+ * again), or `AgentForgeError` with `whatsapp_gateway_unavailable` (503).
267
+ */
268
+ async inboxChannelPairingCode(agentId, channelId) {
269
+ return this.client.request('GET', `${inboxPath(agentId)}/channels/${encodeURIComponent(channelId)}/pairing-code`, undefined, this.asApp('inboxChannelPairingCode'));
270
+ }
271
+ /**
272
+ * `POST …/inbox/channels/:channelId/relink` — starts linking again, by QR or
273
+ * phone. `phoneNumber` goes with `linkMethod: 'phone'` only.
274
+ *
275
+ * Throws `AgentForgeError` with `code`: `channel_number_in_use`,
276
+ * `channel_already_linked` (disconnect it first), `channel_session_gone`
277
+ * (delete it and connect again), all 409; `whatsapp_gateway_unavailable` (503).
278
+ */
279
+ async relinkInboxChannel(agentId, channelId, input) {
280
+ return this.client.request('POST', `${inboxPath(agentId)}/channels/${encodeURIComponent(channelId)}/relink`, input, this.asApp('relinkInboxChannel'));
281
+ }
282
+ /**
283
+ * `PATCH …/inbox/channels/:channelId` — who answers this channel. Accepted on
284
+ * `whatsapp-web` and `whatsapp-cloud` channels; 400 on any other provider.
285
+ */
286
+ async setInboxChannelReplyMode(agentId, channelId, replyMode) {
287
+ return this.client.request('PATCH', `${inboxPath(agentId)}/channels/${encodeURIComponent(channelId)}`, { replyMode }, this.asApp('setInboxChannelReplyMode'));
288
+ }
289
+ /**
290
+ * `POST …/inbox/whatsapp-cloud/start` — starts linking an official number.
291
+ * Open `url`, then call `pollWhatsAppCloudLink` with `excludeIds`.
292
+ * `connectionTypes` defaults to `['coexistence']` on the platform.
293
+ *
294
+ * Throws `AgentForgeError` with `code`: `whatsapp_cloud_link_busy` (409,
295
+ * another agent or App of this business is connecting),
296
+ * `whatsapp_cloud_number_limit` (409), `whatsapp_cloud_unavailable` (503).
297
+ */
298
+ async startWhatsAppCloudLink(agentId, input = {}) {
299
+ return this.client.request('POST', `${inboxPath(agentId)}/whatsapp-cloud/start`, input, this.asApp('startWhatsAppCloudLink'));
300
+ }
301
+ /**
302
+ * `POST …/inbox/whatsapp-cloud/poll` — `{ channel }` once the number is
303
+ * connected, with `replyMode: 'human'`, else `{ channel: null }`. Safe to repeat.
304
+ *
305
+ * Throws `AgentForgeError` with `code`: `whatsapp_cloud_number_limit` (409),
306
+ * `whatsapp_cloud_unavailable` (503).
307
+ */
308
+ async pollWhatsAppCloudLink(agentId, input = {}) {
309
+ return this.client.request('POST', `${inboxPath(agentId)}/whatsapp-cloud/poll`, input, this.asApp('pollWhatsAppCloudLink'));
310
+ }
311
+ /**
312
+ * `GET …/inbox/whatsapp-cloud/numbers` — the numbers already on Kapso that
313
+ * this business can connect: its own, free and connected.
314
+ *
315
+ * Throws `AgentForgeError` with `code` `whatsapp_cloud_unavailable` (503).
316
+ */
317
+ async listWhatsAppCloudNumbers(agentId) {
318
+ return this.client.request('GET', `${inboxPath(agentId)}/whatsapp-cloud/numbers`, undefined, this.asApp('listWhatsAppCloudNumbers'));
319
+ }
320
+ /**
321
+ * `POST …/inbox/whatsapp-cloud/connect` — connects a number from
322
+ * `listWhatsAppCloudNumbers`. `{ channel: null }` means another call is
323
+ * finishing it: call again. Safe to repeat.
324
+ *
325
+ * Throws `AgentForgeNotFoundError` with `code` `whatsapp_cloud_number_not_found`,
326
+ * or `AgentForgeError` with `channel_number_in_use` (409),
327
+ * `whatsapp_cloud_number_limit` (409), `whatsapp_cloud_unavailable` (503).
328
+ */
329
+ async connectWhatsAppCloudNumber(agentId, phoneNumberId) {
330
+ return this.client.request('POST', `${inboxPath(agentId)}/whatsapp-cloud/connect`, { phoneNumberId }, this.asApp('connectWhatsAppCloudNumber'));
331
+ }
332
+ /** The App secret on the wire, whatever else this client holds. */
333
+ asApp(method) {
334
+ const secret = this.client.getAppSecret();
335
+ if (!secret) {
336
+ throw new Error(`connectors.${method} requires appSecret (sk_live_/sk_test_) in ` +
337
+ 'AgentForgeClient. This surface authenticates AS the App, not via chatToken/apiKey.');
338
+ }
339
+ return { forceApiKey: true, headers: { Authorization: `Bearer ${secret}` } };
239
340
  }
240
341
  // ─── App-user scope (AGF-072, Option A — APP_END_USER_CONNECTIONS_SDD.md §4.4) ──
241
342
  //
@@ -478,6 +579,9 @@ class ConnectorsResource {
478
579
  }
479
580
  }
480
581
  exports.ConnectorsResource = ConnectorsResource;
582
+ function inboxPath(agentId) {
583
+ return `/connectors/inbox/agents/${encodeURIComponent(agentId)}/inbox`;
584
+ }
481
585
  /**
482
586
  * Reads the Google Sheets Picker outcome from the `returnTo` URL the hosted
483
587
  * picker navigated to (`connectors.googleSheetsPicker()`). Accepts the full
@@ -3,6 +3,8 @@ import type { InboxThreadView, InboxMessageView, InboxThreadMode } from '../type
3
3
  export interface ListThreadsOptions {
4
4
  /** Optional filter to threads on a single channel of the agent. */
5
5
  channelId?: string;
6
+ /** Also the history of disconnected channels, marked `channelDisconnected`. */
7
+ includeDisconnected?: boolean;
6
8
  }
7
9
  export interface SendMessageInput {
8
10
  /** The operator's text. */
@@ -71,6 +73,8 @@ export declare class InboxResource {
71
73
  sendMessage: (threadId: string, input: SendMessageInput) => Promise<void>;
72
74
  assign: (threadId: string, input: AssignThreadInput) => Promise<void>;
73
75
  unassign: (threadId: string, input: UnassignThreadInput) => Promise<void>;
76
+ /** Throws `AgentForgeError` with `code` `channel_human_only` (409) when
77
+ * handing back on a channel whose `replyMode` is `human`. */
74
78
  setMode: (threadId: string, input: SetThreadModeInput) => Promise<void>;
75
79
  close: (threadId: string, input?: CloseThreadInput) => Promise<void>;
76
80
  };
@@ -48,9 +48,11 @@ class InboxResource {
48
48
  const base = `/connectors/inbox/agents/${encodeURIComponent(agentId)}/inbox`;
49
49
  return {
50
50
  listThreads: async (opts = {}) => {
51
- const qs = opts.channelId
52
- ? `?channelId=${encodeURIComponent(opts.channelId)}`
53
- : '';
51
+ const params = [
52
+ ...(opts.channelId ? [`channelId=${encodeURIComponent(opts.channelId)}`] : []),
53
+ ...(opts.includeDisconnected ? ['includeDisconnected=true'] : []),
54
+ ];
55
+ const qs = params.length ? `?${params.join('&')}` : '';
54
56
  return this.client.request('GET', `${base}/threads${qs}`);
55
57
  },
56
58
  getThread: async (threadId) => {
@@ -68,6 +70,8 @@ class InboxResource {
68
70
  unassign: async (threadId, input) => {
69
71
  await this.client.request('DELETE', `${base}/threads/${encodeURIComponent(threadId)}/assign`, input);
70
72
  },
73
+ /** Throws `AgentForgeError` with `code` `channel_human_only` (409) when
74
+ * handing back on a channel whose `replyMode` is `human`. */
71
75
  setMode: async (threadId, input) => {
72
76
  await this.client.request('POST', `${base}/threads/${encodeURIComponent(threadId)}/mode`, input);
73
77
  },
package/dist/types.d.ts CHANGED
@@ -555,6 +555,8 @@ export interface InboxThreadView {
555
555
  externalId: string;
556
556
  displayName?: string;
557
557
  mode: InboxThreadMode;
558
+ /** Its channel was disconnected: readable as history, no replies. */
559
+ channelDisconnected?: true;
558
560
  unreadCount: number;
559
561
  lastMessageAt?: string;
560
562
  lastMessagePreview?: string;
@@ -2449,6 +2451,16 @@ export interface DirectOrderForm {
2449
2451
  options: DirectPaymentOption[];
2450
2452
  };
2451
2453
  }
2454
+ /** AGF-CASH-REGISTER — a page of the cases sent between two instants, each with what its receipt says. */
2455
+ export interface CaseReportPage {
2456
+ items: Array<{
2457
+ case: CaseView;
2458
+ receipt: Pick<CaseReceipt, 'lines' | 'totalCents' | 'currency'> | null;
2459
+ }>;
2460
+ /** Pass it back as `cursor`; null: this was the last page. */
2461
+ nextCursor: string | null;
2462
+ timeZone: string;
2463
+ }
2452
2464
  /** AGF-CASH-REGISTER — one payment method in a closing. */
2453
2465
  export interface CaseClosingMethod {
2454
2466
  /** The method's key; null when the payment has no account. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge-io/sdk-server",
3
- "version": "4.51.0",
3
+ "version": "4.53.0",
4
4
  "description": "Server-side SDK for backend apps integrating with AgentForge platform. Auth via ChatToken, ak_live_ API key or App secret (sk_live_), with App installations across tenants.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",