@elmohq/sdk 0.0.0-claim → 0.1.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.
Files changed (129) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +325 -2
  3. package/dist/calls/index.d.mts +288 -0
  4. package/dist/calls/index.d.mts.map +1 -0
  5. package/dist/calls/index.mjs +390 -0
  6. package/dist/calls/index.mjs.map +1 -0
  7. package/dist/index.d.mts +2 -0
  8. package/dist/index.mjs +1029 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/request-options-DWYI_Ldj.d.mts +1550 -0
  11. package/dist/request-options-DWYI_Ldj.d.mts.map +1 -0
  12. package/dist/tools-7Hs5J2xb.d.mts +1945 -0
  13. package/dist/tools-7Hs5J2xb.d.mts.map +1 -0
  14. package/dist/tools-SwP0sK8H.mjs +2458 -0
  15. package/dist/tools-SwP0sK8H.mjs.map +1 -0
  16. package/dist/types/index.d.mts +2 -0
  17. package/dist/types/index.mjs +1 -0
  18. package/package.json +59 -2
  19. package/src/calls/brands-analytics-get.ts +33 -0
  20. package/src/calls/brands-citations-domains-list.ts +36 -0
  21. package/src/calls/brands-citations-urls-list.ts +32 -0
  22. package/src/calls/brands-create.ts +19 -0
  23. package/src/calls/brands-get.ts +19 -0
  24. package/src/calls/brands-list.ts +18 -0
  25. package/src/calls/brands-opportunities-get.ts +42 -0
  26. package/src/calls/brands-prompt-performance-list.ts +39 -0
  27. package/src/calls/brands-query-fanout-get.ts +30 -0
  28. package/src/calls/brands-tags-list.ts +28 -0
  29. package/src/calls/brands-update.ts +20 -0
  30. package/src/calls/competitors-create.ts +23 -0
  31. package/src/calls/competitors-delete.ts +19 -0
  32. package/src/calls/competitors-get.ts +19 -0
  33. package/src/calls/competitors-list.ts +23 -0
  34. package/src/calls/competitors-update.ts +24 -0
  35. package/src/calls/index.ts +33 -0
  36. package/src/calls/me-get.ts +18 -0
  37. package/src/calls/models-list.ts +20 -0
  38. package/src/calls/organizations-billing-get.ts +37 -0
  39. package/src/calls/organizations-get.ts +24 -0
  40. package/src/calls/organizations-list.ts +27 -0
  41. package/src/calls/prompts-create.ts +27 -0
  42. package/src/calls/prompts-delete.ts +28 -0
  43. package/src/calls/prompts-get.ts +23 -0
  44. package/src/calls/prompts-list.ts +28 -0
  45. package/src/calls/prompts-runs-get.ts +27 -0
  46. package/src/calls/prompts-runs-list.ts +30 -0
  47. package/src/calls/prompts-snapshot-get.ts +28 -0
  48. package/src/calls/prompts-update.ts +29 -0
  49. package/src/calls/reports-create.ts +31 -0
  50. package/src/calls/reports-get.ts +27 -0
  51. package/src/calls/reports-list.ts +28 -0
  52. package/src/calls/tools-analyze.ts +26 -0
  53. package/src/client.ts +662 -0
  54. package/src/index.ts +21 -0
  55. package/src/internal/binding/rest/binding.ts +127 -0
  56. package/src/internal/binding/rest/errors.ts +107 -0
  57. package/src/internal/binding/rest/path.ts +9 -0
  58. package/src/internal/binding/rest/url.ts +97 -0
  59. package/src/internal/codec/json.ts +66 -0
  60. package/src/internal/codec/registry.ts +55 -0
  61. package/src/internal/core/backoff.ts +170 -0
  62. package/src/internal/core/body.ts +54 -0
  63. package/src/internal/core/browser.ts +11 -0
  64. package/src/internal/core/call-promise.ts +145 -0
  65. package/src/internal/core/callable.ts +11 -0
  66. package/src/internal/core/client.ts +89 -0
  67. package/src/internal/core/config.ts +84 -0
  68. package/src/internal/core/credentials.ts +40 -0
  69. package/src/internal/core/dispatch.ts +227 -0
  70. package/src/internal/core/env.ts +68 -0
  71. package/src/internal/core/errors.ts +431 -0
  72. package/src/internal/core/features.ts +60 -0
  73. package/src/internal/core/lazy-promise.ts +39 -0
  74. package/src/internal/core/metadata.ts +79 -0
  75. package/src/internal/core/params.ts +98 -0
  76. package/src/internal/core/protocol.ts +17 -0
  77. package/src/internal/core/read-reply.ts +7 -0
  78. package/src/internal/core/text.ts +7 -0
  79. package/src/internal/core/types.ts +556 -0
  80. package/src/internal/feature/auth.ts +201 -0
  81. package/src/internal/feature/interceptors.ts +36 -0
  82. package/src/internal/feature/logger.ts +222 -0
  83. package/src/internal/feature/retry.ts +165 -0
  84. package/src/internal/feature/rules.ts +54 -0
  85. package/src/internal/feature/timeout.ts +146 -0
  86. package/src/internal/feature/validate.ts +74 -0
  87. package/src/internal/page/page.ts +402 -0
  88. package/src/internal/transport/fetch.ts +82 -0
  89. package/src/resources/analytics.ts +363 -0
  90. package/src/resources/brands.ts +285 -0
  91. package/src/resources/competitors.ts +212 -0
  92. package/src/resources/identity.ts +48 -0
  93. package/src/resources/models.ts +32 -0
  94. package/src/resources/opportunities.ts +79 -0
  95. package/src/resources/organizations.ts +181 -0
  96. package/src/resources/prompts.ts +292 -0
  97. package/src/resources/reports.ts +211 -0
  98. package/src/resources/runs.ts +123 -0
  99. package/src/resources/shared/auth.ts +13 -0
  100. package/src/resources/shared/request-options.ts +26 -0
  101. package/src/resources/shared/resource.ts +23 -0
  102. package/src/resources/shared/rule.ts +25 -0
  103. package/src/resources/snapshots.ts +54 -0
  104. package/src/resources/tags.ts +46 -0
  105. package/src/resources/tools.ts +68 -0
  106. package/src/types/analytics.ts +497 -0
  107. package/src/types/brands.ts +228 -0
  108. package/src/types/competitors.ts +196 -0
  109. package/src/types/identity.ts +55 -0
  110. package/src/types/index.ts +163 -0
  111. package/src/types/models.ts +40 -0
  112. package/src/types/opportunities.ts +84 -0
  113. package/src/types/organizations.ts +157 -0
  114. package/src/types/prompts.ts +231 -0
  115. package/src/types/reports.ts +266 -0
  116. package/src/types/runs.ts +131 -0
  117. package/src/types/shared/brand-id-path.ts +2 -0
  118. package/src/types/shared/conflict-error.ts +7 -0
  119. package/src/types/shared/error.ts +29 -0
  120. package/src/types/shared/limit.ts +8 -0
  121. package/src/types/shared/mention-entry.ts +21 -0
  122. package/src/types/shared/model-filter.ts +15 -0
  123. package/src/types/shared/not-found-error.ts +4 -0
  124. package/src/types/shared/page.ts +7 -0
  125. package/src/types/shared/pagination.ts +7 -0
  126. package/src/types/shared/validation-error.ts +4 -0
  127. package/src/types/snapshots.ts +88 -0
  128. package/src/types/tags.ts +47 -0
  129. package/src/types/tools.ts +78 -0
