@elmohq/sdk 0.0.0-stage → 0.1.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/LICENSE.md +21 -0
- package/README.md +326 -2
- package/dist/calls/index.d.mts +288 -0
- package/dist/calls/index.d.mts.map +1 -0
- package/dist/calls/index.mjs +390 -0
- package/dist/calls/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1031 -0
- package/dist/index.mjs.map +1 -0
- package/dist/request-options-B9S9d24M.d.mts +1549 -0
- package/dist/request-options-B9S9d24M.d.mts.map +1 -0
- package/dist/tools-7Hs5J2xb.d.mts +1945 -0
- package/dist/tools-7Hs5J2xb.d.mts.map +1 -0
- package/dist/tools-B1lVtYAr.mjs +2459 -0
- package/dist/tools-B1lVtYAr.mjs.map +1 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +68 -4
- package/src/calls/brands-analytics-get.ts +33 -0
- package/src/calls/brands-citations-domains-list.ts +36 -0
- package/src/calls/brands-citations-urls-list.ts +32 -0
- package/src/calls/brands-create.ts +19 -0
- package/src/calls/brands-get.ts +19 -0
- package/src/calls/brands-list.ts +18 -0
- package/src/calls/brands-opportunities-get.ts +42 -0
- package/src/calls/brands-prompt-performance-list.ts +39 -0
- package/src/calls/brands-query-fanout-get.ts +30 -0
- package/src/calls/brands-tags-list.ts +28 -0
- package/src/calls/brands-update.ts +20 -0
- package/src/calls/competitors-create.ts +23 -0
- package/src/calls/competitors-delete.ts +19 -0
- package/src/calls/competitors-get.ts +19 -0
- package/src/calls/competitors-list.ts +23 -0
- package/src/calls/competitors-update.ts +24 -0
- package/src/calls/index.ts +33 -0
- package/src/calls/me-get.ts +18 -0
- package/src/calls/models-list.ts +20 -0
- package/src/calls/organizations-billing-get.ts +37 -0
- package/src/calls/organizations-get.ts +24 -0
- package/src/calls/organizations-list.ts +27 -0
- package/src/calls/prompts-create.ts +27 -0
- package/src/calls/prompts-delete.ts +28 -0
- package/src/calls/prompts-get.ts +23 -0
- package/src/calls/prompts-list.ts +28 -0
- package/src/calls/prompts-runs-get.ts +27 -0
- package/src/calls/prompts-runs-list.ts +30 -0
- package/src/calls/prompts-snapshot-get.ts +28 -0
- package/src/calls/prompts-update.ts +29 -0
- package/src/calls/reports-create.ts +31 -0
- package/src/calls/reports-get.ts +27 -0
- package/src/calls/reports-list.ts +28 -0
- package/src/calls/tools-analyze.ts +26 -0
- package/src/client.ts +649 -0
- package/src/index.ts +21 -0
- package/src/internal/binding/rest/binding.ts +127 -0
- package/src/internal/binding/rest/errors.ts +107 -0
- package/src/internal/binding/rest/path.ts +9 -0
- package/src/internal/binding/rest/url.ts +97 -0
- package/src/internal/codec/json.ts +66 -0
- package/src/internal/codec/registry.ts +55 -0
- package/src/internal/core/backoff.ts +170 -0
- package/src/internal/core/body.ts +54 -0
- package/src/internal/core/browser.ts +11 -0
- package/src/internal/core/call-promise.ts +145 -0
- package/src/internal/core/callable.ts +11 -0
- package/src/internal/core/client.ts +89 -0
- package/src/internal/core/config.ts +84 -0
- package/src/internal/core/credentials.ts +40 -0
- package/src/internal/core/dispatch.ts +225 -0
- package/src/internal/core/env.ts +68 -0
- package/src/internal/core/errors.ts +431 -0
- package/src/internal/core/features.ts +60 -0
- package/src/internal/core/lazy-promise.ts +39 -0
- package/src/internal/core/metadata.ts +79 -0
- package/src/internal/core/page.ts +402 -0
- package/src/internal/core/params.ts +98 -0
- package/src/internal/core/protocol.ts +17 -0
- package/src/internal/core/read-reply.ts +7 -0
- package/src/internal/core/text.ts +7 -0
- package/src/internal/core/types.ts +554 -0
- package/src/internal/feature/auth.ts +201 -0
- package/src/internal/feature/interceptors.ts +36 -0
- package/src/internal/feature/logger.ts +222 -0
- package/src/internal/feature/retry.ts +168 -0
- package/src/internal/feature/rules.ts +54 -0
- package/src/internal/feature/timeout.ts +146 -0
- package/src/internal/feature/validate.ts +82 -0
- package/src/internal/transport/fetch.ts +82 -0
- package/src/resources/analytics.ts +364 -0
- package/src/resources/brands.ts +288 -0
- package/src/resources/competitors.ts +213 -0
- package/src/resources/identity.ts +49 -0
- package/src/resources/models.ts +32 -0
- package/src/resources/opportunities.ts +81 -0
- package/src/resources/organizations.ts +182 -0
- package/src/resources/prompts.ts +293 -0
- package/src/resources/reports.ts +212 -0
- package/src/resources/runs.ts +124 -0
- package/src/resources/shared/auth.ts +13 -0
- package/src/resources/shared/request-options.ts +26 -0
- package/src/resources/shared/resource.ts +23 -0
- package/src/resources/shared/rule.ts +25 -0
- package/src/resources/snapshots.ts +54 -0
- package/src/resources/tags.ts +46 -0
- package/src/resources/tools.ts +69 -0
- package/src/types/analytics.ts +497 -0
- package/src/types/brands.ts +228 -0
- package/src/types/competitors.ts +196 -0
- package/src/types/identity.ts +55 -0
- package/src/types/index.ts +163 -0
- package/src/types/models.ts +40 -0
- package/src/types/opportunities.ts +84 -0
- package/src/types/organizations.ts +157 -0
- package/src/types/prompts.ts +231 -0
- package/src/types/reports.ts +266 -0
- package/src/types/runs.ts +131 -0
- package/src/types/shared/brand-id-path.ts +2 -0
- package/src/types/shared/conflict-error.ts +7 -0
- package/src/types/shared/error.ts +29 -0
- package/src/types/shared/limit.ts +8 -0
- package/src/types/shared/mention-entry.ts +21 -0
- package/src/types/shared/model-filter.ts +15 -0
- package/src/types/shared/not-found-error.ts +4 -0
- package/src/types/shared/page.ts +7 -0
- package/src/types/shared/pagination.ts +7 -0
- package/src/types/shared/validation-error.ts +4 -0
- package/src/types/snapshots.ts +88 -0
- package/src/types/tags.ts +47 -0
- package/src/types/tools.ts +78 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { apiKeyRequirements } from './shared/auth';
|
|
2
|
+
import type { RequestOptions } from './shared/request-options';
|
|
3
|
+
import { ElmoResource } from './shared/resource';
|
|
4
|
+
import { callPromise, RestCallPromise } from '../internal/core/call-promise';
|
|
5
|
+
import { callable } from '../internal/core/callable';
|
|
6
|
+
import { PagePromise, pages } from '../internal/core/page';
|
|
7
|
+
import { groupParams, mergeParams, placeParams } from '../internal/core/params';
|
|
8
|
+
import type { Mutable } from '../internal/feature/validate';
|
|
9
|
+
import { decoded, reviving } from '../internal/feature/validate';
|
|
10
|
+
import type {
|
|
11
|
+
BillingPlan,
|
|
12
|
+
GetOrganizationBillingErrors,
|
|
13
|
+
GetOrganizationBillingResponses,
|
|
14
|
+
GetOrganizationErrors,
|
|
15
|
+
GetOrganizationResponses,
|
|
16
|
+
ListOrganizationsErrors,
|
|
17
|
+
ListOrganizationsParams,
|
|
18
|
+
ListOrganizationsResponses,
|
|
19
|
+
Organization,
|
|
20
|
+
OrganizationBilling,
|
|
21
|
+
OrganizationList,
|
|
22
|
+
PlanLimits,
|
|
23
|
+
} from '../types/organizations';
|
|
24
|
+
|
|
25
|
+
export const getOrganizationBillingFields = { path: ['organizationId'] };
|
|
26
|
+
|
|
27
|
+
function reviveBillingPlan(value: Mutable<BillingPlan>): void {
|
|
28
|
+
if (value.periodEnd != null) {
|
|
29
|
+
value.periodEnd = decoded('BillingPlan.periodEnd', value.periodEnd, (raw) => new Date(raw));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function reviveOrganizationBilling(value: Mutable<OrganizationBilling>): void {
|
|
34
|
+
if (value.plan != null) {
|
|
35
|
+
reviveBillingPlan(value.plan);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const getOrganizationBillingDescriptor = /* @__PURE__ */ callable({
|
|
40
|
+
address: '/organizations/{organizationId}/billing',
|
|
41
|
+
auth: apiKeyRequirements,
|
|
42
|
+
method: 'get',
|
|
43
|
+
returns: 'json',
|
|
44
|
+
validators: { response: /* @__PURE__ */ reviving(reviveOrganizationBilling) },
|
|
45
|
+
} as const);
|
|
46
|
+
|
|
47
|
+
function reviveOrganization(value: Mutable<Organization>): void {
|
|
48
|
+
if (value.createdAt != null) {
|
|
49
|
+
value.createdAt = decoded('Organization.createdAt', value.createdAt, (raw) => new Date(raw));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function reviveOrganizationList(value: Mutable<OrganizationList>): void {
|
|
54
|
+
if (value.data != null) {
|
|
55
|
+
value.data.forEach((item) => {
|
|
56
|
+
reviveOrganization(item);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const listOrganizationsDescriptor = /* @__PURE__ */ callable({
|
|
62
|
+
address: '/organizations',
|
|
63
|
+
auth: apiKeyRequirements,
|
|
64
|
+
method: 'get',
|
|
65
|
+
pagination: {
|
|
66
|
+
items: 'data',
|
|
67
|
+
limitParam: 'limit',
|
|
68
|
+
pages: 'pagination.totalPages',
|
|
69
|
+
param: 'page',
|
|
70
|
+
size: 'pagination.limit',
|
|
71
|
+
style: 'page',
|
|
72
|
+
total: 'pagination.total',
|
|
73
|
+
},
|
|
74
|
+
returns: 'json',
|
|
75
|
+
validators: { response: /* @__PURE__ */ reviving(reviveOrganizationList) },
|
|
76
|
+
} as const);
|
|
77
|
+
|
|
78
|
+
export const getOrganizationFields = { path: ['organizationId'] };
|
|
79
|
+
|
|
80
|
+
export const getOrganizationDescriptor = /* @__PURE__ */ callable({
|
|
81
|
+
address: '/organizations/{organizationId}',
|
|
82
|
+
auth: apiKeyRequirements,
|
|
83
|
+
method: 'get',
|
|
84
|
+
returns: 'json',
|
|
85
|
+
validators: { response: /* @__PURE__ */ reviving(reviveOrganization) },
|
|
86
|
+
} as const);
|
|
87
|
+
|
|
88
|
+
/** Organizations, their plan limits, and their usage */
|
|
89
|
+
export class Billing extends ElmoResource {
|
|
90
|
+
/**
|
|
91
|
+
* Get billing state
|
|
92
|
+
*
|
|
93
|
+
* The organization's plan, its limits, and how much of each limit is already spent — enough for
|
|
94
|
+
* an integration to know a write will be rejected before attempting it.
|
|
95
|
+
*
|
|
96
|
+
* This endpoint is read-only by construction. No API key of any kind can change a subscription,
|
|
97
|
+
* an add-on quantity, or a payment method; there is no billing write endpoint and no billing
|
|
98
|
+
* write scope. Stripe identifiers, invoices, and payment methods are never returned.
|
|
99
|
+
*
|
|
100
|
+
* Deployments without billing answer `200` with `billingEnabled: false`, a null plan, and null
|
|
101
|
+
* limits, so callers need no special case.
|
|
102
|
+
*/
|
|
103
|
+
public get(
|
|
104
|
+
organizationId: string,
|
|
105
|
+
options?: RequestOptions,
|
|
106
|
+
): RestCallPromise<GetOrganizationBillingResponses, GetOrganizationBillingErrors> {
|
|
107
|
+
return callPromise(
|
|
108
|
+
options?.client ?? this.client,
|
|
109
|
+
getOrganizationBillingDescriptor,
|
|
110
|
+
mergeParams(placeParams({ organizationId }, getOrganizationBillingFields, 'query'), options),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Organizations, their plan limits, and their usage */
|
|
116
|
+
export class Organizations extends ElmoResource {
|
|
117
|
+
/**
|
|
118
|
+
* Get an organization
|
|
119
|
+
*
|
|
120
|
+
* No scope required. An organization outside the key's reach answers `404`, identically to one
|
|
121
|
+
* that does not exist.
|
|
122
|
+
*/
|
|
123
|
+
public get(
|
|
124
|
+
organizationId: string,
|
|
125
|
+
options?: RequestOptions,
|
|
126
|
+
): RestCallPromise<GetOrganizationResponses, GetOrganizationErrors> {
|
|
127
|
+
return callPromise(
|
|
128
|
+
options?.client ?? this.client,
|
|
129
|
+
getOrganizationDescriptor,
|
|
130
|
+
mergeParams(placeParams({ organizationId }, getOrganizationFields, 'query'), options),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* One entry for an organization key — the one it acts inside. Every organization for an instance
|
|
136
|
+
* admin key. No scope required: a key can only ever see the organization it is already bound to.
|
|
137
|
+
*/
|
|
138
|
+
public list(
|
|
139
|
+
params?: ListOrganizationsParams,
|
|
140
|
+
options?: RequestOptions,
|
|
141
|
+
): PagePromise<Organization, OrganizationList, ListOrganizationsErrors> {
|
|
142
|
+
return pages(
|
|
143
|
+
options?.client ?? this.client,
|
|
144
|
+
listOrganizationsDescriptor,
|
|
145
|
+
mergeParams(groupParams(params, 'query'), options),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private _billing?: Billing;
|
|
150
|
+
/** Organizations, their plan limits, and their usage */
|
|
151
|
+
get billing(): Billing {
|
|
152
|
+
return (this._billing ??= new Billing(this.client));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export declare namespace Billing {
|
|
157
|
+
export type {
|
|
158
|
+
BillingPlan,
|
|
159
|
+
GetOrganizationBillingErrors,
|
|
160
|
+
GetOrganizationBillingResponses,
|
|
161
|
+
OrganizationBilling,
|
|
162
|
+
PlanLimits,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export declare namespace Organizations {
|
|
167
|
+
export type {
|
|
168
|
+
Billing,
|
|
169
|
+
BillingPlan,
|
|
170
|
+
GetOrganizationBillingErrors,
|
|
171
|
+
GetOrganizationBillingResponses,
|
|
172
|
+
GetOrganizationErrors,
|
|
173
|
+
GetOrganizationResponses,
|
|
174
|
+
ListOrganizationsErrors,
|
|
175
|
+
ListOrganizationsParams,
|
|
176
|
+
ListOrganizationsResponses,
|
|
177
|
+
Organization,
|
|
178
|
+
OrganizationBilling,
|
|
179
|
+
OrganizationList,
|
|
180
|
+
PlanLimits,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Runs } from './runs';
|
|
2
|
+
import { apiKeyRequirements } from './shared/auth';
|
|
3
|
+
import type { RequestOptions } from './shared/request-options';
|
|
4
|
+
import { ElmoResource } from './shared/resource';
|
|
5
|
+
import { valueRule } from './shared/rule';
|
|
6
|
+
import { Snapshot } from './snapshots';
|
|
7
|
+
import { callPromise, RestCallPromise } from '../internal/core/call-promise';
|
|
8
|
+
import { callable } from '../internal/core/callable';
|
|
9
|
+
import { PagePromise, pages } from '../internal/core/page';
|
|
10
|
+
import { groupParams, mergeParams, placeParams } from '../internal/core/params';
|
|
11
|
+
import type { Mutable } from '../internal/feature/validate';
|
|
12
|
+
import { decoded, reviving } from '../internal/feature/validate';
|
|
13
|
+
import type {
|
|
14
|
+
CreatePromptErrors,
|
|
15
|
+
CreatePromptParams,
|
|
16
|
+
CreatePromptResponses,
|
|
17
|
+
DeletePromptErrors,
|
|
18
|
+
DeletePromptResponse,
|
|
19
|
+
DeletePromptResponses,
|
|
20
|
+
GetPromptErrors,
|
|
21
|
+
GetPromptResponses,
|
|
22
|
+
ListPromptsErrors,
|
|
23
|
+
ListPromptsParams,
|
|
24
|
+
ListPromptsResponse,
|
|
25
|
+
ListPromptsResponses,
|
|
26
|
+
Prompt,
|
|
27
|
+
UpdatePromptErrors,
|
|
28
|
+
UpdatePromptParams,
|
|
29
|
+
UpdatePromptResponses,
|
|
30
|
+
} from '../types/prompts';
|
|
31
|
+
import type {
|
|
32
|
+
GetRunErrors,
|
|
33
|
+
GetRunResponses,
|
|
34
|
+
ListPromptRunsErrors,
|
|
35
|
+
ListPromptRunsParams,
|
|
36
|
+
ListPromptRunsResponses,
|
|
37
|
+
Run,
|
|
38
|
+
RunCitation,
|
|
39
|
+
RunList,
|
|
40
|
+
RunSummary,
|
|
41
|
+
} from '../types/runs';
|
|
42
|
+
import type {
|
|
43
|
+
CitedURLEntry,
|
|
44
|
+
GetPromptSnapshotErrors,
|
|
45
|
+
GetPromptSnapshotParams,
|
|
46
|
+
GetPromptSnapshotResponses,
|
|
47
|
+
PromptSnapshot,
|
|
48
|
+
} from '../types/snapshots';
|
|
49
|
+
|
|
50
|
+
function revivePrompt(value: Mutable<Prompt>): void {
|
|
51
|
+
if (value.createdAt != null) {
|
|
52
|
+
value.createdAt = decoded('Prompt.createdAt', value.createdAt, (raw) => new Date(raw));
|
|
53
|
+
}
|
|
54
|
+
if (value.updatedAt != null) {
|
|
55
|
+
value.updatedAt = decoded('Prompt.updatedAt', value.updatedAt, (raw) => new Date(raw));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const listPromptsDescriptor = /* @__PURE__ */ callable({
|
|
60
|
+
address: '/prompts',
|
|
61
|
+
auth: apiKeyRequirements,
|
|
62
|
+
method: 'get',
|
|
63
|
+
pagination: {
|
|
64
|
+
items: 'data',
|
|
65
|
+
limitParam: 'limit',
|
|
66
|
+
pages: 'pagination.totalPages',
|
|
67
|
+
param: 'page',
|
|
68
|
+
size: 'pagination.limit',
|
|
69
|
+
style: 'page',
|
|
70
|
+
total: 'pagination.total',
|
|
71
|
+
},
|
|
72
|
+
returns: 'json',
|
|
73
|
+
validators: {
|
|
74
|
+
response: (data: unknown) => {
|
|
75
|
+
const value = data as ListPromptsResponse;
|
|
76
|
+
if (value == null) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
if (value.data != null) {
|
|
80
|
+
value.data.forEach((item) => {
|
|
81
|
+
revivePrompt(item);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (value.prompts != null) {
|
|
85
|
+
value.prompts.forEach((item) => {
|
|
86
|
+
revivePrompt(item);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
} as const);
|
|
93
|
+
|
|
94
|
+
export const createPromptDescriptor = /* @__PURE__ */ callable({
|
|
95
|
+
address: '/prompts',
|
|
96
|
+
auth: apiKeyRequirements,
|
|
97
|
+
mediaType: 'application/json',
|
|
98
|
+
method: 'post',
|
|
99
|
+
returns: 'json',
|
|
100
|
+
rules: [valueRule],
|
|
101
|
+
validators: { response: /* @__PURE__ */ reviving(revivePrompt) },
|
|
102
|
+
} as const);
|
|
103
|
+
|
|
104
|
+
export const deletePromptFields = { path: ['promptId'] };
|
|
105
|
+
|
|
106
|
+
export const deletePromptDescriptor = /* @__PURE__ */ callable({
|
|
107
|
+
address: '/prompts/{promptId}',
|
|
108
|
+
auth: apiKeyRequirements,
|
|
109
|
+
method: 'delete',
|
|
110
|
+
returns: 'json',
|
|
111
|
+
validators: {
|
|
112
|
+
response: (data: unknown) => {
|
|
113
|
+
const value = data as DeletePromptResponse;
|
|
114
|
+
if (value == null) {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
if (value.createdAt != null) {
|
|
118
|
+
value.createdAt = decoded('createdAt', value.createdAt, (raw) => new Date(raw));
|
|
119
|
+
}
|
|
120
|
+
if (value.updatedAt != null) {
|
|
121
|
+
value.updatedAt = decoded('updatedAt', value.updatedAt, (raw) => new Date(raw));
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
} as const);
|
|
127
|
+
|
|
128
|
+
export const getPromptFields = { path: ['promptId'] };
|
|
129
|
+
|
|
130
|
+
export const getPromptDescriptor = /* @__PURE__ */ callable({
|
|
131
|
+
address: '/prompts/{promptId}',
|
|
132
|
+
auth: apiKeyRequirements,
|
|
133
|
+
method: 'get',
|
|
134
|
+
returns: 'json',
|
|
135
|
+
validators: { response: /* @__PURE__ */ reviving(revivePrompt) },
|
|
136
|
+
} as const);
|
|
137
|
+
|
|
138
|
+
export const updatePromptFields = { path: ['promptId'] };
|
|
139
|
+
|
|
140
|
+
export const updatePromptDescriptor = /* @__PURE__ */ callable({
|
|
141
|
+
address: '/prompts/{promptId}',
|
|
142
|
+
auth: apiKeyRequirements,
|
|
143
|
+
mediaType: 'application/json',
|
|
144
|
+
method: 'patch',
|
|
145
|
+
returns: 'json',
|
|
146
|
+
rules: [valueRule],
|
|
147
|
+
validators: { response: /* @__PURE__ */ reviving(revivePrompt) },
|
|
148
|
+
} as const);
|
|
149
|
+
|
|
150
|
+
/** Manage brand prompts */
|
|
151
|
+
export class Prompts extends ElmoResource {
|
|
152
|
+
/**
|
|
153
|
+
* Create a new prompt
|
|
154
|
+
*
|
|
155
|
+
* Create a new prompt for a brand. This will automatically schedule the prompt for execution.
|
|
156
|
+
*/
|
|
157
|
+
public create(
|
|
158
|
+
params: CreatePromptParams,
|
|
159
|
+
options?: RequestOptions,
|
|
160
|
+
): RestCallPromise<CreatePromptResponses, CreatePromptErrors> {
|
|
161
|
+
return callPromise(
|
|
162
|
+
options?.client ?? this.client,
|
|
163
|
+
createPromptDescriptor,
|
|
164
|
+
mergeParams(groupParams(params, 'body'), options),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Delete a prompt
|
|
170
|
+
*
|
|
171
|
+
* Permanently delete a prompt and cancel all related scheduled jobs. This will also cascade
|
|
172
|
+
* delete all associated prompt runs.
|
|
173
|
+
*
|
|
174
|
+
* Requires an instance admin key; organization keys receive `403`. The dashboard has no delete
|
|
175
|
+
* either — stop tracking a prompt with `prompts.update()` and `enabled: false`, which keeps its
|
|
176
|
+
* history and frees the plan slot.
|
|
177
|
+
*
|
|
178
|
+
* @param promptId The ID of the prompt to delete
|
|
179
|
+
*/
|
|
180
|
+
public delete(
|
|
181
|
+
promptId: string,
|
|
182
|
+
options?: RequestOptions,
|
|
183
|
+
): RestCallPromise<DeletePromptResponses, DeletePromptErrors> {
|
|
184
|
+
return callPromise(
|
|
185
|
+
options?.client ?? this.client,
|
|
186
|
+
deletePromptDescriptor,
|
|
187
|
+
mergeParams(placeParams({ promptId }, deletePromptFields, 'query'), options),
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Get a prompt
|
|
193
|
+
*
|
|
194
|
+
* Retrieve a specific prompt by ID
|
|
195
|
+
*
|
|
196
|
+
* @param promptId The ID of the prompt
|
|
197
|
+
*/
|
|
198
|
+
public get(
|
|
199
|
+
promptId: string,
|
|
200
|
+
options?: RequestOptions,
|
|
201
|
+
): RestCallPromise<GetPromptResponses, GetPromptErrors> {
|
|
202
|
+
return callPromise(
|
|
203
|
+
options?.client ?? this.client,
|
|
204
|
+
getPromptDescriptor,
|
|
205
|
+
mergeParams(placeParams({ promptId }, getPromptFields, 'query'), options),
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* List all prompts
|
|
211
|
+
*
|
|
212
|
+
* Retrieve a paginated list of all prompts across all brands
|
|
213
|
+
*/
|
|
214
|
+
public list(
|
|
215
|
+
params?: ListPromptsParams,
|
|
216
|
+
options?: RequestOptions,
|
|
217
|
+
): PagePromise<Prompt, ListPromptsResponse, ListPromptsErrors> {
|
|
218
|
+
return pages(
|
|
219
|
+
options?.client ?? this.client,
|
|
220
|
+
listPromptsDescriptor,
|
|
221
|
+
mergeParams(groupParams(params, 'query'), options),
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Update a prompt
|
|
227
|
+
*
|
|
228
|
+
* Update a prompt's properties. Only provided fields will be updated. Toggling `enabled`
|
|
229
|
+
* schedules or unschedules the recurring run job.
|
|
230
|
+
*
|
|
231
|
+
* @param promptId The ID of the prompt to update
|
|
232
|
+
*/
|
|
233
|
+
public update(
|
|
234
|
+
promptId: string,
|
|
235
|
+
params: UpdatePromptParams,
|
|
236
|
+
options?: RequestOptions,
|
|
237
|
+
): RestCallPromise<UpdatePromptResponses, UpdatePromptErrors> {
|
|
238
|
+
return callPromise(
|
|
239
|
+
options?.client ?? this.client,
|
|
240
|
+
updatePromptDescriptor,
|
|
241
|
+
mergeParams(placeParams({ ...params, promptId }, updatePromptFields, 'body'), options),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private _runs?: Runs;
|
|
246
|
+
/** Individual model answers behind the aggregates */
|
|
247
|
+
get runs(): Runs {
|
|
248
|
+
return (this._runs ??= new Runs(this.client));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private _snapshot?: Snapshot;
|
|
252
|
+
/** Aggregated analytics snapshots for prompts */
|
|
253
|
+
get snapshot(): Snapshot {
|
|
254
|
+
return (this._snapshot ??= new Snapshot(this.client));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export declare namespace Prompts {
|
|
259
|
+
export type {
|
|
260
|
+
CitedURLEntry,
|
|
261
|
+
CreatePromptErrors,
|
|
262
|
+
CreatePromptParams,
|
|
263
|
+
CreatePromptResponses,
|
|
264
|
+
DeletePromptErrors,
|
|
265
|
+
DeletePromptResponse,
|
|
266
|
+
DeletePromptResponses,
|
|
267
|
+
GetPromptErrors,
|
|
268
|
+
GetPromptResponses,
|
|
269
|
+
GetPromptSnapshotErrors,
|
|
270
|
+
GetPromptSnapshotParams,
|
|
271
|
+
GetPromptSnapshotResponses,
|
|
272
|
+
GetRunErrors,
|
|
273
|
+
GetRunResponses,
|
|
274
|
+
ListPromptRunsErrors,
|
|
275
|
+
ListPromptRunsParams,
|
|
276
|
+
ListPromptRunsResponses,
|
|
277
|
+
ListPromptsErrors,
|
|
278
|
+
ListPromptsParams,
|
|
279
|
+
ListPromptsResponse,
|
|
280
|
+
ListPromptsResponses,
|
|
281
|
+
Prompt,
|
|
282
|
+
PromptSnapshot,
|
|
283
|
+
Run,
|
|
284
|
+
RunCitation,
|
|
285
|
+
RunList,
|
|
286
|
+
Runs,
|
|
287
|
+
RunSummary,
|
|
288
|
+
Snapshot,
|
|
289
|
+
UpdatePromptErrors,
|
|
290
|
+
UpdatePromptParams,
|
|
291
|
+
UpdatePromptResponses,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { apiKeyRequirements } from './shared/auth';
|
|
2
|
+
import type { RequestOptions } from './shared/request-options';
|
|
3
|
+
import { ElmoResource } from './shared/resource';
|
|
4
|
+
import { brandNameRule } from './shared/rule';
|
|
5
|
+
import { callPromise, RestCallPromise } from '../internal/core/call-promise';
|
|
6
|
+
import { callable } from '../internal/core/callable';
|
|
7
|
+
import { PagePromise, pages } from '../internal/core/page';
|
|
8
|
+
import { groupParams, mergeParams, placeParams } from '../internal/core/params';
|
|
9
|
+
import type { Mutable } from '../internal/feature/validate';
|
|
10
|
+
import { decoded } from '../internal/feature/validate';
|
|
11
|
+
import type {
|
|
12
|
+
CreateReportErrors,
|
|
13
|
+
CreateReportParams,
|
|
14
|
+
CreateReportResponse,
|
|
15
|
+
CreateReportResponses,
|
|
16
|
+
GetReportErrors,
|
|
17
|
+
GetReportParams,
|
|
18
|
+
GetReportResponse,
|
|
19
|
+
GetReportResponses,
|
|
20
|
+
ListReportsErrors,
|
|
21
|
+
ListReportsParams,
|
|
22
|
+
ListReportsResponse,
|
|
23
|
+
ListReportsResponses,
|
|
24
|
+
ReportPromptSnapshot,
|
|
25
|
+
ReportSummary,
|
|
26
|
+
} from '../types/reports';
|
|
27
|
+
|
|
28
|
+
function reviveReportSummary(value: Mutable<ReportSummary>): void {
|
|
29
|
+
if (value.createdAt != null) {
|
|
30
|
+
value.createdAt = decoded('ReportSummary.createdAt', value.createdAt, (raw) => new Date(raw));
|
|
31
|
+
}
|
|
32
|
+
if (value.completedAt != null) {
|
|
33
|
+
value.completedAt = decoded(
|
|
34
|
+
'ReportSummary.completedAt',
|
|
35
|
+
value.completedAt,
|
|
36
|
+
(raw) => new Date(raw),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const listReportsDescriptor = /* @__PURE__ */ callable({
|
|
42
|
+
address: '/reports',
|
|
43
|
+
auth: apiKeyRequirements,
|
|
44
|
+
method: 'get',
|
|
45
|
+
pagination: {
|
|
46
|
+
items: 'data',
|
|
47
|
+
limitParam: 'limit',
|
|
48
|
+
pages: 'pagination.totalPages',
|
|
49
|
+
param: 'page',
|
|
50
|
+
size: 'pagination.limit',
|
|
51
|
+
style: 'page',
|
|
52
|
+
total: 'pagination.total',
|
|
53
|
+
},
|
|
54
|
+
returns: 'json',
|
|
55
|
+
validators: {
|
|
56
|
+
response: (data: unknown) => {
|
|
57
|
+
const value = data as ListReportsResponse;
|
|
58
|
+
if (value == null) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
if (value.data != null) {
|
|
62
|
+
value.data.forEach((item) => {
|
|
63
|
+
reviveReportSummary(item);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (value.reports != null) {
|
|
67
|
+
value.reports.forEach((item) => {
|
|
68
|
+
reviveReportSummary(item);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
} as const);
|
|
75
|
+
|
|
76
|
+
export const createReportDescriptor = /* @__PURE__ */ callable({
|
|
77
|
+
address: '/reports',
|
|
78
|
+
auth: apiKeyRequirements,
|
|
79
|
+
mediaType: 'application/json',
|
|
80
|
+
method: 'post',
|
|
81
|
+
returns: 'json',
|
|
82
|
+
rules: [
|
|
83
|
+
brandNameRule,
|
|
84
|
+
{
|
|
85
|
+
max: 10,
|
|
86
|
+
name: 'brandAliases',
|
|
87
|
+
of: 'items',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
min: 1,
|
|
91
|
+
name: 'brandWebsite',
|
|
92
|
+
of: 'characters',
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
validators: {
|
|
96
|
+
response: (data: unknown) => {
|
|
97
|
+
const value = data as CreateReportResponse;
|
|
98
|
+
if (value == null) {
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
if (value.createdAt != null) {
|
|
102
|
+
value.createdAt = decoded('createdAt', value.createdAt, (raw) => new Date(raw));
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
} as const);
|
|
108
|
+
|
|
109
|
+
export const getReportFields = { path: ['reportId'] };
|
|
110
|
+
|
|
111
|
+
export const getReportDescriptor = /* @__PURE__ */ callable({
|
|
112
|
+
address: '/reports/{reportId}',
|
|
113
|
+
auth: apiKeyRequirements,
|
|
114
|
+
method: 'get',
|
|
115
|
+
returns: 'json',
|
|
116
|
+
validators: {
|
|
117
|
+
response: (data: unknown) => {
|
|
118
|
+
const value = data as GetReportResponse;
|
|
119
|
+
if (value == null) {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
if (value.createdAt != null) {
|
|
123
|
+
value.createdAt = decoded('createdAt', value.createdAt, (raw) => new Date(raw));
|
|
124
|
+
}
|
|
125
|
+
if (value.completedAt != null) {
|
|
126
|
+
value.completedAt = decoded('completedAt', value.completedAt, (raw) => new Date(raw));
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
} as const);
|
|
132
|
+
|
|
133
|
+
/** Generate and retrieve AI Share of Voice reports */
|
|
134
|
+
export class Reports extends ElmoResource {
|
|
135
|
+
/**
|
|
136
|
+
* Create a report
|
|
137
|
+
*
|
|
138
|
+
* Create a new AI Share of Voice report and queue it for generation. The report will evaluate the
|
|
139
|
+
* brand across multiple AI engines (ChatGPT, Claude, Google AI) using generated and optional
|
|
140
|
+
* custom prompts.
|
|
141
|
+
*
|
|
142
|
+
* Requires an instance admin key; organization keys receive `403`.
|
|
143
|
+
*/
|
|
144
|
+
public create(
|
|
145
|
+
params: CreateReportParams,
|
|
146
|
+
options?: RequestOptions,
|
|
147
|
+
): RestCallPromise<CreateReportResponses, CreateReportErrors> {
|
|
148
|
+
return callPromise(
|
|
149
|
+
options?.client ?? this.client,
|
|
150
|
+
createReportDescriptor,
|
|
151
|
+
mergeParams(groupParams(params, 'body'), options),
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get report status and data
|
|
157
|
+
*
|
|
158
|
+
* Poll a report's status. When completed, returns per-prompt snapshot data with raw mention
|
|
159
|
+
* counts. Consumers are responsible for computing SoV and other derived metrics from the raw
|
|
160
|
+
* data.
|
|
161
|
+
*
|
|
162
|
+
* Requires an instance admin key; organization keys receive `403`.
|
|
163
|
+
*
|
|
164
|
+
* @param reportId The ID of the report
|
|
165
|
+
*/
|
|
166
|
+
public get(
|
|
167
|
+
reportId: string,
|
|
168
|
+
params?: GetReportParams,
|
|
169
|
+
options?: RequestOptions,
|
|
170
|
+
): RestCallPromise<GetReportResponses, GetReportErrors> {
|
|
171
|
+
return callPromise(
|
|
172
|
+
options?.client ?? this.client,
|
|
173
|
+
getReportDescriptor,
|
|
174
|
+
mergeParams(placeParams({ ...params, reportId }, getReportFields, 'query'), options),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Retrieve a paginated list of all reports, ordered by creation date (newest first).
|
|
180
|
+
*
|
|
181
|
+
* Requires an instance admin key; organization keys receive `403`.
|
|
182
|
+
*/
|
|
183
|
+
public list(
|
|
184
|
+
params?: ListReportsParams,
|
|
185
|
+
options?: RequestOptions,
|
|
186
|
+
): PagePromise<ReportSummary, ListReportsResponse, ListReportsErrors> {
|
|
187
|
+
return pages(
|
|
188
|
+
options?.client ?? this.client,
|
|
189
|
+
listReportsDescriptor,
|
|
190
|
+
mergeParams(groupParams(params, 'query'), options),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export declare namespace Reports {
|
|
196
|
+
export type {
|
|
197
|
+
CreateReportErrors,
|
|
198
|
+
CreateReportParams,
|
|
199
|
+
CreateReportResponse,
|
|
200
|
+
CreateReportResponses,
|
|
201
|
+
GetReportErrors,
|
|
202
|
+
GetReportParams,
|
|
203
|
+
GetReportResponse,
|
|
204
|
+
GetReportResponses,
|
|
205
|
+
ListReportsErrors,
|
|
206
|
+
ListReportsParams,
|
|
207
|
+
ListReportsResponse,
|
|
208
|
+
ListReportsResponses,
|
|
209
|
+
ReportPromptSnapshot,
|
|
210
|
+
ReportSummary,
|
|
211
|
+
};
|
|
212
|
+
}
|