@cadenya/widgets 1.0.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 (48) hide show
  1. package/README.md +133 -0
  2. package/api.md +66 -0
  3. package/dist/client.d.ts +33 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +49 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/core/error.d.ts +39 -0
  8. package/dist/core/error.d.ts.map +1 -0
  9. package/dist/core/error.js +56 -0
  10. package/dist/core/error.js.map +1 -0
  11. package/dist/core/http.d.ts +140 -0
  12. package/dist/core/http.d.ts.map +1 -0
  13. package/dist/core/http.js +525 -0
  14. package/dist/core/http.js.map +1 -0
  15. package/dist/core/pagination.d.ts +12 -0
  16. package/dist/core/pagination.d.ts.map +1 -0
  17. package/dist/core/pagination.js +29 -0
  18. package/dist/core/pagination.js.map +1 -0
  19. package/dist/core/sse.d.ts +44 -0
  20. package/dist/core/sse.d.ts.map +1 -0
  21. package/dist/core/sse.js +350 -0
  22. package/dist/core/sse.js.map +1 -0
  23. package/dist/index.d.ts +12 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +10 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/resources/config.d.ts +16 -0
  28. package/dist/resources/config.d.ts.map +1 -0
  29. package/dist/resources/config.js +21 -0
  30. package/dist/resources/config.js.map +1 -0
  31. package/dist/resources/conversations.d.ts +173 -0
  32. package/dist/resources/conversations.d.ts.map +1 -0
  33. package/dist/resources/conversations.js +150 -0
  34. package/dist/resources/conversations.js.map +1 -0
  35. package/dist/types.d.ts +461 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +3 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +29 -0
  40. package/src/client.ts +87 -0
  41. package/src/core/error.ts +69 -0
  42. package/src/core/http.ts +639 -0
  43. package/src/core/pagination.ts +27 -0
  44. package/src/core/sse.ts +338 -0
  45. package/src/index.ts +13 -0
  46. package/src/resources/config.ts +22 -0
  47. package/src/resources/conversations.ts +232 -0
  48. package/src/types.ts +512 -0