@@ -0,0 +1,292 @@
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 { groupParams, mergeParams, placeParams } from '../internal/core/params';
10
+ import { decoded, reviving } from '../internal/feature/validate';
11
+ import { PagePromise, pages } from '../internal/page/page';
12
+ import type {
13
+ CreatePromptErrors,
14
+ CreatePromptParams,
15
+ CreatePromptResponses,
16
+ DeletePromptErrors,
17
+ DeletePromptResponse,
18
+ DeletePromptResponses,
19
+ GetPromptErrors,
20
+ GetPromptResponses,
21
+ ListPromptsErrors,
22
+ ListPromptsParams,
23
+ ListPromptsResponse,
24
+ ListPromptsResponses,
25
+ Prompt,
26
+ UpdatePromptErrors,
27
+ UpdatePromptParams,
28
+ UpdatePromptResponses,
29
+ } from '../types/prompts';
30
+ import type {
31
+ GetRunErrors,
32
+ GetRunResponses,
33
+ ListPromptRunsErrors,
34
+ ListPromptRunsParams,
35
+ ListPromptRunsResponses,
36
+ Run,
37
+ RunCitation,
38
+ RunList,
39
+ RunSummary,
40
+ } from '../types/runs';
41
+ import type {
42
+ CitedURLEntry,
43
+ GetPromptSnapshotErrors,
44
+ GetPromptSnapshotParams,
45
+ GetPromptSnapshotResponses,
46
+ PromptSnapshot,
47
+ } from '../types/snapshots';
48
+
49
+ function revivePrompt(value: Prompt): void {
50
+ if (value.createdAt != null) {
51
+ value.createdAt = decoded('Prompt.createdAt', value.createdAt, (raw) => new Date(raw));
52
+ }
53
+ if (value.updatedAt != null) {
54
+ value.updatedAt = decoded('Prompt.updatedAt', value.updatedAt, (raw) => new Date(raw));
55
+ }
56
+ }
57
+
58
+ export const listPromptsDescriptor = /* @__PURE__ */ callable({
59
+ address: '/prompts',
60
+ auth: apiKeyRequirements,
61
+ method: 'get',
62
+ pagination: {
63
+ items: 'data',
64
+ limitParam: 'limit',
65
+ pages: 'pagination.totalPages',
66
+ param: 'page',
67
+ size: 'pagination.limit',
68
+ style: 'page',
69
+ total: 'pagination.total',
70
+ },
71
+ returns: 'json',
72
+ validators: {
73
+ response: (data: unknown) => {
74
+ const value = data as ListPromptsResponse;
75
+ if (value == null) {
76
+ return value;
77
+ }
78
+ if (value.data != null) {
79
+ value.data.forEach((item) => {
80
+ revivePrompt(item);
81
+ });
82
+ }
83
+ if (value.prompts != null) {
84
+ value.prompts.forEach((item) => {
85
+ revivePrompt(item);
86
+ });
87
+ }
88
+ return value;
89
+ },
90
+ },
91
+ } as const);
92
+
93
+ export const createPromptDescriptor = /* @__PURE__ */ callable({
94
+ address: '/prompts',
95
+ auth: apiKeyRequirements,
96
+ mediaType: 'application/json',
97
+ method: 'post',
98
+ returns: 'json',
99
+ rules: [valueRule],
100
+ validators: { response: /* @__PURE__ */ reviving(revivePrompt) },
101
+ } as const);
102
+
103
+ export const deletePromptFields = { path: ['promptId'] };
104
+
105
+ export const deletePromptDescriptor = /* @__PURE__ */ callable({
106
+ address: '/prompts/{promptId}',
107
+ auth: apiKeyRequirements,
108
+ method: 'delete',
109
+ returns: 'json',
110
+ validators: {
111
+ response: (data: unknown) => {
112
+ const value = data as DeletePromptResponse;
113
+ if (value == null) {
114
+ return value;
115
+ }
116
+ if (value.createdAt != null) {
117
+ value.createdAt = decoded('createdAt', value.createdAt, (raw) => new Date(raw));
118
+ }
119
+ if (value.updatedAt != null) {
120
+ value.updatedAt = decoded('updatedAt', value.updatedAt, (raw) => new Date(raw));
121
+ }
122
+ return value;
123
+ },
124
+ },
125
+ } as const);
126
+
127
+ export const getPromptFields = { path: ['promptId'] };
128
+
129
+ export const getPromptDescriptor = /* @__PURE__ */ callable({
130
+ address: '/prompts/{promptId}',
131
+ auth: apiKeyRequirements,
132
+ method: 'get',
133
+ returns: 'json',
134
+ validators: { response: /* @__PURE__ */ reviving(revivePrompt) },
135
+ } as const);
136
+
137
+ export const updatePromptFields = { path: ['promptId'] };
138
+
139
+ export const updatePromptDescriptor = /* @__PURE__ */ callable({
140
+ address: '/prompts/{promptId}',
141
+ auth: apiKeyRequirements,
142
+ mediaType: 'application/json',
143
+ method: 'patch',
144
+ returns: 'json',
145
+ rules: [valueRule],
146
+ validators: { response: /* @__PURE__ */ reviving(revivePrompt) },
147
+ } as const);
148
+
149
+ /** Manage brand prompts */
150
+ export class Prompts extends ElmoResource {
151
+ /**
152
+ * Create a new prompt
153
+ *
154
+ * Create a new prompt for a brand. This will automatically schedule the prompt for execution.
155
+ */
156
+ public create(
157
+ params: CreatePromptParams,
158
+ options?: RequestOptions,
159
+ ): RestCallPromise<CreatePromptResponses, CreatePromptErrors> {
160
+ return callPromise(
161
+ options?.client ?? this.client,
162
+ createPromptDescriptor,
163
+ mergeParams(groupParams(params, 'body'), options),
164
+ );
165
+ }
166
+
167
+ /**
168
+ * Delete a prompt
169
+ *
170
+ * Permanently delete a prompt and cancel all related scheduled jobs. This will also cascade
171
+ * delete all associated prompt runs.
172
+ *
173
+ * Requires an instance admin key; organization keys receive `403`. The dashboard has no delete
174
+ * either — stop tracking a prompt with `prompts.update()` and `enabled: false`, which keeps its
175
+ * history and frees the plan slot.
176
+ *
177
+ * @param promptId The ID of the prompt to delete
178
+ */
179
+ public delete(
180
+ promptId: string,
181
+ options?: RequestOptions,
182
+ ): RestCallPromise<DeletePromptResponses, DeletePromptErrors> {
183
+ return callPromise(
184
+ options?.client ?? this.client,
185
+ deletePromptDescriptor,
186
+ mergeParams(placeParams({ promptId }, deletePromptFields, 'query'), options),
187
+ );
188
+ }
189
+
190
+ /**
191
+ * Get a prompt
192
+ *
193
+ * Retrieve a specific prompt by ID
194
+ *
195
+ * @param promptId The ID of the prompt
196
+ */
197
+ public get(
198
+ promptId: string,
199
+ options?: RequestOptions,
200
+ ): RestCallPromise<GetPromptResponses, GetPromptErrors> {
201
+ return callPromise(
202
+ options?.client ?? this.client,
203
+ getPromptDescriptor,
204
+ mergeParams(placeParams({ promptId }, getPromptFields, 'query'), options),
205
+ );
206
+ }
207
+
208
+ /**
209
+ * List all prompts
210
+ *
211
+ * Retrieve a paginated list of all prompts across all brands
212
+ */
213
+ public list(
214
+ params?: ListPromptsParams,
215
+ options?: RequestOptions,
216
+ ): PagePromise<Prompt, ListPromptsResponse, ListPromptsErrors> {
217
+ return pages(
218
+ options?.client ?? this.client,
219
+ listPromptsDescriptor,
220
+ mergeParams(groupParams(params, 'query'), options),
221
+ );
222
+ }
223
+
224
+ /**
225
+ * Update a prompt
226
+ *
227
+ * Update a prompt's properties. Only provided fields will be updated. Toggling `enabled`
228
+ * schedules or unschedules the recurring run job.
229
+ *
230
+ * @param promptId The ID of the prompt to update
231
+ */
232
+ public update(
233
+ promptId: string,
234
+ params: UpdatePromptParams,
235
+ options?: RequestOptions,
236
+ ): RestCallPromise<UpdatePromptResponses, UpdatePromptErrors> {
237
+ return callPromise(
238
+ options?.client ?? this.client,
239
+ updatePromptDescriptor,
240
+ mergeParams(placeParams({ ...params, promptId }, updatePromptFields, 'body'), options),
241
+ );
242
+ }
243
+
244
+ private _runs?: Runs;
245
+ /** Individual model answers behind the aggregates */
246
+ get runs(): Runs {
247
+ return (this._runs ??= new Runs(this.client));
248
+ }
249
+
250
+ private _snapshot?: Snapshot;
251
+ /** Aggregated analytics snapshots for prompts */
252
+ get snapshot(): Snapshot {
253
+ return (this._snapshot ??= new Snapshot(this.client));
254
+ }
255
+ }
256
+
257
+ export declare namespace Prompts {
258
+ export type {
259
+ CitedURLEntry,
260
+ CreatePromptErrors,
261
+ CreatePromptParams,
262
+ CreatePromptResponses,
263
+ DeletePromptErrors,
264
+ DeletePromptResponse,
265
+ DeletePromptResponses,
266
+ GetPromptErrors,
267
+ GetPromptResponses,
268
+ GetPromptSnapshotErrors,
269
+ GetPromptSnapshotParams,
270
+ GetPromptSnapshotResponses,
271
+ GetRunErrors,
272
+ GetRunResponses,
273
+ ListPromptRunsErrors,
274
+ ListPromptRunsParams,
275
+ ListPromptRunsResponses,
276
+ ListPromptsErrors,
277
+ ListPromptsParams,
278
+ ListPromptsResponse,
279
+ ListPromptsResponses,
280
+ Prompt,
281
+ PromptSnapshot,
282
+ Run,
283
+ RunCitation,
284
+ RunList,
285
+ Runs,
286
+ RunSummary,
287
+ Snapshot,
288
+ UpdatePromptErrors,
289
+ UpdatePromptParams,
290
+ UpdatePromptResponses,
291
+ };
292
+ }
@@ -0,0 +1,211 @@
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 { groupParams, mergeParams, placeParams } from '../internal/core/params';
8
+ import { decoded } from '../internal/feature/validate';
9
+ import { PagePromise, pages } from '../internal/page/page';
10
+ import type {
11
+ CreateReportErrors,
12
+ CreateReportParams,
13
+ CreateReportResponse,
14
+ CreateReportResponses,
15
+ GetReportErrors,
16
+ GetReportParams,
17
+ GetReportResponse,
18
+ GetReportResponses,
19
+ ListReportsErrors,
20
+ ListReportsParams,
21
+ ListReportsResponse,
22
+ ListReportsResponses,
23
+ ReportPromptSnapshot,
24
+ ReportSummary,
25
+ } from '../types/reports';
26
+
27
+ function reviveReportSummary(value: ReportSummary): void {
28
+ if (value.createdAt != null) {
29
+ value.createdAt = decoded('ReportSummary.createdAt', value.createdAt, (raw) => new Date(raw));
30
+ }
31
+ if (value.completedAt != null) {
32
+ value.completedAt = decoded(
33
+ 'ReportSummary.completedAt',
34
+ value.completedAt,
35
+ (raw) => new Date(raw),
36
+ );
37
+ }
38
+ }
39
+
40
+ export const listReportsDescriptor = /* @__PURE__ */ callable({
41
+ address: '/reports',
42
+ auth: apiKeyRequirements,
43
+ method: 'get',
44
+ pagination: {
45
+ items: 'data',
46
+ limitParam: 'limit',
47
+ pages: 'pagination.totalPages',
48
+ param: 'page',
49
+ size: 'pagination.limit',
50
+ style: 'page',
51
+ total: 'pagination.total',
52
+ },
53
+ returns: 'json',
54
+ validators: {
55
+ response: (data: unknown) => {
56
+ const value = data as ListReportsResponse;
57
+ if (value == null) {
58
+ return value;
59
+ }
60
+ if (value.data != null) {
61
+ value.data.forEach((item) => {
62
+ reviveReportSummary(item);
63
+ });
64
+ }
65
+ if (value.reports != null) {
66
+ value.reports.forEach((item) => {
67
+ reviveReportSummary(item);
68
+ });
69
+ }
70
+ return value;
71
+ },
72
+ },
73
+ } as const);
74
+
75
+ export const createReportDescriptor = /* @__PURE__ */ callable({
76
+ address: '/reports',
77
+ auth: apiKeyRequirements,
78
+ mediaType: 'application/json',
79
+ method: 'post',
80
+ returns: 'json',
81
+ rules: [
82
+ brandNameRule,
83
+ {
84
+ max: 10,
85
+ name: 'brandAliases',
86
+ of: 'items',
87
+ },
88
+ {
89
+ min: 1,
90
+ name: 'brandWebsite',
91
+ of: 'characters',
92
+ },
93
+ ],
94
+ validators: {
95
+ response: (data: unknown) => {
96
+ const value = data as CreateReportResponse;
97
+ if (value == null) {
98
+ return value;
99
+ }
100
+ if (value.createdAt != null) {
101
+ value.createdAt = decoded('createdAt', value.createdAt, (raw) => new Date(raw));
102
+ }
103
+ return value;
104
+ },
105
+ },
106
+ } as const);
107
+
108
+ export const getReportFields = { path: ['reportId'] };
109
+
110
+ export const getReportDescriptor = /* @__PURE__ */ callable({
111
+ address: '/reports/{reportId}',
112
+ auth: apiKeyRequirements,
113
+ method: 'get',
114
+ returns: 'json',
115
+ validators: {
116
+ response: (data: unknown) => {
117
+ const value = data as GetReportResponse;
118
+ if (value == null) {
119
+ return value;
120
+ }
121
+ if (value.createdAt != null) {
122
+ value.createdAt = decoded('createdAt', value.createdAt, (raw) => new Date(raw));
123
+ }
124
+ if (value.completedAt != null) {
125
+ value.completedAt = decoded('completedAt', value.completedAt, (raw) => new Date(raw));
126
+ }
127
+ return value;
128
+ },
129
+ },
130
+ } as const);
131
+
132
+ /** Generate and retrieve AI Share of Voice reports */
133
+ export class Reports extends ElmoResource {
134
+ /**
135
+ * Create a report
136
+ *
137
+ * Create a new AI Share of Voice report and queue it for generation. The report will evaluate the
138
+ * brand across multiple AI engines (ChatGPT, Claude, Google AI) using generated and optional
139
+ * custom prompts.
140
+ *
141
+ * Requires an instance admin key; organization keys receive `403`.
142
+ */
143
+ public create(
144
+ params: CreateReportParams,
145
+ options?: RequestOptions,
146
+ ): RestCallPromise<CreateReportResponses, CreateReportErrors> {
147
+ return callPromise(
148
+ options?.client ?? this.client,
149
+ createReportDescriptor,
150
+ mergeParams(groupParams(params, 'body'), options),
151
+ );
152
+ }
153
+
154
+ /**
155
+ * Get report status and data
156
+ *
157
+ * Poll a report's status. When completed, returns per-prompt snapshot data with raw mention
158
+ * counts. Consumers are responsible for computing SoV and other derived metrics from the raw
159
+ * data.
160
+ *
161
+ * Requires an instance admin key; organization keys receive `403`.
162
+ *
163
+ * @param reportId The ID of the report
164
+ */
165
+ public get(
166
+ reportId: string,
167
+ params?: GetReportParams,
168
+ options?: RequestOptions,
169
+ ): RestCallPromise<GetReportResponses, GetReportErrors> {
170
+ return callPromise(
171
+ options?.client ?? this.client,
172
+ getReportDescriptor,
173
+ mergeParams(placeParams({ ...params, reportId }, getReportFields, 'query'), options),
174
+ );
175
+ }
176
+
177
+ /**
178
+ * Retrieve a paginated list of all reports, ordered by creation date (newest first).
179
+ *
180
+ * Requires an instance admin key; organization keys receive `403`.
181
+ */
182
+ public list(
183
+ params?: ListReportsParams,
184
+ options?: RequestOptions,
185
+ ): PagePromise<ReportSummary, ListReportsResponse, ListReportsErrors> {
186
+ return pages(
187
+ options?.client ?? this.client,
188
+ listReportsDescriptor,
189
+ mergeParams(groupParams(params, 'query'), options),
190
+ );
191
+ }
192
+ }
193
+
194
+ export declare namespace Reports {
195
+ export type {
196
+ CreateReportErrors,
197
+ CreateReportParams,
198
+ CreateReportResponse,
199
+ CreateReportResponses,
200
+ GetReportErrors,
201
+ GetReportParams,
202
+ GetReportResponse,
203
+ GetReportResponses,
204
+ ListReportsErrors,
205
+ ListReportsParams,
206
+ ListReportsResponse,
207
+ ListReportsResponses,
208
+ ReportPromptSnapshot,
209
+ ReportSummary,
210
+ };
211
+ }
@@ -0,0 +1,123 @@
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 { mergeParams, placeParams } from '../internal/core/params';
7
+ import { decoded, reviving } from '../internal/feature/validate';
8
+ import { PagePromise, pages } from '../internal/page/page';
9
+ import type {
10
+ GetRunErrors,
11
+ GetRunResponses,
12
+ ListPromptRunsErrors,
13
+ ListPromptRunsParams,
14
+ ListPromptRunsResponses,
15
+ Run,
16
+ RunCitation,
17
+ RunList,
18
+ RunSummary,
19
+ } from '../types/runs';
20
+
21
+ export const listPromptRunsFields = { path: ['promptId'] };
22
+
23
+ function reviveRunSummary(value: RunSummary): void {
24
+ if (value.createdAt != null) {
25
+ value.createdAt = decoded('RunSummary.createdAt', value.createdAt, (raw) => new Date(raw));
26
+ }
27
+ }
28
+
29
+ function reviveRunList(value: RunList): void {
30
+ if (value.data != null) {
31
+ value.data.forEach((item) => {
32
+ reviveRunSummary(item);
33
+ });
34
+ }
35
+ }
36
+
37
+ export const listPromptRunsDescriptor = /* @__PURE__ */ callable({
38
+ address: '/prompts/{promptId}/runs',
39
+ auth: apiKeyRequirements,
40
+ method: 'get',
41
+ pagination: {
42
+ items: 'data',
43
+ limitParam: 'limit',
44
+ pages: 'pagination.totalPages',
45
+ param: 'page',
46
+ size: 'pagination.limit',
47
+ style: 'page',
48
+ total: 'pagination.total',
49
+ },
50
+ returns: 'json',
51
+ validators: { response: /* @__PURE__ */ reviving(reviveRunList) },
52
+ } as const);
53
+
54
+ export const getRunFields = { path: ['promptId', 'runId'] };
55
+
56
+ function reviveRun(value: Run): void {
57
+ if (value.createdAt != null) {
58
+ value.createdAt = decoded('Run.createdAt', value.createdAt, (raw) => new Date(raw));
59
+ }
60
+ }
61
+
62
+ export const getRunDescriptor = /* @__PURE__ */ callable({
63
+ address: '/prompts/{promptId}/runs/{runId}',
64
+ auth: apiKeyRequirements,
65
+ method: 'get',
66
+ returns: 'json',
67
+ validators: { response: /* @__PURE__ */ reviving(reviveRun) },
68
+ } as const);
69
+
70
+ /** Individual model answers behind the aggregates */
71
+ export class Runs extends ElmoResource {
72
+ /**
73
+ * Get a run
74
+ *
75
+ * One model answer, with its text normalized out of the provider’s response and its citations in
76
+ * the order the engine listed them. A run belonging to some other prompt answers `404`. The
77
+ * provider’s raw payload is deliberately not exposed — its shape belongs to the provider, not to
78
+ * this API.
79
+ */
80
+ public get(
81
+ promptId: string,
82
+ runId: string,
83
+ options?: RequestOptions,
84
+ ): RestCallPromise<GetRunResponses, GetRunErrors> {
85
+ return callPromise(
86
+ options?.client ?? this.client,
87
+ getRunDescriptor,
88
+ mergeParams(placeParams({ promptId, runId }, getRunFields, 'query'), options),
89
+ );
90
+ }
91
+
92
+ /**
93
+ * List runs for a prompt
94
+ *
95
+ * Individual model answers behind the aggregates, newest first, without their text — the list
96
+ * stays small enough to page through. Fetch `prompts.runs.get()` for the answer itself.
97
+ */
98
+ public list(
99
+ promptId: string,
100
+ params: ListPromptRunsParams,
101
+ options?: RequestOptions,
102
+ ): PagePromise<RunSummary, RunList, ListPromptRunsErrors> {
103
+ return pages(
104
+ options?.client ?? this.client,
105
+ listPromptRunsDescriptor,
106
+ mergeParams(placeParams({ ...params, promptId }, listPromptRunsFields, 'query'), options),
107
+ );
108
+ }
109
+ }
110
+
111
+ export declare namespace Runs {
112
+ export type {
113
+ GetRunErrors,
114
+ GetRunResponses,
115
+ ListPromptRunsErrors,
116
+ ListPromptRunsParams,
117
+ ListPromptRunsResponses,
118
+ Run,
119
+ RunCitation,
120
+ RunList,
121
+ RunSummary,
122
+ };
123
+ }
@@ -0,0 +1,13 @@
1
+ import type { AuthScheme } from '../../internal/core/types';
2
+
3
+ /**
4
+ * An instance admin key from `ADMIN_API_KEYS`, or an organization key (`elmo_…`) issued from the
5
+ * dashboard.
6
+ */
7
+ export const apiKeyRequirements = [
8
+ {
9
+ key: 'apiKey',
10
+ scheme: 'bearer',
11
+ type: 'http',
12
+ },
13
+ ] as const satisfies ReadonlyArray<AuthScheme>;
@@ -0,0 +1,26 @@
1
+ import type { BaseURL, BehaviorOptions, ClientCredentials } from '../../client';
2
+ import type { Client } from '../../internal/core/client';
3
+ import type {
4
+ AuthValue,
5
+ BodySerializerOptions,
6
+ ConnectionOptions,
7
+ MetadataOptions,
8
+ PageOptions,
9
+ SignalOptions,
10
+ } from '../../internal/core/types';
11
+
12
+ /** What one call may set for itself, overriding the client it goes through. */
13
+ export type RequestOptions = BehaviorOptions &
14
+ BodySerializerOptions &
15
+ ClientCredentials &
16
+ ConnectionOptions<BaseURL, AuthValue, never> &
17
+ MetadataOptions &
18
+ PageOptions &
19
+ SignalOptions & {
20
+ /**
21
+ * The client that sends this call, in place of the one this SDK uses.
22
+ *
23
+ * Build one with `createElmoClient`.
24
+ */
25
+ client?: Client;
26
+ };
@@ -0,0 +1,23 @@
1
+ import type { ClientOptions } from '../../client';
2
+ import type { Client } from '../../internal/core/client';
3
+ import { clientFor, withClient } from '../../internal/core/client';
4
+
5
+ export class ElmoResource {
6
+ /** The client every call on this SDK dispatches through. */
7
+ readonly client: Client;
8
+
9
+ constructor(client: Client) {
10
+ this.client = client;
11
+ }
12
+
13
+ /**
14
+ * The same calls, with different options.
15
+ *
16
+ * Options given here layer over the ones already in force. Headers, path
17
+ * parameters and query parameters merge per name. Everything else replaces.
18
+ * What this was called on does not change.
19
+ */
20
+ public withOptions(options: ClientOptions): this {
21
+ return withClient(this, clientFor(options, this.client));
22
+ }
23
+ }