@agentforge-io/sdk-server 4.5.3 → 4.6.1
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/client.d.ts +4 -0
- package/dist/client.js +4 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/resources/analytics.d.ts +39 -0
- package/dist/resources/analytics.js +51 -0
- package/dist/resources/apps.d.ts +3 -4
- package/dist/resources/apps.js +3 -4
- package/dist/resources/inbox.d.ts +71 -0
- package/dist/resources/inbox.js +80 -0
- package/dist/types.d.ts +89 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AgentsResource } from './resources/agents';
|
|
2
|
+
import { AnalyticsResource } from './resources/analytics';
|
|
2
3
|
import { AppsResource } from './resources/apps';
|
|
3
4
|
import { ChatResource } from './resources/chat';
|
|
4
5
|
import { ConnectorsResource } from './resources/connectors';
|
|
6
|
+
import { InboxResource } from './resources/inbox';
|
|
5
7
|
import { ProvisioningResource } from './resources/provisioning';
|
|
6
8
|
import { SecretsResource } from './resources/secrets';
|
|
7
9
|
import { ToolsResource } from './resources/tools';
|
|
@@ -58,9 +60,11 @@ export declare class AgentForgeClient {
|
|
|
58
60
|
private readonly fetchImpl;
|
|
59
61
|
private readonly timeoutMs;
|
|
60
62
|
readonly agents: AgentsResource;
|
|
63
|
+
readonly analytics: AnalyticsResource;
|
|
61
64
|
readonly apps: AppsResource;
|
|
62
65
|
readonly chat: ChatResource;
|
|
63
66
|
readonly connectors: ConnectorsResource;
|
|
67
|
+
readonly inbox: InboxResource;
|
|
64
68
|
readonly provisioning: ProvisioningResource;
|
|
65
69
|
readonly secrets: SecretsResource;
|
|
66
70
|
readonly tools: ToolsResource;
|
package/dist/client.js
CHANGED
|
@@ -21,9 +21,11 @@ exports.AgentForgeClient = void 0;
|
|
|
21
21
|
// solo tiene ChatToken. Esas pasan `{ forceApiKey: true }` a `request()`.
|
|
22
22
|
const errors_1 = require("./errors");
|
|
23
23
|
const agents_1 = require("./resources/agents");
|
|
24
|
+
const analytics_1 = require("./resources/analytics");
|
|
24
25
|
const apps_1 = require("./resources/apps");
|
|
25
26
|
const chat_1 = require("./resources/chat");
|
|
26
27
|
const connectors_1 = require("./resources/connectors");
|
|
28
|
+
const inbox_1 = require("./resources/inbox");
|
|
27
29
|
const provisioning_1 = require("./resources/provisioning");
|
|
28
30
|
const secrets_1 = require("./resources/secrets");
|
|
29
31
|
const tools_1 = require("./resources/tools");
|
|
@@ -47,9 +49,11 @@ class AgentForgeClient {
|
|
|
47
49
|
this.fetchImpl = opts.fetch ?? fetch;
|
|
48
50
|
this.timeoutMs = opts.timeoutMs ?? 30000;
|
|
49
51
|
this.agents = new agents_1.AgentsResource(this);
|
|
52
|
+
this.analytics = new analytics_1.AnalyticsResource(this);
|
|
50
53
|
this.apps = new apps_1.AppsResource(this);
|
|
51
54
|
this.chat = new chat_1.ChatResource(this);
|
|
52
55
|
this.connectors = new connectors_1.ConnectorsResource(this);
|
|
56
|
+
this.inbox = new inbox_1.InboxResource(this);
|
|
53
57
|
this.provisioning = new provisioning_1.ProvisioningResource(this);
|
|
54
58
|
this.secrets = new secrets_1.SecretsResource(this);
|
|
55
59
|
this.tools = new tools_1.ToolsResource(this);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,17 @@ export { AgentForgeClient } from './client';
|
|
|
2
2
|
export type { AgentForgeClientOptions, RequestOptions } from './client';
|
|
3
3
|
export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, } from './errors';
|
|
4
4
|
export { TOOL_CALLBACK_HEADERS, ToolCallbackSignatureError, signToolCallbackPayload, verifyToolCallbackSignature, } from './webhooks';
|
|
5
|
-
export type { 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, AppSelf, AppSelfConnector, AppSelfConnectors, AppSelfConnectorTools, AppSelfConnectorToolsResponse, RegisterToolInput, RegisterToolsInput, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, } from './types';
|
|
5
|
+
export type { 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, AppSelf, AppSelfConnector, AppSelfConnectors, AppSelfConnectorTools, AppSelfConnectorToolsResponse, RegisterToolInput, RegisterToolsInput, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
|
|
6
6
|
export { AgentsResource } from './resources/agents';
|
|
7
|
+
export { AnalyticsResource } from './resources/analytics';
|
|
8
|
+
export type { GetSupportKpisInput, GetAgentAttentionLogInput, } from './resources/analytics';
|
|
7
9
|
export { AppsResource } from './resources/apps';
|
|
8
10
|
export { ChatResource } from './resources/chat';
|
|
9
11
|
export type { AnthropicClientOptions, StreamMessageInput } from './resources/chat';
|
|
10
12
|
export { ConnectorsResource } from './resources/connectors';
|
|
11
13
|
export type { InboxChannelView } from './resources/connectors';
|
|
14
|
+
export { InboxResource } from './resources/inbox';
|
|
15
|
+
export type { ListThreadsOptions, SendMessageInput, AssignThreadInput, UnassignThreadInput, SetThreadModeInput, CloseThreadInput, } from './resources/inbox';
|
|
12
16
|
export { ProvisioningResource } from './resources/provisioning';
|
|
13
17
|
export type { ProvisionedTenant, ProvisionedApp, ProvisionedTeam, } from './resources/provisioning';
|
|
14
18
|
export { SecretsResource } from './resources/secrets';
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// const payload = af.tools.verifyCallback({ rawBody, signatureHeader, secretPlaintext });
|
|
29
29
|
// await af.tools.respondToCallback({ resultUrl: payload.resultUrl, tenantId: payload.tenantId, secret, result });
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.ToolsResource = exports.SecretsResource = exports.ProvisioningResource = exports.ConnectorsResource = exports.ChatResource = exports.AppsResource = exports.AgentsResource = exports.verifyToolCallbackSignature = exports.signToolCallbackPayload = exports.ToolCallbackSignatureError = exports.TOOL_CALLBACK_HEADERS = exports.AgentForgeNetworkError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = exports.AgentForgeClient = void 0;
|
|
31
|
+
exports.ToolsResource = exports.SecretsResource = exports.ProvisioningResource = exports.InboxResource = exports.ConnectorsResource = exports.ChatResource = exports.AppsResource = exports.AnalyticsResource = exports.AgentsResource = exports.verifyToolCallbackSignature = exports.signToolCallbackPayload = exports.ToolCallbackSignatureError = exports.TOOL_CALLBACK_HEADERS = exports.AgentForgeNetworkError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = exports.AgentForgeClient = void 0;
|
|
32
32
|
var client_1 = require("./client");
|
|
33
33
|
Object.defineProperty(exports, "AgentForgeClient", { enumerable: true, get: function () { return client_1.AgentForgeClient; } });
|
|
34
34
|
var errors_1 = require("./errors");
|
|
@@ -43,12 +43,16 @@ Object.defineProperty(exports, "signToolCallbackPayload", { enumerable: true, ge
|
|
|
43
43
|
Object.defineProperty(exports, "verifyToolCallbackSignature", { enumerable: true, get: function () { return webhooks_1.verifyToolCallbackSignature; } });
|
|
44
44
|
var agents_1 = require("./resources/agents");
|
|
45
45
|
Object.defineProperty(exports, "AgentsResource", { enumerable: true, get: function () { return agents_1.AgentsResource; } });
|
|
46
|
+
var analytics_1 = require("./resources/analytics");
|
|
47
|
+
Object.defineProperty(exports, "AnalyticsResource", { enumerable: true, get: function () { return analytics_1.AnalyticsResource; } });
|
|
46
48
|
var apps_1 = require("./resources/apps");
|
|
47
49
|
Object.defineProperty(exports, "AppsResource", { enumerable: true, get: function () { return apps_1.AppsResource; } });
|
|
48
50
|
var chat_1 = require("./resources/chat");
|
|
49
51
|
Object.defineProperty(exports, "ChatResource", { enumerable: true, get: function () { return chat_1.ChatResource; } });
|
|
50
52
|
var connectors_1 = require("./resources/connectors");
|
|
51
53
|
Object.defineProperty(exports, "ConnectorsResource", { enumerable: true, get: function () { return connectors_1.ConnectorsResource; } });
|
|
54
|
+
var inbox_1 = require("./resources/inbox");
|
|
55
|
+
Object.defineProperty(exports, "InboxResource", { enumerable: true, get: function () { return inbox_1.InboxResource; } });
|
|
52
56
|
var provisioning_1 = require("./resources/provisioning");
|
|
53
57
|
Object.defineProperty(exports, "ProvisioningResource", { enumerable: true, get: function () { return provisioning_1.ProvisioningResource; } });
|
|
54
58
|
var secrets_1 = require("./resources/secrets");
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AgentForgeClient } from '../client';
|
|
2
|
+
import type { SupportKpiResponse, AgentAttentionLogRow } from '../types';
|
|
3
|
+
export interface GetSupportKpisInput {
|
|
4
|
+
/** Window start (inclusive). ISO 8601 or Date. */
|
|
5
|
+
from: string | Date;
|
|
6
|
+
/** Window end (exclusive). ISO 8601 or Date. */
|
|
7
|
+
to: string | Date;
|
|
8
|
+
agentId?: string;
|
|
9
|
+
operatorUserId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GetAgentAttentionLogInput {
|
|
12
|
+
from: string | Date;
|
|
13
|
+
to: string | Date;
|
|
14
|
+
agentId?: string;
|
|
15
|
+
operatorUserId?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class AnalyticsResource {
|
|
18
|
+
private readonly client;
|
|
19
|
+
constructor(client: AgentForgeClient);
|
|
20
|
+
/**
|
|
21
|
+
* `GET /apps/me/support-kpis` — totals + per-(agent|operator)
|
|
22
|
+
* breakdown for the App's tenant, in the given window.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const { totals, byDimension } = await af.analytics.getSupportKpis({
|
|
26
|
+
* from: '2026-08-01T00:00:00Z',
|
|
27
|
+
* to: '2026-08-08T00:00:00Z',
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
getSupportKpis(input: GetSupportKpisInput): Promise<SupportKpiResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* `GET /apps/me/support-attention-log` — per-day rows for
|
|
33
|
+
* the "atención por agente" table/chart (SD-11).
|
|
34
|
+
*/
|
|
35
|
+
getAgentAttentionLog(input: GetAgentAttentionLogInput): Promise<{
|
|
36
|
+
items: AgentAttentionLogRow[];
|
|
37
|
+
}>;
|
|
38
|
+
private buildQuery;
|
|
39
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// analytics resource (AGF-SD-5) — App-scoped read surface for the support
|
|
3
|
+
// KPIs materialized by SD-3 (`af_support_metrics`). Wraps SD-3b's
|
|
4
|
+
// `AppSupportAnalyticsController` (`GET /apps/me/support-*`), which follows
|
|
5
|
+
// the `me/*` precedent of `AppsController`: the `sk_live_` IS the identity,
|
|
6
|
+
// so there is no `:agentId` in the path and no `tenantId` in the query.
|
|
7
|
+
//
|
|
8
|
+
// Both methods are single-tenant reads: `tenantId` is resolved from the
|
|
9
|
+
// caller's auth context on the server (never from input), so the SDK
|
|
10
|
+
// signature only takes the query knobs. `agentId`/`operatorUserId` are
|
|
11
|
+
// optional filters within that tenant.
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AnalyticsResource = void 0;
|
|
14
|
+
class AnalyticsResource {
|
|
15
|
+
constructor(client) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `GET /apps/me/support-kpis` — totals + per-(agent|operator)
|
|
20
|
+
* breakdown for the App's tenant, in the given window.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const { totals, byDimension } = await af.analytics.getSupportKpis({
|
|
24
|
+
* from: '2026-08-01T00:00:00Z',
|
|
25
|
+
* to: '2026-08-08T00:00:00Z',
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
async getSupportKpis(input) {
|
|
29
|
+
const qs = this.buildQuery(input);
|
|
30
|
+
return this.client.request('GET', `/apps/me/support-kpis?${qs}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `GET /apps/me/support-attention-log` — per-day rows for
|
|
34
|
+
* the "atención por agente" table/chart (SD-11).
|
|
35
|
+
*/
|
|
36
|
+
async getAgentAttentionLog(input) {
|
|
37
|
+
const qs = this.buildQuery(input);
|
|
38
|
+
return this.client.request('GET', `/apps/me/support-attention-log?${qs}`);
|
|
39
|
+
}
|
|
40
|
+
buildQuery(input) {
|
|
41
|
+
const params = new URLSearchParams();
|
|
42
|
+
params.set('from', input.from instanceof Date ? input.from.toISOString() : input.from);
|
|
43
|
+
params.set('to', input.to instanceof Date ? input.to.toISOString() : input.to);
|
|
44
|
+
if (input.agentId)
|
|
45
|
+
params.set('agentId', input.agentId);
|
|
46
|
+
if (input.operatorUserId)
|
|
47
|
+
params.set('operatorUserId', input.operatorUserId);
|
|
48
|
+
return params.toString();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.AnalyticsResource = AnalyticsResource;
|
package/dist/resources/apps.d.ts
CHANGED
|
@@ -48,10 +48,9 @@ export declare class AppsResource {
|
|
|
48
48
|
* per-end-user — that narrowing already happens downstream at runtime
|
|
49
49
|
* via `toolsForAppUser ∩ agent.tools[]`.
|
|
50
50
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* flat, de-duplicated union across every enabled connector.
|
|
51
|
+
* Use it to build a whitelist of tool names an App may reference (e.g.
|
|
52
|
+
* the SOP Architect's bootstrap), so a prompt cannot name a connector
|
|
53
|
+
* tool the App has no connector enabled for.
|
|
55
54
|
*
|
|
56
55
|
* @example
|
|
57
56
|
* const { toolNames } = await af.apps.connectors.tools();
|
package/dist/resources/apps.js
CHANGED
|
@@ -42,10 +42,9 @@ class AppsResource {
|
|
|
42
42
|
* per-end-user — that narrowing already happens downstream at runtime
|
|
43
43
|
* via `toolsForAppUser ∩ agent.tools[]`.
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* flat, de-duplicated union across every enabled connector.
|
|
45
|
+
* Use it to build a whitelist of tool names an App may reference (e.g.
|
|
46
|
+
* the SOP Architect's bootstrap), so a prompt cannot name a connector
|
|
47
|
+
* tool the App has no connector enabled for.
|
|
49
48
|
*
|
|
50
49
|
* @example
|
|
51
50
|
* const { toolNames } = await af.apps.connectors.tools();
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AgentForgeClient } from '../client';
|
|
2
|
+
import type { InboxThreadView, InboxMessageView, InboxThreadMode } from '../types';
|
|
3
|
+
export interface ListThreadsOptions {
|
|
4
|
+
/** Optional filter to threads on a single channel of the agent. */
|
|
5
|
+
channelId?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SendMessageInput {
|
|
8
|
+
/** The operator's text. */
|
|
9
|
+
text: string;
|
|
10
|
+
/** Default true. Toggle off when the operator wants to chime in
|
|
11
|
+
* without taking the thread away from the agent. */
|
|
12
|
+
pauseAgent?: boolean;
|
|
13
|
+
/** App-minted operator identity (see file header). */
|
|
14
|
+
operatorId?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AssignThreadInput {
|
|
17
|
+
/** App-minted operator identity — required for assign. Same string
|
|
18
|
+
* re-sent proves ownership of a prior claim. */
|
|
19
|
+
operatorId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface UnassignThreadInput {
|
|
22
|
+
/** App-minted operator identity — must match the current assignee. */
|
|
23
|
+
operatorId: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SetThreadModeInput {
|
|
26
|
+
mode: InboxThreadMode;
|
|
27
|
+
}
|
|
28
|
+
export interface CloseThreadInput {
|
|
29
|
+
/** Free-text notes the operator leaves on close. Persisted as
|
|
30
|
+
* `af_inbox_threads.close_notes` — later consumed by AGF-BRAIN as
|
|
31
|
+
* institutional knowledge. */
|
|
32
|
+
notes?: string;
|
|
33
|
+
/** App-minted operator identity — recorded on `closed_by_user_id`. */
|
|
34
|
+
operatorId?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Agent-scoped inbox operator surface. Every method takes the `agentId`
|
|
38
|
+
* whose threads the App is operating; the App-ownership boundary is
|
|
39
|
+
* enforced server-side (404 on mismatch, mirroring
|
|
40
|
+
* `assertAgentOwnedByApp` in the identity-side controllers).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const inbox = af.inbox.forAgent(agentId);
|
|
44
|
+
* const { items: threads } = await inbox.listThreads();
|
|
45
|
+
* const { items: messages } = await inbox.listMessages(threads[0].id);
|
|
46
|
+
* await inbox.sendMessage(threads[0].id, {
|
|
47
|
+
* text: 'Hi, jumping in to help',
|
|
48
|
+
* operatorId: 'rep_alice',
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
export declare class InboxResource {
|
|
52
|
+
private readonly client;
|
|
53
|
+
constructor(client: AgentForgeClient);
|
|
54
|
+
/** Bind an agent id and return a helper with one method per
|
|
55
|
+
* `AppInboxController` route. Avoids threading `agentId` through
|
|
56
|
+
* every call. */
|
|
57
|
+
forAgent(agentId: string): {
|
|
58
|
+
listThreads: (opts?: ListThreadsOptions) => Promise<{
|
|
59
|
+
items: InboxThreadView[];
|
|
60
|
+
}>;
|
|
61
|
+
getThread: (threadId: string) => Promise<InboxThreadView>;
|
|
62
|
+
listMessages: (threadId: string) => Promise<{
|
|
63
|
+
items: InboxMessageView[];
|
|
64
|
+
}>;
|
|
65
|
+
sendMessage: (threadId: string, input: SendMessageInput) => Promise<void>;
|
|
66
|
+
assign: (threadId: string, input: AssignThreadInput) => Promise<void>;
|
|
67
|
+
unassign: (threadId: string, input: UnassignThreadInput) => Promise<void>;
|
|
68
|
+
setMode: (threadId: string, input: SetThreadModeInput) => Promise<void>;
|
|
69
|
+
close: (threadId: string, input?: CloseThreadInput) => Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// inbox resource (AGF-SD-5) — App-scoped operator surface. Wraps the
|
|
3
|
+
// platform's `AppInboxController` (AGF-SD-1, `connectors/inbox/agents/:agentId`),
|
|
4
|
+
// exposing list/read/reply/assign/close for the threads of an agent the
|
|
5
|
+
// calling App owns.
|
|
6
|
+
//
|
|
7
|
+
// Auth: `ApiKeyGuard` on the server accepts BOTH `ak_live_` and `sk_live_`.
|
|
8
|
+
// The SDK's `authHeaders()` already sends whichever the client was
|
|
9
|
+
// constructed with on the `Authorization: Bearer` header — no per-call
|
|
10
|
+
// wiring needed here.
|
|
11
|
+
//
|
|
12
|
+
// `operatorId` semantics: SD-1's header comment flags this explicitly — an
|
|
13
|
+
// App has no `af_users.id`, so `operatorId` is whatever stable string the
|
|
14
|
+
// App mints for its own end of the conversation. The SDK exposes it as an
|
|
15
|
+
// optional param on `send()`, `assign()`, `unassign()`, `close()` and
|
|
16
|
+
// passes it through verbatim. The server's assignment guard still enforces
|
|
17
|
+
// "same operatorId re-sent = same claimant".
|
|
18
|
+
//
|
|
19
|
+
// NOTE — chip AGF-INBOX-OPERATORID-UUID: SD-1's free-string `operatorId`
|
|
20
|
+
// collides with UUID columns on assign/close (open follow-up on the
|
|
21
|
+
// platform side). Callers passing arbitrary strings should not be
|
|
22
|
+
// surprised by a 500 today; the shape convergence lands separately.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.InboxResource = void 0;
|
|
25
|
+
/**
|
|
26
|
+
* Agent-scoped inbox operator surface. Every method takes the `agentId`
|
|
27
|
+
* whose threads the App is operating; the App-ownership boundary is
|
|
28
|
+
* enforced server-side (404 on mismatch, mirroring
|
|
29
|
+
* `assertAgentOwnedByApp` in the identity-side controllers).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const inbox = af.inbox.forAgent(agentId);
|
|
33
|
+
* const { items: threads } = await inbox.listThreads();
|
|
34
|
+
* const { items: messages } = await inbox.listMessages(threads[0].id);
|
|
35
|
+
* await inbox.sendMessage(threads[0].id, {
|
|
36
|
+
* text: 'Hi, jumping in to help',
|
|
37
|
+
* operatorId: 'rep_alice',
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
class InboxResource {
|
|
41
|
+
constructor(client) {
|
|
42
|
+
this.client = client;
|
|
43
|
+
}
|
|
44
|
+
/** Bind an agent id and return a helper with one method per
|
|
45
|
+
* `AppInboxController` route. Avoids threading `agentId` through
|
|
46
|
+
* every call. */
|
|
47
|
+
forAgent(agentId) {
|
|
48
|
+
const base = `/connectors/inbox/agents/${encodeURIComponent(agentId)}/inbox`;
|
|
49
|
+
return {
|
|
50
|
+
listThreads: async (opts = {}) => {
|
|
51
|
+
const qs = opts.channelId
|
|
52
|
+
? `?channelId=${encodeURIComponent(opts.channelId)}`
|
|
53
|
+
: '';
|
|
54
|
+
return this.client.request('GET', `${base}/threads${qs}`);
|
|
55
|
+
},
|
|
56
|
+
getThread: async (threadId) => {
|
|
57
|
+
return this.client.request('GET', `${base}/threads/${encodeURIComponent(threadId)}`);
|
|
58
|
+
},
|
|
59
|
+
listMessages: async (threadId) => {
|
|
60
|
+
return this.client.request('GET', `${base}/threads/${encodeURIComponent(threadId)}/messages`);
|
|
61
|
+
},
|
|
62
|
+
sendMessage: async (threadId, input) => {
|
|
63
|
+
await this.client.request('POST', `${base}/threads/${encodeURIComponent(threadId)}/messages`, input);
|
|
64
|
+
},
|
|
65
|
+
assign: async (threadId, input) => {
|
|
66
|
+
await this.client.request('POST', `${base}/threads/${encodeURIComponent(threadId)}/assign`, input);
|
|
67
|
+
},
|
|
68
|
+
unassign: async (threadId, input) => {
|
|
69
|
+
await this.client.request('DELETE', `${base}/threads/${encodeURIComponent(threadId)}/assign`, input);
|
|
70
|
+
},
|
|
71
|
+
setMode: async (threadId, input) => {
|
|
72
|
+
await this.client.request('POST', `${base}/threads/${encodeURIComponent(threadId)}/mode`, input);
|
|
73
|
+
},
|
|
74
|
+
close: async (threadId, input = {}) => {
|
|
75
|
+
await this.client.request('POST', `${base}/threads/${encodeURIComponent(threadId)}/close`, input);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.InboxResource = InboxResource;
|
package/dist/types.d.ts
CHANGED
|
@@ -498,4 +498,93 @@ export interface TenantSecretEntry {
|
|
|
498
498
|
* Ausente si nunca se configuró. */
|
|
499
499
|
updatedAt?: string;
|
|
500
500
|
}
|
|
501
|
+
export type InboxThreadMode = 'agent' | 'human';
|
|
502
|
+
export type InboxMessageDirection = 'inbound' | 'outbound';
|
|
503
|
+
export type InboxMessageSource = 'customer' | 'agent' | 'operator';
|
|
504
|
+
export type InboxMessageType = 'text' | 'image' | 'video' | 'audio' | 'document' | 'sticker' | 'location' | 'unsupported';
|
|
505
|
+
/** Read-through customer profile snapshot embedded on every thread — saves
|
|
506
|
+
* the UI a round-trip per thread. NULL on threads whose customerProfileId
|
|
507
|
+
* hasn't been linked yet (very brief window on first inbound). */
|
|
508
|
+
export interface InboxThreadCustomerProfileView {
|
|
509
|
+
id: string;
|
|
510
|
+
displayName?: string;
|
|
511
|
+
/** Provider handle without the leading `@`. */
|
|
512
|
+
username?: string;
|
|
513
|
+
avatarUrl?: string;
|
|
514
|
+
providerId?: string;
|
|
515
|
+
tags?: string[];
|
|
516
|
+
notes?: string;
|
|
517
|
+
}
|
|
518
|
+
export interface InboxThreadView {
|
|
519
|
+
id: string;
|
|
520
|
+
channelId: string;
|
|
521
|
+
externalId: string;
|
|
522
|
+
displayName?: string;
|
|
523
|
+
mode: InboxThreadMode;
|
|
524
|
+
unreadCount: number;
|
|
525
|
+
lastMessageAt?: string;
|
|
526
|
+
lastMessagePreview?: string;
|
|
527
|
+
/** Workspace user currently responsible for the thread. */
|
|
528
|
+
assignedHumanUserId?: string;
|
|
529
|
+
/** AGF-ASSIGN-P1-CLOSE. ISO timestamp when the human conversation was
|
|
530
|
+
* formally closed. Undefined = open / never escalated. */
|
|
531
|
+
closedAt?: string;
|
|
532
|
+
closeNotes?: string;
|
|
533
|
+
closedByUserId?: string;
|
|
534
|
+
customerProfileId?: string;
|
|
535
|
+
customerProfile?: InboxThreadCustomerProfileView;
|
|
536
|
+
createdAt: string;
|
|
537
|
+
updatedAt: string;
|
|
538
|
+
}
|
|
539
|
+
export interface InboxMessageView {
|
|
540
|
+
id: string;
|
|
541
|
+
threadId: string;
|
|
542
|
+
direction: InboxMessageDirection;
|
|
543
|
+
source: InboxMessageSource;
|
|
544
|
+
type: InboxMessageType;
|
|
545
|
+
body: string;
|
|
546
|
+
externalMessageId?: string;
|
|
547
|
+
payload?: Record<string, unknown>;
|
|
548
|
+
sentAt: string;
|
|
549
|
+
recordedAt: string;
|
|
550
|
+
}
|
|
551
|
+
export interface SupportKpiTotals {
|
|
552
|
+
receivedCount: number;
|
|
553
|
+
aiResponsesCount: number;
|
|
554
|
+
humanMessagesCount: number;
|
|
555
|
+
escalationsCount: number;
|
|
556
|
+
aiResolvedCount: number;
|
|
557
|
+
humanHandledCount: number;
|
|
558
|
+
assignmentsCount: number;
|
|
559
|
+
avgResolutionMs: number | null;
|
|
560
|
+
avgFrtMs: number | null;
|
|
561
|
+
avgTimeToAssignMs: number | null;
|
|
562
|
+
}
|
|
563
|
+
export interface SupportKpiResponse {
|
|
564
|
+
tenantId: string;
|
|
565
|
+
from: string;
|
|
566
|
+
to: string;
|
|
567
|
+
totals: SupportKpiTotals;
|
|
568
|
+
/** One entry per (dimensionType, dimensionKey) in range. */
|
|
569
|
+
byDimension: Array<SupportKpiTotals & {
|
|
570
|
+
dimensionType: 'agent' | 'operator';
|
|
571
|
+
dimensionKey: string;
|
|
572
|
+
}>;
|
|
573
|
+
}
|
|
574
|
+
export interface AgentAttentionLogRow {
|
|
575
|
+
dimensionType: 'agent' | 'operator';
|
|
576
|
+
dimensionKey: string;
|
|
577
|
+
/** YYYY-MM-DD */
|
|
578
|
+
metricDate: string;
|
|
579
|
+
receivedCount: number;
|
|
580
|
+
aiResponsesCount: number;
|
|
581
|
+
humanMessagesCount: number;
|
|
582
|
+
escalationsCount: number;
|
|
583
|
+
aiResolvedCount: number;
|
|
584
|
+
humanHandledCount: number;
|
|
585
|
+
assignmentsCount: number;
|
|
586
|
+
avgResolutionMs: number | null;
|
|
587
|
+
avgFrtMs: number | null;
|
|
588
|
+
avgTimeToAssignMs: number | null;
|
|
589
|
+
}
|
|
501
590
|
export {};
|
package/package.json
CHANGED