@@ -0,0 +1,461 @@
1
+ /**
2
+ * Approve tool call request. Responds to a toolApprovalRequested event.
3
+ */
4
+ export interface ApproveToolCallRequest {
5
+ /**
6
+ * Conversation ID.
7
+ */
8
+ id?: string;
9
+ /**
10
+ * The tool call awaiting a decision, from the toolApprovalRequested event.
11
+ */
12
+ toolCallId?: string;
13
+ }
14
+ /**
15
+ * Continue conversation request.
16
+ */
17
+ export interface ContinueConversationRequest {
18
+ /**
19
+ * Conversation ID.
20
+ */
21
+ id?: string;
22
+ /**
23
+ * The visitor's next message.
24
+ */
25
+ message: string;
26
+ }
27
+ /**
28
+ * Create conversation request. The session, tenant, subject, secrets, labels,
29
+ * and pinned parameters all come from the presenting token's session — the
30
+ * browser asserts nothing.
31
+ */
32
+ export interface CreateConversationRequest {
33
+ /**
34
+ * The visitor's opening message.
35
+ */
36
+ message: string;
37
+ }
38
+ /**
39
+ * Deny tool call request. Responds to a toolApprovalRequested event.
40
+ */
41
+ export interface DenyToolCallRequest {
42
+ /**
43
+ * Conversation ID.
44
+ */
45
+ id?: string;
46
+ /**
47
+ * The tool call awaiting a decision, from the toolApprovalRequested event.
48
+ */
49
+ toolCallId?: string;
50
+ }
51
+ /**
52
+ * Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
53
+ */
54
+ export interface GoogleProtobufAny {
55
+ /**
56
+ * The type of the serialized message.
57
+ */
58
+ '@type'?: string;
59
+ }
60
+ /**
61
+ * Represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values.
62
+ */
63
+ export type GoogleProtobufValue = unknown;
64
+ /**
65
+ * List conversation events response. Ordered oldest first.
66
+ */
67
+ export interface ListConversationEventsResponse {
68
+ items?: Array<WidgetEvent>;
69
+ pagination?: Page;
70
+ }
71
+ /**
72
+ * List conversations response. Ordered by last activity, newest first.
73
+ */
74
+ export interface ListConversationsResponse {
75
+ items?: Array<WidgetConversation>;
76
+ pagination?: Page;
77
+ }
78
+ /**
79
+ * Page carries pagination data for list responses. A deliberate local
80
+ * duplicate of the api module's Page — this package imports nothing from
81
+ * cadenya.api.v1 (see the workspace README).
82
+ */
83
+ export interface Page {
84
+ /**
85
+ * Cursor for the next page. Empty when there are no further results.
86
+ */
87
+ nextCursor?: string;
88
+ /**
89
+ * Total number of items matching the request.
90
+ */
91
+ total?: number;
92
+ }
93
+ /**
94
+ * Set tool call content request. Lets the embedding page supply the result
95
+ * of a bare tool call (one whose tool set has no execution adapter) — the
96
+ * widget-session flavor of the reverse-harness pattern, where client-side
97
+ * logic executes the tool and reports the result back. The result then
98
+ * reaches the conversation as a toolResult event.
99
+ */
100
+ export interface SetToolCallContentRequest {
101
+ /**
102
+ * Conversation ID.
103
+ */
104
+ id?: string;
105
+ /**
106
+ * The bare tool call to supply content for.
107
+ */
108
+ toolCallId?: string;
109
+ /**
110
+ * The tool call's result content.
111
+ */
112
+ content: string;
113
+ }
114
+ /**
115
+ * The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).
116
+ */
117
+ export interface Status {
118
+ /**
119
+ * The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
120
+ */
121
+ code?: number;
122
+ /**
123
+ * A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
124
+ */
125
+ message?: string;
126
+ /**
127
+ * A list of messages that carry the error details. There is a common set of message types for APIs to use.
128
+ */
129
+ details?: Array<GoogleProtobufAny>;
130
+ }
131
+ /**
132
+ * Submit conversation feedback request — the visitor's rating of a
133
+ * conversation, mirroring internal objective feedback in slimmed form. Flows
134
+ * into the same feedback machinery that scores agent variations.
135
+ */
136
+ export interface SubmitConversationFeedbackRequest {
137
+ /**
138
+ * Conversation ID.
139
+ */
140
+ id?: string;
141
+ /**
142
+ * A score between -1.0 and 1.0. -1.0 is the worst, 0.0 neutral, 1.0 the
143
+ * best — a thumbs-down/up UI maps to -1.0/1.0.
144
+ */
145
+ score: number;
146
+ /**
147
+ * Optional comment explaining the feedback.
148
+ */
149
+ comment?: string;
150
+ }
151
+ /**
152
+ * WidgetAssistantMessageEvent is a message from the agent. Content may
153
+ * arrive incrementally: later events for the same turn replace earlier
154
+ * partial content.
155
+ */
156
+ export interface WidgetAssistantMessageEvent {
157
+ content: string;
158
+ }
159
+ /**
160
+ * WidgetCancelledEvent: the conversation was cancelled. Terminal.
161
+ */
162
+ export interface WidgetCancelledEvent {
163
+ }
164
+ /**
165
+ * WidgetConfig is the widget's presentation configuration, served to the
166
+ * browser before any session exists. Contains nothing sensitive: the widget
167
+ * is identified by the hostname, and the edge has already enforced the
168
+ * origin allowlist by the time this is served.
169
+ */
170
+ export interface WidgetConfig {
171
+ /**
172
+ * Display name shown in the widget header.
173
+ */
174
+ displayName: string;
175
+ }
176
+ export type WidgetConversationState = 'STATE_UNSPECIFIED' | 'STATE_RESPONDING' | 'STATE_OPEN' | 'STATE_CLOSED';
177
+ /**
178
+ * WidgetConversation is one conversation between the session's visitor and
179
+ * the widget's agent. Conversations are scoped by the presenting token to the
180
+ * VISITOR: a session with a subject sees that subject's conversations on this
181
+ * widget; a session without one sees only the conversations it created
182
+ * itself. A conversation id from outside that scope is indistinguishable from
183
+ * one that does not exist. Tenant is a management-side grouping only — it is
184
+ * never a read scope on this surface.
185
+ */
186
+ export interface WidgetConversation {
187
+ id: string;
188
+ state: WidgetConversationState;
189
+ /**
190
+ * Server-derived display title (e.g. from the opening message).
191
+ */
192
+ title?: string;
193
+ createdAt: string;
194
+ /**
195
+ * When the conversation last saw a message or event.
196
+ */
197
+ lastActiveAt?: string;
198
+ }
199
+ /**
200
+ * WidgetErrorEvent reports a visitor-safe conversation error. The message is
201
+ * sanitized; internal error detail never reaches the widget.
202
+ */
203
+ export interface WidgetErrorEvent {
204
+ message: string;
205
+ }
206
+ /**
207
+ * WidgetEvent is the visitor-facing event vocabulary. It MIRRORS the internal
208
+ * conversation event variants — same granularity, same discriminator names —
209
+ * with slimmed messages holding exactly what a widget UI needs. Internal
210
+ * events map to these through an explicit, exhaustive server-side projection;
211
+ * internal-only types (context compaction, memory reads, sub-agent
212
+ * bookkeeping) have no widget variant and are dropped. Nothing here carries
213
+ * tool configuration, tool arguments, server identities, operator details,
214
+ * or internal error strings.
215
+ */
216
+ export type WidgetEvent = WidgetEvent_UserMessage | WidgetEvent_AssistantMessage | WidgetEvent_ToolApprovalRequested | WidgetEvent_ToolApproved | WidgetEvent_ToolDenied | WidgetEvent_ToolCalled | WidgetEvent_ToolResult | WidgetEvent_ToolError | WidgetEvent_Error | WidgetEvent_Cancelled | WidgetEvent_TimedOut;
217
+ /**
218
+ * WidgetTimedOutEvent: the conversation timed out after inactivity. Terminal.
219
+ * (There is no finalized variant: agents with structured output — the only
220
+ * path to finalization — cannot be bound to widgets.)
221
+ */
222
+ export interface WidgetTimedOutEvent {
223
+ }
224
+ /**
225
+ * WidgetToolApprovalRequestedEvent asks the visitor to approve or deny a
226
+ * tool call before it runs. The tool reference lets the embedding UI render
227
+ * a custom approval experience per tool; the visitor responds via the
228
+ * approve/deny endpoints.
229
+ */
230
+ export interface WidgetToolApprovalRequestedEvent {
231
+ /**
232
+ * The tool call awaiting a decision; pass it to the approve/deny endpoint.
233
+ */
234
+ toolCallId: string;
235
+ tool: WidgetToolReference;
236
+ }
237
+ /**
238
+ * WidgetToolApprovedEvent records that the pending tool call was approved.
239
+ */
240
+ export interface WidgetToolApprovedEvent {
241
+ toolCallId: string;
242
+ }
243
+ /**
244
+ * WidgetToolCalledEvent reports that the agent invoked a tool. Arguments are
245
+ * never included.
246
+ */
247
+ export interface WidgetToolCalledEvent {
248
+ toolCallId: string;
249
+ tool: WidgetToolReference;
250
+ }
251
+ /**
252
+ * WidgetToolDeniedEvent records that the pending tool call was denied.
253
+ */
254
+ export interface WidgetToolDeniedEvent {
255
+ toolCallId: string;
256
+ }
257
+ /**
258
+ * WidgetToolErrorEvent reports that a tool call failed. Internal error
259
+ * detail never reaches the widget.
260
+ */
261
+ export interface WidgetToolErrorEvent {
262
+ toolCallId: string;
263
+ tool: WidgetToolReference;
264
+ }
265
+ /**
266
+ * WidgetToolReference identifies the tool involved in a tool event — enough
267
+ * for the embedding UI to label the activity and to register custom
268
+ * renderers keyed by the tool's id or the customer's own external id.
269
+ * Deliberately omitted: tool configuration, adapter details, and any server
270
+ * identity.
271
+ */
272
+ export interface WidgetToolReference {
273
+ /**
274
+ * Cadenya's canonical tool id.
275
+ */
276
+ id: string;
277
+ /**
278
+ * The tool's external id in the customer's namespace, when set.
279
+ */
280
+ externalId?: string;
281
+ /**
282
+ * The tool's name as the workspace configured it (e.g. "FetchOrderDetails").
283
+ */
284
+ name: string;
285
+ }
286
+ /**
287
+ * WidgetToolResultEvent reports that a tool call finished. Result content is
288
+ * omitted by default and included only for tools the workspace has opted in
289
+ * to sharing content with widget sessions.
290
+ */
291
+ export interface WidgetToolResultEvent {
292
+ toolCallId: string;
293
+ tool: WidgetToolReference;
294
+ /**
295
+ * The tool's result, present only for tools opted in to sharing content
296
+ * with widget sessions (a per-tool setting; default off). Arbitrary JSON
297
+ * the embedding UI may render — chart data, cards, structured results.
298
+ */
299
+ content?: GoogleProtobufValue;
300
+ }
301
+ /**
302
+ * WidgetUserMessageEvent is a message from the visitor.
303
+ */
304
+ export interface WidgetUserMessageEvent {
305
+ content: string;
306
+ }
307
+ export interface WidgetEvent_UserMessage {
308
+ type: 'userMessage';
309
+ userMessage: WidgetUserMessageEvent;
310
+ /**
311
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
312
+ * `Last-Event-ID` on reconnect to resume without duplication.
313
+ */
314
+ id: string;
315
+ /**
316
+ * The conversation this event belongs to.
317
+ */
318
+ conversationId: string;
319
+ createdAt: string;
320
+ }
321
+ export interface WidgetEvent_AssistantMessage {
322
+ type: 'assistantMessage';
323
+ assistantMessage: WidgetAssistantMessageEvent;
324
+ /**
325
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
326
+ * `Last-Event-ID` on reconnect to resume without duplication.
327
+ */
328
+ id: string;
329
+ /**
330
+ * The conversation this event belongs to.
331
+ */
332
+ conversationId: string;
333
+ createdAt: string;
334
+ }
335
+ export interface WidgetEvent_ToolApprovalRequested {
336
+ type: 'toolApprovalRequested';
337
+ toolApprovalRequested: WidgetToolApprovalRequestedEvent;
338
+ /**
339
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
340
+ * `Last-Event-ID` on reconnect to resume without duplication.
341
+ */
342
+ id: string;
343
+ /**
344
+ * The conversation this event belongs to.
345
+ */
346
+ conversationId: string;
347
+ createdAt: string;
348
+ }
349
+ export interface WidgetEvent_ToolApproved {
350
+ type: 'toolApproved';
351
+ toolApproved: WidgetToolApprovedEvent;
352
+ /**
353
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
354
+ * `Last-Event-ID` on reconnect to resume without duplication.
355
+ */
356
+ id: string;
357
+ /**
358
+ * The conversation this event belongs to.
359
+ */
360
+ conversationId: string;
361
+ createdAt: string;
362
+ }
363
+ export interface WidgetEvent_ToolDenied {
364
+ type: 'toolDenied';
365
+ toolDenied: WidgetToolDeniedEvent;
366
+ /**
367
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
368
+ * `Last-Event-ID` on reconnect to resume without duplication.
369
+ */
370
+ id: string;
371
+ /**
372
+ * The conversation this event belongs to.
373
+ */
374
+ conversationId: string;
375
+ createdAt: string;
376
+ }
377
+ export interface WidgetEvent_ToolCalled {
378
+ type: 'toolCalled';
379
+ toolCalled: WidgetToolCalledEvent;
380
+ /**
381
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
382
+ * `Last-Event-ID` on reconnect to resume without duplication.
383
+ */
384
+ id: string;
385
+ /**
386
+ * The conversation this event belongs to.
387
+ */
388
+ conversationId: string;
389
+ createdAt: string;
390
+ }
391
+ export interface WidgetEvent_ToolResult {
392
+ type: 'toolResult';
393
+ toolResult: WidgetToolResultEvent;
394
+ /**
395
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
396
+ * `Last-Event-ID` on reconnect to resume without duplication.
397
+ */
398
+ id: string;
399
+ /**
400
+ * The conversation this event belongs to.
401
+ */
402
+ conversationId: string;
403
+ createdAt: string;
404
+ }
405
+ export interface WidgetEvent_ToolError {
406
+ type: 'toolError';
407
+ toolError: WidgetToolErrorEvent;
408
+ /**
409
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
410
+ * `Last-Event-ID` on reconnect to resume without duplication.
411
+ */
412
+ id: string;
413
+ /**
414
+ * The conversation this event belongs to.
415
+ */
416
+ conversationId: string;
417
+ createdAt: string;
418
+ }
419
+ export interface WidgetEvent_Error {
420
+ type: 'error';
421
+ error: WidgetErrorEvent;
422
+ /**
423
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
424
+ * `Last-Event-ID` on reconnect to resume without duplication.
425
+ */
426
+ id: string;
427
+ /**
428
+ * The conversation this event belongs to.
429
+ */
430
+ conversationId: string;
431
+ createdAt: string;
432
+ }
433
+ export interface WidgetEvent_Cancelled {
434
+ type: 'cancelled';
435
+ cancelled: WidgetCancelledEvent;
436
+ /**
437
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
438
+ * `Last-Event-ID` on reconnect to resume without duplication.
439
+ */
440
+ id: string;
441
+ /**
442
+ * The conversation this event belongs to.
443
+ */
444
+ conversationId: string;
445
+ createdAt: string;
446
+ }
447
+ export interface WidgetEvent_TimedOut {
448
+ type: 'timedOut';
449
+ timedOut: WidgetTimedOutEvent;
450
+ /**
451
+ * Unique event id (ULID). Doubles as the SSE `id:` — replay it as
452
+ * `Last-Event-ID` on reconnect to resume without duplication.
453
+ */
454
+ id: string;
455
+ /**
456
+ * The conversation this event belongs to.
457
+ */
458
+ conversationId: string;
459
+ createdAt: string;
460
+ }
461
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,KAAK,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC3B,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAClC,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACx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OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,oBAAoB,CAAC;IAChC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,gBAAgB,CAAC;IACxB;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,oBAAoB,CAAC;IAChC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ // Generated by redwood. Do not edit by hand.
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,6CAA6C","sourcesContent":["// Generated by redwood. Do not edit by hand.\n\n/**\n * Approve tool call request. Responds to a toolApprovalRequested event.\n */\nexport interface ApproveToolCallRequest {\n /**\n * Conversation ID.\n */\n id?: string;\n /**\n * The tool call awaiting a decision, from the toolApprovalRequested event.\n */\n toolCallId?: string;\n}\n\n/**\n * Continue conversation request.\n */\nexport interface ContinueConversationRequest {\n /**\n * Conversation ID.\n */\n id?: string;\n /**\n * The visitor's next message.\n */\n message: string;\n}\n\n/**\n * Create conversation request. The session, tenant, subject, secrets, labels,\n * and pinned parameters all come from the presenting token's session — the\n * browser asserts nothing.\n */\nexport interface CreateConversationRequest {\n /**\n * The visitor's opening message.\n */\n message: string;\n}\n\n/**\n * Deny tool call request. Responds to a toolApprovalRequested event.\n */\nexport interface DenyToolCallRequest {\n /**\n * Conversation ID.\n */\n id?: string;\n /**\n * The tool call awaiting a decision, from the toolApprovalRequested event.\n */\n toolCallId?: string;\n}\n\n/**\n * Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.\n */\nexport interface GoogleProtobufAny {\n /**\n * The type of the serialized message.\n */\n '@type'?: string;\n}\n\n/**\n * Represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values.\n */\nexport type GoogleProtobufValue = unknown;\n\n/**\n * List conversation events response. Ordered oldest first.\n */\nexport interface ListConversationEventsResponse {\n items?: Array<WidgetEvent>;\n pagination?: Page;\n}\n\n/**\n * List conversations response. Ordered by last activity, newest first.\n */\nexport interface ListConversationsResponse {\n items?: Array<WidgetConversation>;\n pagination?: Page;\n}\n\n/**\n * Page carries pagination data for list responses. A deliberate local\n * duplicate of the api module's Page — this package imports nothing from\n * cadenya.api.v1 (see the workspace README).\n */\nexport interface Page {\n /**\n * Cursor for the next page. Empty when there are no further results.\n */\n nextCursor?: string;\n /**\n * Total number of items matching the request.\n */\n total?: number;\n}\n\n/**\n * Set tool call content request. Lets the embedding page supply the result\n * of a bare tool call (one whose tool set has no execution adapter) — the\n * widget-session flavor of the reverse-harness pattern, where client-side\n * logic executes the tool and reports the result back. The result then\n * reaches the conversation as a toolResult event.\n */\nexport interface SetToolCallContentRequest {\n /**\n * Conversation ID.\n */\n id?: string;\n /**\n * The bare tool call to supply content for.\n */\n toolCallId?: string;\n /**\n * The tool call's result content.\n */\n content: string;\n}\n\n/**\n * The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).\n */\nexport interface Status {\n /**\n * The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].\n */\n code?: number;\n /**\n * A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.\n */\n message?: string;\n /**\n * A list of messages that carry the error details. There is a common set of message types for APIs to use.\n */\n details?: Array<GoogleProtobufAny>;\n}\n\n/**\n * Submit conversation feedback request — the visitor's rating of a\n * conversation, mirroring internal objective feedback in slimmed form. Flows\n * into the same feedback machinery that scores agent variations.\n */\nexport interface SubmitConversationFeedbackRequest {\n /**\n * Conversation ID.\n */\n id?: string;\n /**\n * A score between -1.0 and 1.0. -1.0 is the worst, 0.0 neutral, 1.0 the\n * best — a thumbs-down/up UI maps to -1.0/1.0.\n */\n score: number;\n /**\n * Optional comment explaining the feedback.\n */\n comment?: string;\n}\n\n/**\n * WidgetAssistantMessageEvent is a message from the agent. Content may\n * arrive incrementally: later events for the same turn replace earlier\n * partial content.\n */\nexport interface WidgetAssistantMessageEvent {\n content: string;\n}\n\n/**\n * WidgetCancelledEvent: the conversation was cancelled. Terminal.\n */\nexport interface WidgetCancelledEvent {\n}\n\n/**\n * WidgetConfig is the widget's presentation configuration, served to the\n * browser before any session exists. Contains nothing sensitive: the widget\n * is identified by the hostname, and the edge has already enforced the\n * origin allowlist by the time this is served.\n */\nexport interface WidgetConfig {\n /**\n * Display name shown in the widget header.\n */\n displayName: string;\n}\n\nexport type WidgetConversationState = 'STATE_UNSPECIFIED' | 'STATE_RESPONDING' | 'STATE_OPEN' | 'STATE_CLOSED';\n\n/**\n * WidgetConversation is one conversation between the session's visitor and\n * the widget's agent. Conversations are scoped by the presenting token to the\n * VISITOR: a session with a subject sees that subject's conversations on this\n * widget; a session without one sees only the conversations it created\n * itself. A conversation id from outside that scope is indistinguishable from\n * one that does not exist. Tenant is a management-side grouping only — it is\n * never a read scope on this surface.\n */\nexport interface WidgetConversation {\n id: string;\n state: WidgetConversationState;\n /**\n * Server-derived display title (e.g. from the opening message).\n */\n title?: string;\n createdAt: string;\n /**\n * When the conversation last saw a message or event.\n */\n lastActiveAt?: string;\n}\n\n/**\n * WidgetErrorEvent reports a visitor-safe conversation error. The message is\n * sanitized; internal error detail never reaches the widget.\n */\nexport interface WidgetErrorEvent {\n message: string;\n}\n\n/**\n * WidgetEvent is the visitor-facing event vocabulary. It MIRRORS the internal\n * conversation event variants — same granularity, same discriminator names —\n * with slimmed messages holding exactly what a widget UI needs. Internal\n * events map to these through an explicit, exhaustive server-side projection;\n * internal-only types (context compaction, memory reads, sub-agent\n * bookkeeping) have no widget variant and are dropped. Nothing here carries\n * tool configuration, tool arguments, server identities, operator details,\n * or internal error strings.\n */\nexport type WidgetEvent =\n | WidgetEvent_UserMessage\n | WidgetEvent_AssistantMessage\n | WidgetEvent_ToolApprovalRequested\n | WidgetEvent_ToolApproved\n | WidgetEvent_ToolDenied\n | WidgetEvent_ToolCalled\n | WidgetEvent_ToolResult\n | WidgetEvent_ToolError\n | WidgetEvent_Error\n | WidgetEvent_Cancelled\n | WidgetEvent_TimedOut;\n\n/**\n * WidgetTimedOutEvent: the conversation timed out after inactivity. Terminal.\n * (There is no finalized variant: agents with structured output — the only\n * path to finalization — cannot be bound to widgets.)\n */\nexport interface WidgetTimedOutEvent {\n}\n\n/**\n * WidgetToolApprovalRequestedEvent asks the visitor to approve or deny a\n * tool call before it runs. The tool reference lets the embedding UI render\n * a custom approval experience per tool; the visitor responds via the\n * approve/deny endpoints.\n */\nexport interface WidgetToolApprovalRequestedEvent {\n /**\n * The tool call awaiting a decision; pass it to the approve/deny endpoint.\n */\n toolCallId: string;\n tool: WidgetToolReference;\n}\n\n/**\n * WidgetToolApprovedEvent records that the pending tool call was approved.\n */\nexport interface WidgetToolApprovedEvent {\n toolCallId: string;\n}\n\n/**\n * WidgetToolCalledEvent reports that the agent invoked a tool. Arguments are\n * never included.\n */\nexport interface WidgetToolCalledEvent {\n toolCallId: string;\n tool: WidgetToolReference;\n}\n\n/**\n * WidgetToolDeniedEvent records that the pending tool call was denied.\n */\nexport interface WidgetToolDeniedEvent {\n toolCallId: string;\n}\n\n/**\n * WidgetToolErrorEvent reports that a tool call failed. Internal error\n * detail never reaches the widget.\n */\nexport interface WidgetToolErrorEvent {\n toolCallId: string;\n tool: WidgetToolReference;\n}\n\n/**\n * WidgetToolReference identifies the tool involved in a tool event — enough\n * for the embedding UI to label the activity and to register custom\n * renderers keyed by the tool's id or the customer's own external id.\n * Deliberately omitted: tool configuration, adapter details, and any server\n * identity.\n */\nexport interface WidgetToolReference {\n /**\n * Cadenya's canonical tool id.\n */\n id: string;\n /**\n * The tool's external id in the customer's namespace, when set.\n */\n externalId?: string;\n /**\n * The tool's name as the workspace configured it (e.g. \"FetchOrderDetails\").\n */\n name: string;\n}\n\n/**\n * WidgetToolResultEvent reports that a tool call finished. Result content is\n * omitted by default and included only for tools the workspace has opted in\n * to sharing content with widget sessions.\n */\nexport interface WidgetToolResultEvent {\n toolCallId: string;\n tool: WidgetToolReference;\n /**\n * The tool's result, present only for tools opted in to sharing content\n * with widget sessions (a per-tool setting; default off). Arbitrary JSON\n * the embedding UI may render — chart data, cards, structured results.\n */\n content?: GoogleProtobufValue;\n}\n\n/**\n * WidgetUserMessageEvent is a message from the visitor.\n */\nexport interface WidgetUserMessageEvent {\n content: string;\n}\n\nexport interface WidgetEvent_UserMessage {\n type: 'userMessage';\n userMessage: WidgetUserMessageEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_AssistantMessage {\n type: 'assistantMessage';\n assistantMessage: WidgetAssistantMessageEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_ToolApprovalRequested {\n type: 'toolApprovalRequested';\n toolApprovalRequested: WidgetToolApprovalRequestedEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_ToolApproved {\n type: 'toolApproved';\n toolApproved: WidgetToolApprovedEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_ToolDenied {\n type: 'toolDenied';\n toolDenied: WidgetToolDeniedEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_ToolCalled {\n type: 'toolCalled';\n toolCalled: WidgetToolCalledEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_ToolResult {\n type: 'toolResult';\n toolResult: WidgetToolResultEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_ToolError {\n type: 'toolError';\n toolError: WidgetToolErrorEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_Error {\n type: 'error';\n error: WidgetErrorEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_Cancelled {\n type: 'cancelled';\n cancelled: WidgetCancelledEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\nexport interface WidgetEvent_TimedOut {\n type: 'timedOut';\n timedOut: WidgetTimedOutEvent;\n /**\n * Unique event id (ULID). Doubles as the SSE `id:` — replay it as\n * `Last-Event-ID` on reconnect to resume without duplication.\n */\n id: string;\n /**\n * The conversation this event belongs to.\n */\n conversationId: string;\n createdAt: string;\n}\n\n"]}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@cadenya/widgets",
3
+ "version": "1.0.0",
4
+ "description": "The official TypeScript SDK for the CadenyaWidgets API",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "sideEffects": false,
16
+ "publishConfig": { "access": "public" },
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "files": ["dist", "src", "api.md"],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "dependencies": {},
26
+ "devDependencies": {
27
+ "typescript": "^5.5.0"
28
+ }
29
+ }
package/src/client.ts ADDED
@@ -0,0 +1,87 @@
1
+ // Generated by redwood. Do not edit by hand.
2
+
3
+ import { HttpClient } from './core/http.js';
4
+ import type { Logger, LogLevel } from './core/http.js';
5
+ import { Config } from './resources/config.js';
6
+ import { Conversations } from './resources/conversations.js';
7
+
8
+ export interface ClientOptions {
9
+ /** API key. Defaults to the CADENYAWIDGETS_API_KEY environment variable. */
10
+ apiKey?: string;
11
+ /** Override the API base URL. Defaults to . */
12
+ baseURL?: string;
13
+ /** Max automatic retries for retryable failures. Defaults to 0. */
14
+ maxRetries?: number;
15
+ /**
16
+ * Deadline for ordinary (non-streaming) requests in milliseconds; override
17
+ * per request with `options.timeout`. Streams bound only response-header
18
+ * acquisition — body lifetime stays under the caller's AbortSignal.
19
+ * Defaults to 60000; a non-finite or <= 0 value disables the deadline.
20
+ */
21
+ timeout?: number;
22
+ /** Headers sent with every request. */
23
+ defaultHeaders?: Record<string, string>;
24
+ /** Custom fetch implementation. */
25
+ fetch?: typeof fetch;
26
+ /** Destination for SDK logs. Defaults to `console`. */
27
+ logger?: Logger;
28
+ /** 'debug' | 'warn' (default) | 'off'. Never logs headers or bodies. */
29
+ logLevel?: LogLevel;
30
+ }
31
+
32
+ export class CadenyaWidgets {
33
+ readonly config: Config;
34
+ readonly conversations: Conversations;
35
+
36
+ private readonly _client: HttpClient;
37
+
38
+ constructor(options: ClientOptions = {}) {
39
+ // Presence is not validity: empty strings from options or environment
40
+ // are configuration mistakes, not credentials.
41
+ const apiKey = resolveOption('apiKey', options.apiKey, readEnv('CADENYAWIDGETS_API_KEY'));
42
+ if (!apiKey) {
43
+ throw new Error(
44
+ "Missing API key. Pass it with `new CadenyaWidgets({ apiKey })` or set the CADENYAWIDGETS_API_KEY environment variable.",
45
+ );
46
+ }
47
+ this._client = new HttpClient({
48
+ baseURL: resolveOption('baseURL', options.baseURL, readEnv('CADENYAWIDGETS_BASE_URL')) ?? '',
49
+ authHeader: () => ({ Authorization: `Bearer ${apiKey}` }),
50
+ maxRetries: options.maxRetries ?? 0,
51
+ timeout: options.timeout,
52
+ defaultHeaders: { 'User-Agent': 'cadenyawidgets-typescript/1.0.0 (api 1.0)', ...options.defaultHeaders },
53
+ fetch: options.fetch,
54
+ logger: options.logger,
55
+ logLevel: options.logLevel,
56
+ defaults: { },
57
+ });
58
+ this.config = new Config(this._client);
59
+ this.conversations = new Conversations(this._client);
60
+ }
61
+ }
62
+
63
+ function readEnv(name: string): string | undefined {
64
+ const env = (globalThis as { process?: { env?: Record<string, string | undefined> } })
65
+ .process?.env;
66
+ return env?.[name];
67
+ }
68
+
69
+ // Presence is not validity: an explicitly provided option must be usable —
70
+ // a blank value is a configuration mistake and never silently falls back to
71
+ // the environment or a default. Only an OMITTED option reads the env.
72
+ function resolveOption(
73
+ label: string,
74
+ explicit: string | undefined,
75
+ env: string | undefined,
76
+ ): string | undefined {
77
+ if (explicit !== undefined) {
78
+ const value = explicit.trim();
79
+ if (!value) {
80
+ throw new Error(
81
+ `${label} must not be blank when provided explicitly; omit it to use the environment instead.`,
82
+ );
83
+ }
84
+ return value;
85
+ }
86
+ return env?.trim() || undefined;
87
+ }