@cadenya/cadenya 0.129.0 → 0.131.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 (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/client.d.mts +17 -0
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +17 -0
  5. package/client.d.ts.map +1 -1
  6. package/client.js +17 -0
  7. package/client.js.map +1 -1
  8. package/client.mjs +17 -0
  9. package/client.mjs.map +1 -1
  10. package/package.json +1 -1
  11. package/resources/api-keys.d.mts +5 -4
  12. package/resources/api-keys.d.mts.map +1 -1
  13. package/resources/api-keys.d.ts +5 -4
  14. package/resources/api-keys.d.ts.map +1 -1
  15. package/resources/index.d.mts +2 -0
  16. package/resources/index.d.mts.map +1 -1
  17. package/resources/index.d.ts +2 -0
  18. package/resources/index.d.ts.map +1 -1
  19. package/resources/index.js +5 -1
  20. package/resources/index.js.map +1 -1
  21. package/resources/index.mjs +2 -0
  22. package/resources/index.mjs.map +1 -1
  23. package/resources/objectives/objectives.d.mts +71 -0
  24. package/resources/objectives/objectives.d.mts.map +1 -1
  25. package/resources/objectives/objectives.d.ts +71 -0
  26. package/resources/objectives/objectives.d.ts.map +1 -1
  27. package/resources/objectives/objectives.js.map +1 -1
  28. package/resources/objectives/objectives.mjs.map +1 -1
  29. package/resources/widget-sessions.d.mts +388 -0
  30. package/resources/widget-sessions.d.mts.map +1 -0
  31. package/resources/widget-sessions.d.ts +388 -0
  32. package/resources/widget-sessions.d.ts.map +1 -0
  33. package/resources/widget-sessions.js +79 -0
  34. package/resources/widget-sessions.js.map +1 -0
  35. package/resources/widget-sessions.mjs +75 -0
  36. package/resources/widget-sessions.mjs.map +1 -0
  37. package/resources/widgets.d.mts +225 -0
  38. package/resources/widgets.d.mts.map +1 -0
  39. package/resources/widgets.d.ts +225 -0
  40. package/resources/widgets.d.ts.map +1 -0
  41. package/resources/widgets.js +83 -0
  42. package/resources/widgets.js.map +1 -0
  43. package/resources/widgets.mjs +79 -0
  44. package/resources/widgets.mjs.map +1 -0
  45. package/src/client.ts +81 -0
  46. package/src/resources/api-keys.ts +5 -4
  47. package/src/resources/index.ts +32 -0
  48. package/src/resources/objectives/objectives.ts +78 -0
  49. package/src/resources/widget-sessions.ts +509 -0
  50. package/src/resources/widgets.ts +317 -0
  51. package/src/version.ts +1 -1
  52. package/version.d.mts +1 -1
  53. package/version.d.ts +1 -1
  54. package/version.js +1 -1
  55. package/version.mjs +1 -1
@@ -0,0 +1,509 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import * as Shared from './shared';
5
+ import { APIPromise } from '../core/api-promise';
6
+ import { CursorPagination, type CursorPaginationParams, PagePromise } from '../core/pagination';
7
+ import { buildHeaders } from '../internal/headers';
8
+ import { RequestOptions } from '../internal/request-options';
9
+ import { path } from '../internal/utils/path';
10
+
11
+ /**
12
+ * Mint and manage widget sessions. Session creation is server-to-server only:
13
+ * the customer's backend authenticates its visitor, asserts tenant/subject
14
+ * context, attaches any per-visitor secrets, and receives a short-lived
15
+ * bearer token the browser uses against the widget host.
16
+ */
17
+ export class WidgetSessions extends APIResource {
18
+ /**
19
+ * Mints a session against a widget and returns the session bearer token
20
+ * (`spec.token`, returned only on creation) plus the authoritative widget hostname
21
+ * (`info.host`). Asserting a tenant upserts the tenant record; attached secrets
22
+ * flow to every conversation the session creates.
23
+ */
24
+ create(params: WidgetSessionCreateParams, options?: RequestOptions): APIPromise<WidgetSession> {
25
+ const { workspaceId = this._client.workspaceID, ...body } = params;
26
+ return this._client.post(path`/v1/workspaces/${workspaceId}/widget_sessions`, { body, ...options });
27
+ }
28
+
29
+ /**
30
+ * Retrieves a widget session. The bearer token is never returned on reads.
31
+ */
32
+ retrieve(
33
+ id: string,
34
+ params: WidgetSessionRetrieveParams | null | undefined = {},
35
+ options?: RequestOptions,
36
+ ): APIPromise<WidgetSession> {
37
+ const { workspaceId = this._client.workspaceID } = params ?? {};
38
+ return this._client.get(path`/v1/workspaces/${workspaceId}/widget_sessions/${id}`, options);
39
+ }
40
+
41
+ /**
42
+ * Lists widget sessions in a workspace, filterable by widget, tenant, subject, and
43
+ * state
44
+ */
45
+ list(
46
+ params: WidgetSessionListParams | null | undefined = {},
47
+ options?: RequestOptions,
48
+ ): PagePromise<WidgetSessionsCursorPagination, WidgetSession> {
49
+ const { workspaceId = this._client.workspaceID, ...query } = params ?? {};
50
+ return this._client.getAPIList(
51
+ path`/v1/workspaces/${workspaceId}/widget_sessions`,
52
+ CursorPagination<WidgetSession>,
53
+ { query, ...options },
54
+ );
55
+ }
56
+
57
+ /**
58
+ * Deletes a session and its secrets. The session's conversations are
59
+ * disassociated, not deleted; use the tenant-level delete for full erasure.
60
+ */
61
+ delete(
62
+ id: string,
63
+ params: WidgetSessionDeleteParams | null | undefined = {},
64
+ options?: RequestOptions,
65
+ ): APIPromise<void> {
66
+ const { workspaceId = this._client.workspaceID } = params ?? {};
67
+ return this._client.delete(path`/v1/workspaces/${workspaceId}/widget_sessions/${id}`, {
68
+ ...options,
69
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Deletes every session belonging to a tenant across all widgets in the workspace,
75
+ * along with the conversations those sessions created — built for GDPR erasure
76
+ * requests. The tenant is required; an empty value is rejected rather than
77
+ * matching everything.
78
+ */
79
+ deleteTenant(
80
+ params: WidgetSessionDeleteTenantParams | null | undefined = {},
81
+ options?: RequestOptions,
82
+ ): APIPromise<WidgetSessionDeleteTenantResponse> {
83
+ const { workspaceId = this._client.workspaceID, tenantId } = params ?? {};
84
+ return this._client.delete(path`/v1/workspaces/${workspaceId}/widget_sessions`, {
85
+ query: { tenantId },
86
+ ...options,
87
+ });
88
+ }
89
+
90
+ /**
91
+ * Transitions a session to STATE_REVOKED. Outstanding tokens stop working
92
+ * immediately, open event streams close within seconds, and the session's secrets
93
+ * are deleted. Terminal.
94
+ */
95
+ revoke(id: string, params: WidgetSessionRevokeParams, options?: RequestOptions): APIPromise<WidgetSession> {
96
+ const { workspaceId = this._client.workspaceID, ...body } = params;
97
+ return this._client.post(path`/v1/workspaces/${workspaceId}/widget_sessions/${id}:revoke`, {
98
+ body,
99
+ ...options,
100
+ });
101
+ }
102
+ }
103
+
104
+ export type WidgetSessionsCursorPagination = CursorPagination<WidgetSession>;
105
+
106
+ /**
107
+ * SubjectAssertion identifies a person within a tenant in the customer's own
108
+ * namespace — typically their user id. Asserting a subject upserts the subject
109
+ * record under the asserted tenant and associates the created resource with it. A
110
+ * subject assertion is only valid alongside a tenant assertion: subject
111
+ * identifiers are scoped to their tenant.
112
+ */
113
+ export interface SubjectAssertion {
114
+ /**
115
+ * The subject identifier in the customer's namespace (e.g. their user id). Stored
116
+ * as the subject record's external_id; unique within the tenant.
117
+ */
118
+ id: string;
119
+
120
+ /**
121
+ * Optional human-readable name for the subject. Updates the subject record's name
122
+ * on every assertion that provides it.
123
+ */
124
+ name?: string;
125
+ }
126
+
127
+ /**
128
+ * SubjectReference is the read-only echo of a resource's subject association,
129
+ * carrying both Cadenya's canonical id and the customer's own key.
130
+ */
131
+ export interface SubjectReference {
132
+ /**
133
+ * Cadenya's canonical subject id.
134
+ */
135
+ id: string;
136
+
137
+ /**
138
+ * The subject identifier in the customer's namespace, as asserted. Unique within
139
+ * the subject's tenant.
140
+ */
141
+ externalId: string;
142
+
143
+ /**
144
+ * Human-readable name of the subject, when one has been asserted.
145
+ */
146
+ name?: string;
147
+ }
148
+
149
+ /**
150
+ * TenantAssertion identifies a tenant in the customer's own namespace — their org,
151
+ * company, or team identifier for an end user. Asserting a tenant upserts the
152
+ * tenant record in the workspace (keyed on `id` as the tenant's external_id) and
153
+ * associates the created resource with it.
154
+ */
155
+ export interface TenantAssertion {
156
+ /**
157
+ * The tenant identifier in the customer's namespace (e.g. "acme-corp"). Stored as
158
+ * the tenant record's external_id; stable across requests.
159
+ */
160
+ id: string;
161
+
162
+ /**
163
+ * Optional human-readable name for the tenant. Updates the tenant record's name on
164
+ * every assertion that provides it.
165
+ */
166
+ name?: string;
167
+ }
168
+
169
+ /**
170
+ * TenantReference is the read-only echo of a resource's tenant association,
171
+ * carrying both Cadenya's canonical id and the customer's own key.
172
+ */
173
+ export interface TenantReference {
174
+ /**
175
+ * Cadenya's canonical tenant id.
176
+ */
177
+ id: string;
178
+
179
+ /**
180
+ * The tenant identifier in the customer's namespace, as asserted.
181
+ */
182
+ externalId: string;
183
+
184
+ /**
185
+ * Human-readable name of the tenant, when one has been asserted.
186
+ */
187
+ name?: string;
188
+ }
189
+
190
+ /**
191
+ * WidgetSession is a delegated, narrowed credential for one visitor's use of a
192
+ * widget, minted server-to-server by the customer's backend. The session carries
193
+ * all customer-asserted context — tenant, subject, labels, secrets — and every
194
+ * conversation (objective) created through the widget inherits it. The bearer
195
+ * token returned at mint is short-lived and refreshed at the widget host; the
196
+ * session row is what makes revocation possible.
197
+ */
198
+ export interface WidgetSession {
199
+ /**
200
+ * Metadata for ephemeral operations and activities (e.g., objectives, executions,
201
+ * runs)
202
+ */
203
+ metadata: Shared.OperationMetadata;
204
+
205
+ /**
206
+ * WidgetSessionSpec is the configuration of a session, fixed at mint.
207
+ */
208
+ spec: WidgetSessionSpec;
209
+
210
+ /**
211
+ * The current lifecycle state of the session. Output only. Sessions are created
212
+ * STATE_ACTIVE; use :revoke to end one early.
213
+ */
214
+ state: 'STATE_UNSPECIFIED' | 'STATE_ACTIVE' | 'STATE_EXPIRED' | 'STATE_REVOKED' | 'STATE_EXHAUSTED';
215
+
216
+ /**
217
+ * WidgetSessionInfo provides read-only server-derived data about a session.
218
+ */
219
+ info?: WidgetSessionInfo;
220
+
221
+ /**
222
+ * Names of the secrets attached to the session. Values are write-only: provided at
223
+ * creation, encrypted at rest, and interpolated into tool-call headers server-side
224
+ * — never returned by any API.
225
+ */
226
+ secrets?: Array<WidgetSession.Secret>;
227
+ }
228
+
229
+ export namespace WidgetSession {
230
+ /**
231
+ * Secret is the name-only echo of a secret attached to the session. Values are
232
+ * never returned.
233
+ */
234
+ export interface Secret {
235
+ name?: string;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * WidgetSessionInfo provides read-only server-derived data about a session.
241
+ */
242
+ export interface WidgetSessionInfo {
243
+ /**
244
+ * BareMetadata contains the minimal metadata for a resource: the ID and an
245
+ * optional human-readable name. These are used for reference fields where the full
246
+ * metadata (account scoping, timestamps, labels, external IDs) is not needed —
247
+ * e.g., the tool references inside an agent variation spec or the tools assigned
248
+ * to an objective. Both fields are server-populated; clients provide IDs through
249
+ * sibling fields rather than by constructing a BareMetadata themselves.
250
+ */
251
+ agent?: Shared.BareMetadata;
252
+
253
+ /**
254
+ * The widget hostname this session's tokens are bound to. Authoritative — clients
255
+ * must use this value rather than constructing the hostname.
256
+ */
257
+ host?: string;
258
+
259
+ /**
260
+ * When the session last created a conversation, sent a message, or refreshed a
261
+ * token.
262
+ */
263
+ lastActiveAt?: string;
264
+
265
+ /**
266
+ * Number of conversation messages created through this session, counted against
267
+ * the session's message cap.
268
+ */
269
+ messageCount?: number;
270
+
271
+ /**
272
+ * SubjectReference is the read-only echo of a resource's subject association,
273
+ * carrying both Cadenya's canonical id and the customer's own key.
274
+ */
275
+ subject?: SubjectReference;
276
+
277
+ /**
278
+ * TenantReference is the read-only echo of a resource's tenant association,
279
+ * carrying both Cadenya's canonical id and the customer's own key.
280
+ */
281
+ tenant?: TenantReference;
282
+
283
+ /**
284
+ * BareMetadata contains the minimal metadata for a resource: the ID and an
285
+ * optional human-readable name. These are used for reference fields where the full
286
+ * metadata (account scoping, timestamps, labels, external IDs) is not needed —
287
+ * e.g., the tool references inside an agent variation spec or the tools assigned
288
+ * to an objective. Both fields are server-populated; clients provide IDs through
289
+ * sibling fields rather than by constructing a BareMetadata themselves.
290
+ */
291
+ widget?: Shared.BareMetadata;
292
+ }
293
+
294
+ /**
295
+ * WidgetSessionSpec is the configuration of a session, fixed at mint.
296
+ */
297
+ export interface WidgetSessionSpec {
298
+ /**
299
+ * Widget this session is minted against. Accepts the canonical `wgt_…` form or the
300
+ * `external_id:<value>` form.
301
+ */
302
+ widgetId: string;
303
+
304
+ /**
305
+ * The session bearer token. Returned only on creation — subsequent reads omit it.
306
+ * The token is short-lived; the widget refreshes it at the widget host without
307
+ * involving the customer's backend.
308
+ */
309
+ token?: string;
310
+
311
+ /**
312
+ * Hard session expiry. Tokens never outlive it; after it passes the session
313
+ * transitions to STATE_EXPIRED. Defaults to a server-chosen horizon when unset.
314
+ */
315
+ expiresAt?: string;
316
+
317
+ /**
318
+ * Parameters forced onto tool calls made by this session's conversations. A pinned
319
+ * parameter is an overlay on a tool's JSON schema: the parameter is removed from
320
+ * what the LLM sees, and its value is always overwritten server-side with the
321
+ * pinned value — so the model cannot be tricked into calling a tool with a
322
+ * different id than the one the session was minted for (e.g. pin "workspaceId" for
323
+ * an OpenAPI tool with a /workspaces/{workspaceId} path). Flows to every objective
324
+ * the session creates.
325
+ */
326
+ pinnedParameters?: { [key: string]: string };
327
+
328
+ /**
329
+ * SubjectAssertion identifies a person within a tenant in the customer's own
330
+ * namespace — typically their user id. Asserting a subject upserts the subject
331
+ * record under the asserted tenant and associates the created resource with it. A
332
+ * subject assertion is only valid alongside a tenant assertion: subject
333
+ * identifiers are scoped to their tenant.
334
+ */
335
+ subject?: SubjectAssertion;
336
+
337
+ /**
338
+ * TenantAssertion identifies a tenant in the customer's own namespace — their org,
339
+ * company, or team identifier for an end user. Asserting a tenant upserts the
340
+ * tenant record in the workspace (keyed on `id` as the tenant's external_id) and
341
+ * associates the created resource with it.
342
+ */
343
+ tenant?: TenantAssertion;
344
+
345
+ /**
346
+ * Expiry of the token returned in `token`. Distinct from `expires_at`, which
347
+ * bounds the session itself.
348
+ */
349
+ tokenExpiresAt?: string;
350
+ }
351
+
352
+ /**
353
+ * Delete tenant widget sessions response.
354
+ */
355
+ export interface WidgetSessionDeleteTenantResponse {
356
+ /**
357
+ * Number of conversations (objectives) deleted along with the sessions.
358
+ */
359
+ objectivesDeleted?: number;
360
+
361
+ /**
362
+ * Number of sessions deleted.
363
+ */
364
+ sessionsDeleted?: number;
365
+ }
366
+
367
+ export interface WidgetSessionCreateParams {
368
+ /**
369
+ * Path param: Workspace ID.
370
+ */
371
+ workspaceId?: string;
372
+
373
+ /**
374
+ * Body param: WidgetSessionSpec is the configuration of a session, fixed at mint.
375
+ */
376
+ spec: WidgetSessionSpec;
377
+
378
+ /**
379
+ * Body param: CreateOperationMetadata contains the user-provided fields for
380
+ * creating an operation. Read-only fields (id, account_id, workspace_id,
381
+ * created_at, profile_id) are excluded since they are set by the server.
382
+ */
383
+ metadata?: Shared.CreateOperationMetadata;
384
+
385
+ /**
386
+ * Body param: Secrets to attach to the session.
387
+ */
388
+ secrets?: Array<WidgetSessionCreateParams.Secret>;
389
+ }
390
+
391
+ export namespace WidgetSessionCreateParams {
392
+ /**
393
+ * Secret is a named credential attached to the session — typically a token the
394
+ * customer's backend minted for the visitor, so the agent acts against their API
395
+ * as that subject. Values are captured at the boundary, encrypted at rest,
396
+ * appended to every conversation the session creates (re-synced on each turn), and
397
+ * never returned by any API. Session secrets take precedence over workspace and
398
+ * tool-set secrets of the same name.
399
+ */
400
+ export interface Secret {
401
+ name?: string;
402
+
403
+ value?: string;
404
+ }
405
+ }
406
+
407
+ export interface WidgetSessionRetrieveParams {
408
+ /**
409
+ * Workspace ID.
410
+ */
411
+ workspaceId?: string;
412
+ }
413
+
414
+ export interface WidgetSessionListParams extends CursorPaginationParams {
415
+ /**
416
+ * Path param: Workspace ID.
417
+ */
418
+ workspaceId?: string;
419
+
420
+ /**
421
+ * Query param: When true, the `info` field on each returned session is populated.
422
+ * Requests with this flag count more against your rate limit.
423
+ */
424
+ includeInfo?: boolean;
425
+
426
+ /**
427
+ * Query param: Filters by metadata labels. Comma-separated key=value pairs, e.g.
428
+ * "env=prod,team=ai". A resource matches only if every pair matches exactly (AND
429
+ * semantics).
430
+ */
431
+ labels?: string;
432
+
433
+ /**
434
+ * Query param: Sort order for results (asc or desc by creation time).
435
+ */
436
+ sortOrder?: string;
437
+
438
+ /**
439
+ * Query param: Filter by state.
440
+ */
441
+ state?: 'STATE_UNSPECIFIED' | 'STATE_ACTIVE' | 'STATE_EXPIRED' | 'STATE_REVOKED' | 'STATE_EXHAUSTED';
442
+
443
+ /**
444
+ * Query param: Filter to sessions asserted for a subject. Accepts the canonical
445
+ * `subj_…` form or the `external_id:<value>` form; the external_id form is scoped
446
+ * within a tenant and requires `tenant_id` to also be set.
447
+ */
448
+ subjectId?: string;
449
+
450
+ /**
451
+ * Query param: Filter to sessions belonging to a tenant. Accepts the canonical
452
+ * `tenant_…` form or the `external_id:<value>` form.
453
+ */
454
+ tenantId?: string;
455
+
456
+ /**
457
+ * Query param: Filter to sessions on a specific widget. Accepts the canonical
458
+ * `wgt_…` form or the `external_id:<value>` form.
459
+ */
460
+ widgetId?: string;
461
+ }
462
+
463
+ export interface WidgetSessionDeleteParams {
464
+ /**
465
+ * Workspace ID.
466
+ */
467
+ workspaceId?: string;
468
+ }
469
+
470
+ export interface WidgetSessionDeleteTenantParams {
471
+ /**
472
+ * Path param: Workspace ID.
473
+ */
474
+ workspaceId?: string;
475
+
476
+ /**
477
+ * Query param: Tenant whose sessions to delete. Required — an empty value is
478
+ * rejected rather than matching everything. Accepts the canonical `tenant_…` form
479
+ * or the `external_id:<value>` form.
480
+ */
481
+ tenantId?: string;
482
+ }
483
+
484
+ export interface WidgetSessionRevokeParams {
485
+ /**
486
+ * Workspace ID.
487
+ */
488
+ workspaceId?: string;
489
+ }
490
+
491
+ export declare namespace WidgetSessions {
492
+ export {
493
+ type SubjectAssertion as SubjectAssertion,
494
+ type SubjectReference as SubjectReference,
495
+ type TenantAssertion as TenantAssertion,
496
+ type TenantReference as TenantReference,
497
+ type WidgetSession as WidgetSession,
498
+ type WidgetSessionInfo as WidgetSessionInfo,
499
+ type WidgetSessionSpec as WidgetSessionSpec,
500
+ type WidgetSessionDeleteTenantResponse as WidgetSessionDeleteTenantResponse,
501
+ type WidgetSessionsCursorPagination as WidgetSessionsCursorPagination,
502
+ type WidgetSessionCreateParams as WidgetSessionCreateParams,
503
+ type WidgetSessionRetrieveParams as WidgetSessionRetrieveParams,
504
+ type WidgetSessionListParams as WidgetSessionListParams,
505
+ type WidgetSessionDeleteParams as WidgetSessionDeleteParams,
506
+ type WidgetSessionDeleteTenantParams as WidgetSessionDeleteTenantParams,
507
+ type WidgetSessionRevokeParams as WidgetSessionRevokeParams,
508
+ };
509
+ }