modulex-js 0.1.0 → 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.
package/dist/index.d.ts CHANGED
@@ -6,7 +6,12 @@ interface ModulexConfig {
6
6
  apiKey: string;
7
7
  /** Default organization ID for all requests. Can be overridden per-request. */
8
8
  organizationId?: string;
9
- /** Base URL for the ModuleX API. */
9
+ /**
10
+ * Base URL for the ModuleX REST API (the root; routers are mounted at the root
11
+ * with NO version prefix, so do not append `/api` or `/v1`). Defaults to the
12
+ * production host. For local development point this at your dev server,
13
+ * e.g. `http://localhost:8000`.
14
+ */
10
15
  baseUrl?: string;
11
16
  /** Request timeout in milliseconds. */
12
17
  timeout?: number;
@@ -27,8 +32,19 @@ interface ResolvedConfig {
27
32
 
28
33
  /** A parsed SSE event. */
29
34
  interface SSEEvent {
30
- /** Event type (e.g., "node_update", "done", "error"). */
35
+ /**
36
+ * The raw SSE `event:` field, or "message" when the frame has no `event:` line.
37
+ * NOTE: most ModuleX streams (workflows, composer, assistant, credentials) emit
38
+ * data-only frames, so `event` is "message" for them — prefer {@link SSEEvent.type}
39
+ * for discriminating. The chats stream is the exception and uses real `event:` lines.
40
+ */
31
41
  event: string;
42
+ /**
43
+ * The semantic event type to discriminate on. Resolves to `data.type` when the
44
+ * JSON payload carries a `type` field (data-only streams), otherwise falls back to
45
+ * the `event:` field (chats stream). This is the value to switch on in consumers.
46
+ */
47
+ type: string;
32
48
  /** Parsed JSON data payload. */
33
49
  data: Record<string, unknown>;
34
50
  /** Optional event ID. */
@@ -64,13 +80,17 @@ interface SuccessResponse {
64
80
  }
65
81
  /**
66
82
  * Generic paginated list envelope.
67
- * The API uses different pagination styles across resources; all optional
68
- * fields that a particular endpoint may or may not include are represented here.
83
+ * The API uses different pagination styles across resources (page+limit,
84
+ * offset, cursor/has_next); every field a particular endpoint may or may not
85
+ * include is optional here. `total` is optional because cursor/has_next style
86
+ * endpoints do not return a total count.
69
87
  *
70
88
  * @template T - The type of each item in the collection.
71
89
  */
72
90
  interface PaginatedList<T> {
73
- total: number;
91
+ /** The page of items. Some endpoints nest items under a resource-specific key instead. */
92
+ items?: T[];
93
+ total?: number;
74
94
  page?: number;
75
95
  page_size?: number;
76
96
  total_pages?: number;
@@ -165,14 +185,23 @@ interface UserResponse {
165
185
  }
166
186
  /**
167
187
  * Lightweight organization membership record returned inside user-centric responses.
188
+ *
189
+ * Wire shape matches the backend `get_user_organizations` projection
190
+ * (`{id, slug, name, domain, role, joined_at, is_default}`). Fields are
191
+ * snake_case to mirror the API response exactly.
168
192
  */
169
193
  interface OrganizationInfo {
170
194
  id: string;
171
195
  name: string;
172
196
  slug: string;
197
+ /** The organization's email domain, or `null` when unset. */
198
+ domain: string | null;
173
199
  /** The calling user's role inside this organization. */
174
200
  role: string;
175
- created_at: string;
201
+ /** ISO-8601 timestamp of when the user joined this organization. */
202
+ joined_at: string;
203
+ /** Whether this organization is the user's default organization. */
204
+ is_default: boolean;
176
205
  }
177
206
  /**
178
207
  * Response from listing the organizations a user belongs to.
@@ -183,19 +212,47 @@ interface OrganizationsResponse {
183
212
  organizations: OrganizationInfo[];
184
213
  total: number;
185
214
  }
215
+ /**
216
+ * The organization an invitation grants membership to.
217
+ */
218
+ interface InvitationOrganization {
219
+ id: string;
220
+ name: string;
221
+ slug: string | null;
222
+ /** The organization's email domain, or `null` when unset. */
223
+ domain: string | null;
224
+ }
225
+ /**
226
+ * The user who issued an invitation.
227
+ */
228
+ interface InvitationInviter {
229
+ id: string;
230
+ email: string;
231
+ username: string | null;
232
+ }
186
233
  /**
187
234
  * A single organization invitation object.
235
+ *
236
+ * Wire shape matches the backend `get_user_all_pending_invitations_optimized`
237
+ * projection. The organization and inviter are nested objects (not flat
238
+ * `organization_id` / `invited_email` fields).
188
239
  */
189
240
  interface InvitationObject {
190
241
  id: string;
191
- organization_id: string;
192
- organization_name?: string;
193
- invited_email: string;
242
+ /** The organization the invitation grants access to. */
243
+ organization: InvitationOrganization;
244
+ /** The user who sent the invitation. */
245
+ invited_by: InvitationInviter;
194
246
  role: string;
195
247
  status: string;
196
- invitation_message?: string;
248
+ invitation_message?: string | null;
197
249
  created_at: string;
198
- expires_at?: string;
250
+ expires_at?: string | null;
251
+ /**
252
+ * Whole days remaining until the invitation expires. Can be `0` for
253
+ * invitations expiring in under 24 hours (derived from `timedelta.days`).
254
+ */
255
+ days_until_expiry: number;
199
256
  }
200
257
  /**
201
258
  * Response from listing pending invitations for the authenticated user.
@@ -203,15 +260,30 @@ interface InvitationObject {
203
260
  interface InvitationsResponse {
204
261
  success: boolean;
205
262
  invitations: InvitationObject[];
206
- total: number;
263
+ /** Total number of pending invitations returned. */
264
+ total_count: number;
265
+ }
266
+ /**
267
+ * The organization details returned when an invitation is accepted.
268
+ */
269
+ interface AcceptedInvitationOrganization {
270
+ id: string;
271
+ name: string;
272
+ slug: string;
207
273
  }
208
274
  /**
209
- * Response from accepting or rejecting a single invitation.
275
+ * Response from accepting an invitation.
276
+ *
277
+ * On success the backend returns the joined organization and the granted
278
+ * role in addition to `success` / `message`.
210
279
  */
211
280
  interface InvitationResponse {
212
281
  success: boolean;
213
282
  message?: string;
214
- invitation: InvitationObject;
283
+ /** The organization the user joined. */
284
+ organization?: AcceptedInvitationOrganization;
285
+ /** The role the user was granted in the organization. */
286
+ role?: string;
215
287
  }
216
288
  /**
217
289
  * Response returned when a user leaves an organization.
@@ -223,12 +295,12 @@ interface LeaveResponse {
223
295
  left_organization: {
224
296
  id: string;
225
297
  name: string;
298
+ slug: string;
226
299
  };
227
- /** The organizations the user still belongs to. */
228
- remaining_organizations: {
229
- id: string;
230
- name: string;
231
- }[];
300
+ /**
301
+ * The organizations the user still belongs to, as full membership records.
302
+ */
303
+ remaining_organizations: OrganizationInfo[];
232
304
  total_remaining: number;
233
305
  }
234
306
 
@@ -241,13 +313,19 @@ interface LeaveResponse {
241
313
  * Field names are camelCase; the SDK converts them to snake_case before sending.
242
314
  */
243
315
  interface CreateApiKeyParams {
244
- /** Human-readable label for the key. */
316
+ /** Human-readable label for the key. Must be 1-255 characters. */
245
317
  name: string;
246
- /** Scope the key to a specific organization. Defaults to the client-level org. */
318
+ /**
319
+ * Scope the key to a specific organization.
320
+ * If omitted, the key works for all of the user's organizations.
321
+ */
247
322
  organizationId?: string;
248
323
  /** ISO-8601 datetime after which the key becomes invalid. */
249
324
  expiresAt?: string;
250
- /** Maximum number of API calls allowed per minute for this key. */
325
+ /**
326
+ * Maximum number of API calls allowed per minute for this key.
327
+ * Must be between 1 and 1000 (backend default: 60).
328
+ */
251
329
  rateLimitPerMinute?: number;
252
330
  }
253
331
  /**
@@ -262,13 +340,21 @@ interface ApiKeyResponse {
262
340
  * Only returned once, immediately after creation — store it securely.
263
341
  */
264
342
  key?: string;
265
- /** Masked hint showing the first / last characters of the key. */
343
+ /** Identifier hint: the first 8 characters of the key. */
266
344
  key_hint: string;
345
+ /** Masked key for display, e.g. `mx_live_XXXX****`. */
346
+ masked_key: string;
267
347
  organization_id: string | null;
268
348
  expires_at: string | null;
269
- rate_limit_per_minute: number | null;
349
+ /** Whether the key has passed its expiration datetime. */
350
+ is_expired: boolean;
351
+ /** Whether the key is active (i.e. not revoked). */
352
+ is_active: boolean;
353
+ rate_limit_per_minute: number;
354
+ /** ISO-8601 datetime the key was last used, or null if never used. */
355
+ last_used_at: string | null;
270
356
  created_at: string;
271
- is_revoked?: boolean;
357
+ /** ISO-8601 datetime the key was revoked, or null if still active. */
272
358
  revoked_at?: string | null;
273
359
  }
274
360
  /**
@@ -284,7 +370,10 @@ interface CreateApiKeyResponse extends ApiKeyResponse {
284
370
  */
285
371
  interface ApiKeyListResponse {
286
372
  keys: ApiKeyResponse[];
287
- total?: number;
373
+ /** Total number of keys returned. Always present. */
374
+ total: number;
375
+ /** Maximum number of keys allowed per user. */
376
+ max_keys: number;
288
377
  }
289
378
  /**
290
379
  * Response returned after revoking an API key.
@@ -308,12 +397,20 @@ interface CreateOrganizationParams {
308
397
  slug?: string;
309
398
  }
310
399
  /**
311
- * Minimal organization object embedded in creation responses.
400
+ * Organization object embedded in creation responses.
401
+ *
402
+ * Wire fields are snake_case to match the backend `org_payload`.
312
403
  */
313
404
  interface OrganizationCreatedObject {
314
405
  id: string;
315
406
  name: string;
316
407
  slug: string;
408
+ /** Email domain associated with the organization, if any. */
409
+ domain: string | null;
410
+ /** Whether the organization is active. */
411
+ is_active: boolean;
412
+ /** ISO-8601 creation timestamp, or `null` if unavailable. */
413
+ created_at: string | null;
317
414
  }
318
415
  /**
319
416
  * Response from the create-organization endpoint.
@@ -348,8 +445,13 @@ interface LLMsResponse {
348
445
  interface InviteParams {
349
446
  /** Email address of the person being invited. */
350
447
  invitedEmail: string;
351
- /** Role to assign upon acceptance. Defaults to `'member'`. */
352
- role?: string;
448
+ /**
449
+ * Role to assign upon acceptance. Only `'admin'` is accepted — the org
450
+ * `member` role was retired (organizations are owner/admin only). Omit to use
451
+ * the server-side default (`admin`). The backend rejects `role: 'member'` with
452
+ * HTTP 422.
453
+ */
454
+ role?: 'admin';
353
455
  /** Optional personal message included in the invitation email. */
354
456
  invitationMessage?: string;
355
457
  }
@@ -364,8 +466,12 @@ interface CancelInvitationResponse {
364
466
  * Parameters for updating a member's role within an organization.
365
467
  */
366
468
  interface RoleUpdateParams {
367
- /** New role to assign. */
368
- role: 'member' | 'admin';
469
+ /**
470
+ * New role to assign. Only `'admin'` is accepted — the org `member` role was
471
+ * retired (organizations are owner/admin only); the backend rejects
472
+ * `role: 'member'` with HTTP 422.
473
+ */
474
+ role: 'admin';
369
475
  }
370
476
  /**
371
477
  * Response returned after a successful role update.
@@ -377,6 +483,120 @@ interface RoleUpdateResponse {
377
483
  organization_id: string;
378
484
  new_role: string;
379
485
  }
486
+ /**
487
+ * Response from previewing the prorated cost of adding one seat
488
+ * (`POST /organizations/invite/preview`).
489
+ *
490
+ * A discriminated union on `preview_available`:
491
+ * - `false` — preview is not available (e.g. no active subscription); includes a `reason`.
492
+ * - `true` — a prorated cost preview is available with full pricing detail.
493
+ *
494
+ * Wire fields are snake_case to match the backend response.
495
+ */
496
+ type InvitePreviewResponse = {
497
+ preview_available: false;
498
+ /** Machine-readable reason the preview is unavailable, e.g. `'no_active_subscription'`. */
499
+ reason: string;
500
+ } | {
501
+ preview_available: true;
502
+ /** Billing interval of the active subscription, e.g. `'month'` or `'year'`. */
503
+ interval: string;
504
+ /** The seat count that would result after adding one seat. */
505
+ new_quantity: number;
506
+ /** Total amount due, in major currency units (e.g. dollars). */
507
+ amount_due: number;
508
+ /** ISO-4217 currency code, e.g. `'usd'`. */
509
+ currency: string;
510
+ /** Prorated line amount for the added seat, in major currency units. */
511
+ proration_line_amount: number;
512
+ /** `true` if the charge is immediate (annual plans); `false` if billed on the next invoice (monthly). */
513
+ immediate: boolean;
514
+ };
515
+ /**
516
+ * A single visible model in an integration's model-visibility dropdown.
517
+ *
518
+ * Wire fields are snake_case to match the backend `LLMModelEntry`.
519
+ */
520
+ interface LLMModelEntry {
521
+ /** Model id / slug used at runtime. */
522
+ id: string;
523
+ /** Optional label shown in the dropdown. */
524
+ display_name?: string;
525
+ }
526
+ /**
527
+ * The org's persisted default composer LLM selection.
528
+ *
529
+ * Wire fields are snake_case to match the backend `composer_llm` object.
530
+ */
531
+ interface ComposerLLMSelection {
532
+ integration_name: string;
533
+ provider_id: string;
534
+ model_id: string;
535
+ credential_id?: string;
536
+ }
537
+ /**
538
+ * Response from reading per-organization settings (`GET /organizations/settings`).
539
+ *
540
+ * Wire fields are snake_case to match the backend response.
541
+ */
542
+ interface SettingsResponse {
543
+ /**
544
+ * Per-integration map of visible models. Keys are integration names
545
+ * (e.g. `'openrouter'`), values are the visible model entries.
546
+ */
547
+ llm_model_visibility: Record<string, LLMModelEntry[]>;
548
+ /** The org's default composer LLM, or `null` if not configured. */
549
+ composer_llm: ComposerLLMSelection | null;
550
+ }
551
+ /**
552
+ * Parameters for setting which models are visible for one integration
553
+ * (`PUT /organizations/settings/llm-model-visibility`).
554
+ *
555
+ * Send the FULL desired visible list. An empty `models` array resets the
556
+ * integration's visibility to the catalog default.
557
+ *
558
+ * Field names are camelCase and converted to snake_case on the wire by the
559
+ * base client.
560
+ */
561
+ interface SetModelVisibilityParams {
562
+ /** Integration name, e.g. `'openrouter'` or `'openai'`. */
563
+ integrationName: string;
564
+ /** Full desired set of visible models. Empty resets to default. */
565
+ models: LLMModelEntry[];
566
+ }
567
+ /**
568
+ * Response from setting model visibility
569
+ * (`PUT /organizations/settings/llm-model-visibility`).
570
+ */
571
+ interface SetModelVisibilityResponse {
572
+ /** Updated per-integration map of visible models. */
573
+ llm_model_visibility: Record<string, LLMModelEntry[]>;
574
+ }
575
+ /**
576
+ * Parameters for setting the org's default composer LLM
577
+ * (`PUT /organizations/settings/composer-llm`).
578
+ *
579
+ * Field names are camelCase and converted to snake_case on the wire by the
580
+ * base client.
581
+ */
582
+ interface ComposerLLMParams {
583
+ /** Integration name, e.g. `'openrouter'`. */
584
+ integrationName: string;
585
+ /** Provider id for the selected model. */
586
+ providerId: string;
587
+ /** Model id to use as the default composer LLM. */
588
+ modelId: string;
589
+ /** Optional credential id to associate with the selection. */
590
+ credentialId?: string;
591
+ }
592
+ /**
593
+ * Response from setting the org's default composer LLM
594
+ * (`PUT /organizations/settings/composer-llm`).
595
+ */
596
+ interface ComposerLLMResponse {
597
+ /** The org's updated default composer LLM, or `null` if cleared. */
598
+ composer_llm: ComposerLLMSelection | null;
599
+ }
380
600
 
381
601
  /**
382
602
  * Types for workflow definitions, nodes, edges, and builder metadata.
@@ -479,8 +699,12 @@ interface LLMNodeConfig {
479
699
  system_prompt?: string;
480
700
  /** User prompt template. */
481
701
  user_prompt?: string;
702
+ /** @deprecated Use `user_prompt`. Kept as a backward-compatible alias; the backend copies it into `user_prompt`. */
703
+ prompt_template?: string;
482
704
  /** JSON Schema describing the expected structured output format. */
483
705
  structured_output_schema?: Record<string, unknown>;
706
+ /** When `true`, enforce strict structured-output schema validation. */
707
+ structured_output_strict?: boolean;
484
708
  }
485
709
  /**
486
710
  * Configuration for a `tool` node — executes a single tool action.
@@ -497,17 +721,25 @@ interface AgentNodeConfig {
497
721
  llm: LLMConfig;
498
722
  /** Tools available to this agent. */
499
723
  tools?: ToolDefinition[];
500
- system_prompt?: string;
724
+ /** Required by the backend — an agent node without a system prompt is rejected (422). */
725
+ system_prompt: string;
501
726
  user_prompt?: string;
502
727
  /** Maximum tool-call iterations before the agent yields. */
503
728
  max_iterations?: number;
504
729
  input_mapping?: Record<string, string>;
505
730
  }
506
731
  /**
507
- * Configuration for a `function` node — executes arbitrary registered code.
508
- * Shape is integration-specific and passed through without transformation.
732
+ * Configuration for a `function` node — executes a registered function.
733
+ * The backend requires `function_name`; `input_mapping` and `parameters` are
734
+ * optional. Additional integration-specific keys pass through untransformed.
509
735
  */
510
736
  interface FunctionNodeConfig {
737
+ /** Name of the registered function to invoke (required by the backend). */
738
+ function_name?: string;
739
+ /** Maps state fields to function input parameters. */
740
+ input_mapping?: Record<string, string>;
741
+ /** Static parameters passed to the function. */
742
+ parameters?: Record<string, unknown>;
511
743
  [key: string]: unknown;
512
744
  }
513
745
  /**
@@ -529,6 +761,8 @@ interface LoopConfig {
529
761
  mode: string;
530
762
  /** Fixed iteration count for `"for"` mode. */
531
763
  iterations?: number;
764
+ /** State field holding a dynamic iteration count for `"for"` mode. */
765
+ iterations_ref?: string;
532
766
  /** State field containing the collection to iterate over for `"foreach"` mode. */
533
767
  collection?: string;
534
768
  /** Boolean expression used for `"while"` mode. */
@@ -541,6 +775,12 @@ interface LoopConfig {
541
775
  exit_target?: string;
542
776
  /** Hard upper bound on iterations to prevent infinite loops. */
543
777
  max_iterations?: number;
778
+ /** Run `"foreach"` iterations in parallel rather than sequentially. */
779
+ parallel?: boolean;
780
+ /** Accumulate iteration results instead of overwriting. */
781
+ accumulate?: boolean;
782
+ /** State field to accumulate iteration results from/into. */
783
+ accumulate_from?: string;
544
784
  }
545
785
  /**
546
786
  * Configuration for a `conditional` node — branches or loops based on state.
@@ -624,10 +864,10 @@ interface NodeDefinition {
624
864
  description?: string;
625
865
  /** Whether the node participates in execution. Defaults to `true`. */
626
866
  enabled?: boolean;
627
- /** Canvas X position (used by the visual editor). */
628
- x?: number;
629
- /** Canvas Y position (used by the visual editor). */
630
- y?: number;
867
+ /** Canvas X position. Required by the backend (create/update return 422 without it). */
868
+ x: number;
869
+ /** Canvas Y position. Required by the backend (create/update return 422 without it). */
870
+ y: number;
631
871
  retry_config?: RetryConfig;
632
872
  llm_config?: LLMNodeConfig;
633
873
  tool_config?: ToolNodeConfig;
@@ -674,7 +914,12 @@ interface CreateWorkflowParams {
674
914
  category?: string;
675
915
  /** Lifecycle status (e.g. `"draft"`, `"published"`). */
676
916
  status?: string;
677
- /** Sharing visibility (e.g. `"private"`, `"organization"`, `"public"`). */
917
+ /**
918
+ * Sharing visibility — one of `"private"`, `"organization"`, `"public"`, or
919
+ * `"system"`. Omit to let the backend default to `"organization"` (there is no
920
+ * client-side default). Note: `"private"` is no longer creator-only — it now
921
+ * behaves like `"organization"` (any org admin/owner can view/run/resume).
922
+ */
678
923
  visibility?: string;
679
924
  /** Default input values shown in the run panel. */
680
925
  input?: Record<string, unknown>;
@@ -692,6 +937,11 @@ interface UpdateWorkflowParams {
692
937
  tags?: string[];
693
938
  category?: string;
694
939
  status?: string;
940
+ /**
941
+ * Sharing visibility — `"private"`, `"organization"`, `"public"`, or
942
+ * `"system"`. `"private"` is no longer creator-only; it behaves like
943
+ * `"organization"`.
944
+ */
695
945
  visibility?: string;
696
946
  workflowSchema?: WorkflowDefinition;
697
947
  input?: Record<string, unknown>;
@@ -706,18 +956,28 @@ interface WorkflowSummary {
706
956
  description: string | null;
707
957
  version: string;
708
958
  status: string;
959
+ /**
960
+ * Sharing visibility — one of `"private"`, `"organization"`, `"public"`, or
961
+ * `"system"`. New workflows default to `"organization"`; `"private"` is no
962
+ * longer creator-only and behaves like `"organization"`.
963
+ */
709
964
  visibility: string;
710
965
  category: string | null;
711
966
  tags: string[];
712
967
  created_at: string;
713
968
  updated_at: string;
714
- creator_id: string;
969
+ /** Null for workflows with no recorded creator (e.g. system/seed workflows). */
970
+ creator_id: string | null;
971
+ /** Default state input payload returned on each list row. */
972
+ input?: Record<string, unknown>;
715
973
  }
716
974
  /**
717
975
  * Full workflow record including the stored schema.
718
976
  */
719
977
  interface WorkflowResponse extends WorkflowSummary {
720
978
  workflow_schema: WorkflowDefinition;
979
+ /** Execution config defaults returned by create/get/update. */
980
+ config?: Partial<WorkflowConfig>;
721
981
  edit_version?: number;
722
982
  last_edited_by?: string | null;
723
983
  last_edited_at?: string | null;
@@ -729,11 +989,14 @@ interface WorkflowResponse extends WorkflowSummary {
729
989
  interface WorkflowListParams {
730
990
  status?: string;
731
991
  category?: string;
992
+ /**
993
+ * Filter by sharing visibility — `"private"`, `"organization"`, `"public"`, or
994
+ * `"system"`.
995
+ */
732
996
  visibility?: string;
733
997
  search?: string;
734
998
  page?: number;
735
999
  pageSize?: number;
736
- organizationId?: string;
737
1000
  }
738
1001
  /**
739
1002
  * Paginated list of workflow summaries.
@@ -764,22 +1027,62 @@ interface BuilderDetailsParams {
764
1027
  category?: string;
765
1028
  /** Filter to a specific integration name. */
766
1029
  integrationName?: string;
767
- organizationId?: string;
1030
+ }
1031
+ /**
1032
+ * A rich descriptor for a single builder node type.
1033
+ */
1034
+ interface BuilderNodeTypeDescriptor {
1035
+ label?: string;
1036
+ description?: string;
1037
+ default_schema?: Record<string, unknown>;
1038
+ output_schema?: Record<string, unknown>;
1039
+ providers?: unknown[];
1040
+ integrations?: unknown[];
1041
+ [key: string]: unknown;
768
1042
  }
769
1043
  /**
770
1044
  * Response from the builder details endpoint, providing the palette of
771
1045
  * available node types, integration categories, and their counts.
772
1046
  */
773
1047
  interface BuilderDetailsResponse {
774
- /** Map of node type identifier to its descriptor. */
775
- node_types: Record<string, unknown>;
776
- /** Available integration categories. */
777
- categories: string[];
778
- /** Count breakdown by category or type. */
779
- counts: Record<string, number>;
1048
+ /** Map of node type identifier to its rich descriptor. */
1049
+ node_types: Record<string, BuilderNodeTypeDescriptor>;
1050
+ /** Available integration items grouped by category. */
1051
+ categories: {
1052
+ tools: string[];
1053
+ functions: string[];
1054
+ transformers: string[];
1055
+ };
1056
+ /** Count breakdown. Known keys: integrations, functions, transformers, providers. */
1057
+ counts: {
1058
+ integrations?: number;
1059
+ functions?: number;
1060
+ transformers?: number;
1061
+ providers?: number;
1062
+ [key: string]: number | undefined;
1063
+ };
1064
+ /** Builder feature flags (e.g. array-spread support). */
1065
+ features?: {
1066
+ array_spread: boolean;
1067
+ };
780
1068
  /** Whether the response was served from cache. */
781
1069
  cached: boolean;
782
1070
  }
1071
+ /**
1072
+ * A real-time collaboration event from the `GET /workflows/{id}/changes`
1073
+ * SSE stream. This is a data-only stream; discriminate on `type`.
1074
+ */
1075
+ type WorkflowChangeEvent = {
1076
+ type: 'connected';
1077
+ workflow_id: string;
1078
+ edit_version: number;
1079
+ } | ({
1080
+ type: 'workflow_updated';
1081
+ } & Record<string, unknown>) | ({
1082
+ type: 'user_joined';
1083
+ } & Record<string, unknown>) | ({
1084
+ type: 'user_left';
1085
+ } & Record<string, unknown>);
783
1086
 
784
1087
  /**
785
1088
  * Types for workflow execution — running, resuming, cancelling, and streaming.
@@ -788,19 +1091,29 @@ interface BuilderDetailsResponse {
788
1091
 
789
1092
  /**
790
1093
  * Parameters for triggering a workflow run.
1094
+ *
1095
+ * Two run modes are supported:
1096
+ * - `workflowId` — run a previously saved workflow (requires an active deployment;
1097
+ * the backend returns 400 if the workflow has not been deployed).
1098
+ * - `workflow` — run an inline, ad-hoc definition without saving it.
1099
+ *
1100
+ * The legacy `llm`-only and `systemWorkflow` modes were removed from the backend
1101
+ * (the run endpoint now returns HTTP 410 for an `llm_config`-only request — use
1102
+ * `client.assistant.chat()` instead).
791
1103
  */
792
1104
  interface WorkflowRunParams {
793
- /** ID of a previously saved workflow to run. Mutually exclusive with `workflow`. */
1105
+ /** ID of a previously saved workflow to run. Mutually exclusive with `workflow`. Requires an active deployment. */
794
1106
  workflowId?: string;
795
- /** An inline workflow definition to run without saving. */
1107
+ /** An inline workflow definition to run without saving. Mutually exclusive with `workflowId`. */
796
1108
  workflow?: WorkflowDefinition;
797
- /** Override the LLM used by the run. */
798
- llm?: LLMConfig;
799
- /** Name of a system-level workflow to run (e.g. `"workflow_name"`). */
800
- systemWorkflow?: string;
1109
+ /** For ad-hoc (inline) runs, the saved workflow to attribute this run to in run history. */
1110
+ attributionWorkflowId?: string;
801
1111
  /** State input values passed to the workflow's entry node. */
802
1112
  input?: Record<string, unknown>;
803
- /** Runtime config overrides for this execution. */
1113
+ /**
1114
+ * Runtime config overrides for this execution. Recognised keys include
1115
+ * `thread_id`, `recursion_limit`, and `batch_interval_ms`.
1116
+ */
804
1117
  config?: Record<string, unknown>;
805
1118
  /** Whether to open an SSE stream for real-time events. */
806
1119
  stream?: boolean;
@@ -808,15 +1121,32 @@ interface WorkflowRunParams {
808
1121
  ephemeral?: boolean;
809
1122
  /** If `true`, the run and its messages are only visible to the creator. */
810
1123
  isPrivate?: boolean;
811
- /** Knowledge base retrieval config for this run. */
812
- knowledgeConfig?: Record<string, unknown>;
813
- organizationId?: string;
1124
+ }
1125
+ /**
1126
+ * A persisted workflow message envelope (human or AI message) returned inline
1127
+ * by a synchronous run.
1128
+ */
1129
+ interface WorkflowMessageEnvelope {
1130
+ id: string;
1131
+ chat_id: string | null;
1132
+ role: string;
1133
+ content: unknown;
1134
+ workflow: Record<string, unknown> | null;
1135
+ run_id: string;
1136
+ running_status: string;
1137
+ created_at: string;
1138
+ updated_at: string;
1139
+ deleted_at: string | null;
814
1140
  }
815
1141
  /**
816
1142
  * Response from initiating a workflow run.
817
1143
  */
818
1144
  interface WorkflowRunResponse {
819
- /** Terminal or intermediate status (e.g. `"completed"`, `"running"`, `"interrupted"`). */
1145
+ /**
1146
+ * The status of the synchronous portion. For a streaming/async run this is
1147
+ * always `"running"`; terminal statuses are observed via `listen()` or the
1148
+ * run-history endpoints, not here.
1149
+ */
820
1150
  status: string;
821
1151
  run_id: string;
822
1152
  thread_id: string;
@@ -825,12 +1155,12 @@ interface WorkflowRunResponse {
825
1155
  stream: boolean;
826
1156
  workflow_name: string;
827
1157
  workflow_version: string;
828
- /** `"saved"` | `"inline"` | `"deployment"` */
829
- workflow_source: string;
1158
+ /** Origin of the executed definition: `"database"`, `"request"`, or `"system:<name>"`. */
1159
+ workflow_source: 'database' | 'request' | `system:${string}`;
830
1160
  /** Wall-clock duration of the synchronous portion in milliseconds. */
831
1161
  elapsed_ms: number;
832
- human_message?: Record<string, unknown> | null;
833
- ai_message?: Record<string, unknown> | null;
1162
+ human_message?: WorkflowMessageEnvelope | null;
1163
+ ai_message?: WorkflowMessageEnvelope | null;
834
1164
  message: string;
835
1165
  }
836
1166
  /**
@@ -838,7 +1168,8 @@ interface WorkflowRunResponse {
838
1168
  */
839
1169
  interface WorkflowStateResponse {
840
1170
  thread_id: string;
841
- run_id: string;
1171
+ /** The originating run ID, read from checkpoint metadata — may be null. */
1172
+ run_id: string | null;
842
1173
  checkpoint_id: string;
843
1174
  /** The full LangGraph state object. */
844
1175
  state: Record<string, unknown>;
@@ -846,7 +1177,7 @@ interface WorkflowStateResponse {
846
1177
  next: string[];
847
1178
  /** LangGraph metadata blob. */
848
1179
  metadata: Record<string, unknown>;
849
- /** Number of writes pending flush to the checkpoint store. */
1180
+ /** Count of pending writes not yet flushed to the checkpoint store. */
850
1181
  pending_writes: number;
851
1182
  }
852
1183
  /**
@@ -865,7 +1196,6 @@ interface WorkflowResumeParams {
865
1196
  runId: string;
866
1197
  /** Whether to open an SSE stream for the resumed execution. */
867
1198
  stream?: boolean;
868
- organizationId?: string;
869
1199
  }
870
1200
  /**
871
1201
  * Response from resuming an interrupted workflow run.
@@ -875,112 +1205,194 @@ interface WorkflowResumeResponse {
875
1205
  run_id: string;
876
1206
  thread_id: string;
877
1207
  stream: boolean;
878
- workflow_source: string;
1208
+ workflow_source: 'database' | 'request' | `system:${string}`;
879
1209
  message: string;
880
1210
  }
881
1211
  /**
882
1212
  * Response from cancelling an in-progress workflow run.
883
1213
  */
884
1214
  interface CancelResponse {
885
- status: string;
1215
+ /** The backend returns the literal `"cancellation_requested"` on success. */
1216
+ status: 'cancellation_requested' | string;
886
1217
  run_id: string;
887
1218
  reason: string;
888
1219
  message: string;
889
1220
  }
890
- /**
891
- * Data payload for the `metadata` SSE event — emitted at the start of a run.
892
- */
1221
+ /** Payload of a `metadata` event (wrapped under `data`). */
893
1222
  interface MetadataEventData {
894
1223
  run_id: string;
895
1224
  thread_id: string;
896
1225
  workflow_name: string;
897
1226
  workflow_version: string;
898
- /** Ordered list of node IDs in the execution plan. */
899
- nodes: string[];
1227
+ /** `"llm"` (token-streaming) or `"workflow"`. */
1228
+ workflow_type: string;
1229
+ timestamp: string;
1230
+ }
1231
+ /** Payload of a `node_started` event (flat — fields sit alongside `type`). */
1232
+ interface NodeStartedEventData {
1233
+ /** The node ID. */
1234
+ node: string;
1235
+ /** The node display name. */
1236
+ name: string;
1237
+ timestamp: string;
1238
+ /** Node-specific start metadata (shape varies by node type). */
1239
+ metadata?: Record<string, unknown>;
900
1240
  }
901
- /**
902
- * Data payload for a `node_update` SSE event — emitted as each node changes state.
903
- */
1241
+ /** Payload of a `node_update` event (flat — fields sit alongside `type`). */
904
1242
  interface NodeUpdateEventData {
905
- node_id: string;
906
- node_type: string;
907
- status: 'started' | 'completed' | 'error';
908
- /** Node output value (present when `status` is `"completed"`). */
909
- output?: unknown;
910
- /** Error message (present when `status` is `"error"`). */
911
- error?: string;
912
- /** How long the node took to execute, in milliseconds. */
913
- execution_time_ms?: number;
1243
+ /** The node ID. */
1244
+ node: string;
1245
+ /** The node display name. */
1246
+ name: string;
1247
+ timestamp: string;
1248
+ /** Node output (shape varies by node type). */
1249
+ output?: Record<string, unknown>;
914
1250
  }
915
- /**
916
- * Data payload for an `interrupt` SSE event — execution is paused for human input.
917
- */
1251
+ /** Payload of an `interrupt` event (wrapped under `data`). */
918
1252
  interface InterruptEventData {
919
1253
  message: string;
920
- /** Current workflow state at the point of interruption. */
921
- state: Record<string, unknown>;
922
- /** Instructions describing what the human should supply as a resume value. */
923
- resume_instructions?: string;
924
- /** ID of the node that triggered the interrupt. */
925
- node_id: string;
1254
+ /** Structured interrupt payload, if any. */
1255
+ data: Record<string, unknown>;
1256
+ /** JSON Schema describing the expected resume value, when provided. */
1257
+ resume_schema?: Record<string, unknown>;
1258
+ /** Example resume values, when provided. */
1259
+ examples?: unknown;
926
1260
  }
927
- /**
928
- * Data payload for a `resumed` SSE event — a previously interrupted run has continued.
929
- */
1261
+ /** Payload of a `resumed` event (wrapped under `data`). */
930
1262
  interface ResumedEventData {
931
1263
  run_id: string;
932
1264
  thread_id: string;
1265
+ resume_value: unknown;
1266
+ timestamp: string;
933
1267
  }
934
- /**
935
- * Data payload for the `done` SSE event — the workflow has finished executing.
936
- */
1268
+ /** Payload of a `done` event (wrapped under `data`). */
937
1269
  interface DoneEventData {
938
- final_state: Record<string, unknown>;
939
- steps_executed: number;
940
- total_execution_time_ms: number;
1270
+ message: string;
941
1271
  }
942
- /**
943
- * Data payload for an `error` SSE event — an unrecoverable error occurred.
944
- */
1272
+ /** Payload of an `error` event (flat — fields sit alongside `type`). */
945
1273
  interface ErrorEventData {
946
- error_message: string;
1274
+ message: string;
947
1275
  error_type?: string;
948
- /** ID of the node where the error originated, if applicable. */
949
- node_id?: string;
950
- stack_trace?: string;
951
1276
  }
952
1277
  /**
953
- * A type-safe discriminated union of all possible SSE events emitted during
954
- * a workflow run or resume stream.
1278
+ * A type-safe discriminated union of every SSE frame emitted during a workflow
1279
+ * run or resume stream. Discriminate on the `type` field (NOT `event`, which is
1280
+ * always `"message"` for these data-only streams):
955
1281
  *
956
- * Discriminate on the `event` field to narrow the `data` type:
957
1282
  * ```ts
958
- * for await (const evt of stream) {
959
- * if (evt.event === 'done') {
960
- * console.log(evt.data.final_state);
1283
+ * for await (const evt of client.executions.listen(runId)) {
1284
+ * switch (evt.type) {
1285
+ * case 'node_update': console.log(evt.node, evt.output); break; // flat
1286
+ * case 'done': console.log(evt.data.message); break; // wrapped
1287
+ * case 'error': console.error(evt.message); break; // flat
961
1288
  * }
962
1289
  * }
963
1290
  * ```
964
1291
  */
965
- type WorkflowSSEEvent = {
966
- event: 'metadata';
1292
+ type WorkflowSSEEvent = ({
1293
+ type: 'metadata';
1294
+ } & {
967
1295
  data: MetadataEventData;
968
- } | {
969
- event: 'node_update';
970
- data: NodeUpdateEventData;
971
- } | {
972
- event: 'interrupt';
1296
+ }) | ({
1297
+ type: 'node_started';
1298
+ } & NodeStartedEventData) | ({
1299
+ type: 'node_update';
1300
+ } & NodeUpdateEventData) | ({
1301
+ type: 'interrupt';
1302
+ } & {
973
1303
  data: InterruptEventData;
974
- } | {
975
- event: 'resumed';
1304
+ }) | ({
1305
+ type: 'resumed';
1306
+ } & {
976
1307
  data: ResumedEventData;
977
- } | {
978
- event: 'done';
1308
+ }) | ({
1309
+ type: 'done';
1310
+ } & {
979
1311
  data: DoneEventData;
980
- } | {
981
- event: 'error';
982
- data: ErrorEventData;
983
- };
1312
+ }) | ({
1313
+ type: 'cancelled';
1314
+ } & {
1315
+ data: Record<string, unknown> | null;
1316
+ }) | ({
1317
+ type: 'error';
1318
+ } & ErrorEventData);
1319
+
1320
+ /**
1321
+ * Types for the durable workflow run-history read endpoints (`/workflow-runs`).
1322
+ * @module types/workflow-runs
1323
+ */
1324
+ /**
1325
+ * Query parameters for listing workflow runs.
1326
+ */
1327
+ interface WorkflowRunListParams {
1328
+ /** Filter to a single workflow's run history. */
1329
+ workflowId?: string;
1330
+ /** Filter by run status. */
1331
+ status?: string;
1332
+ /** Filter by trigger type. */
1333
+ triggerType?: string;
1334
+ /** Page size, 1–100 (default 50). */
1335
+ limit?: number;
1336
+ /** Number of rows to skip (default 0). */
1337
+ offset?: number;
1338
+ }
1339
+ /**
1340
+ * A preview-optimized run-history list row (no heavy snapshot columns).
1341
+ */
1342
+ interface WorkflowRunListItem {
1343
+ /** The run table primary key (UUID) — pass this to `get()`, NOT `run_id`. */
1344
+ id: string;
1345
+ /** The execution run ID (string) used by listen/cancel. */
1346
+ run_id: string;
1347
+ workflow_id: string | null;
1348
+ trigger_type: string;
1349
+ is_ad_hoc: boolean;
1350
+ status: string;
1351
+ started_at: string | null;
1352
+ completed_at: string | null;
1353
+ duration_seconds: number | null;
1354
+ error_message: string | null;
1355
+ created_at: string;
1356
+ has_output: boolean;
1357
+ }
1358
+ /**
1359
+ * Response from `GET /workflow-runs`. Pagination uses `has_more` (there is no
1360
+ * total count).
1361
+ */
1362
+ interface WorkflowRunListResponse {
1363
+ runs: WorkflowRunListItem[];
1364
+ has_more: boolean;
1365
+ limit: number;
1366
+ offset: number;
1367
+ }
1368
+ /**
1369
+ * A full durable run record, including input/output snapshots and attribution.
1370
+ */
1371
+ interface WorkflowRunDetail {
1372
+ /** The run table primary key (UUID). */
1373
+ id: string;
1374
+ run_id: string;
1375
+ organization_id: string;
1376
+ workflow_id: string | null;
1377
+ trigger_type: string;
1378
+ is_ad_hoc: boolean;
1379
+ status: string;
1380
+ user_id: string | null;
1381
+ api_key_id: string | null;
1382
+ schedule_id: string | null;
1383
+ composer_chat_id: string | null;
1384
+ thread_id: string | null;
1385
+ chat_id: string | null;
1386
+ deployment_id: string | null;
1387
+ started_at: string | null;
1388
+ completed_at: string | null;
1389
+ duration_seconds: number | null;
1390
+ error_message: string | null;
1391
+ input_snapshot: unknown | null;
1392
+ output_summary: unknown | null;
1393
+ created_at: string;
1394
+ updated_at: string;
1395
+ }
984
1396
 
985
1397
  /**
986
1398
  * Types for workflow deployment management.
@@ -1001,12 +1413,14 @@ interface CreateDeploymentParams {
1001
1413
  */
1002
1414
  interface DeploymentResponse {
1003
1415
  id: string;
1004
- workflow_id: string;
1416
+ /** Omitted from list rows by the backend; present on detail. */
1417
+ workflow_id?: string;
1005
1418
  name: string;
1006
1419
  version: string;
1007
1420
  deployment_note: string | null;
1008
1421
  schema_image_url: string | null;
1009
- deployed_by: string;
1422
+ /** Null when the deploying user is unknown/unrecorded. */
1423
+ deployed_by: string | null;
1010
1424
  created_at: string;
1011
1425
  /** Whether this deployment is currently the live (active) version. */
1012
1426
  is_live: boolean;
@@ -1032,6 +1446,8 @@ interface DeploymentListResponse {
1032
1446
  * Returned by the get-single-deployment endpoint.
1033
1447
  */
1034
1448
  interface DeploymentDetailResponse extends DeploymentResponse {
1449
+ /** Free-form description, present only on the detail response. */
1450
+ description?: string | null;
1035
1451
  /** The full workflow graph definition at the time of this deployment. */
1036
1452
  workflow_schema: WorkflowDefinition;
1037
1453
  /** Default input values stored with the deployment. */
@@ -1046,8 +1462,8 @@ interface ActivateDeploymentResponse {
1046
1462
  success: boolean;
1047
1463
  message: string;
1048
1464
  deployment_id: string;
1049
- /** The deployment that was previously live, if any. */
1050
- previous_live_deployment_id: string | null;
1465
+ /** The deployment that was previously live. Omitted in early-return branches. */
1466
+ previous_live_deployment_id?: string | null;
1051
1467
  }
1052
1468
  /**
1053
1469
  * Response from deactivating the current live deployment.
@@ -1055,8 +1471,8 @@ interface ActivateDeploymentResponse {
1055
1471
  interface DeactivateDeploymentResponse {
1056
1472
  success: boolean;
1057
1473
  message: string;
1058
- /** The deployment that was deactivated. */
1059
- previous_live_deployment_id: string;
1474
+ /** The deployment that was deactivated. Omitted in early-return branches. */
1475
+ previous_live_deployment_id?: string | null;
1060
1476
  }
1061
1477
  /**
1062
1478
  * Response from deleting a deployment.
@@ -1083,22 +1499,29 @@ interface DeleteDeploymentResponse {
1083
1499
  */
1084
1500
  interface ChatResponse {
1085
1501
  id: string;
1086
- title: string | null;
1087
- creator_id: string;
1502
+ /** Chat title always present (backend `str`, non-nullable). */
1503
+ title: string;
1504
+ /** Creator user ID — nullable for system/org-owned chats. */
1505
+ creator_id: string | null;
1088
1506
  is_private: boolean;
1089
1507
  /** ID of the currently in-progress run attached to this chat, if any. */
1090
1508
  running_id: string | null;
1091
1509
  created_at: string;
1092
1510
  updated_at: string;
1093
- organization_id?: string | null;
1511
+ /** Owning organization ID — always present. */
1512
+ organization_id: string;
1094
1513
  /** Messages are included when fetching a single chat with messages embedded. */
1095
1514
  messages?: ChatMessageResponse[];
1096
1515
  deleted_at?: string | null;
1097
1516
  }
1098
1517
  /**
1099
1518
  * The role of a participant in a chat message.
1519
+ *
1520
+ * Common values are `'human'`, `'ai'`, and `'system'`, but the backend stores
1521
+ * the role as a free-form string (e.g. `'assistant'` may also appear), so any
1522
+ * string is accepted while preserving autocomplete for the common values.
1100
1523
  */
1101
- type ChatMessageRole = 'human' | 'ai' | 'system';
1524
+ type ChatMessageRole = 'human' | 'ai' | 'system' | (string & {});
1102
1525
  /**
1103
1526
  * A single message within a chat session.
1104
1527
  */
@@ -1115,6 +1538,8 @@ interface ChatMessageResponse {
1115
1538
  running_status?: string | null;
1116
1539
  created_at: string;
1117
1540
  updated_at: string;
1541
+ /** Soft-deletion timestamp, if the message has been deleted. */
1542
+ deleted_at?: string | null;
1118
1543
  }
1119
1544
  /**
1120
1545
  * Query parameters for paginating messages within a chat.
@@ -1125,25 +1550,40 @@ interface ChatMessagesParams {
1125
1550
  }
1126
1551
  /**
1127
1552
  * Paginated list of messages within a chat.
1553
+ *
1554
+ * Mirrors the backend `MessageListResponse`, which returns only the page of
1555
+ * messages plus the echoed `limit`/`offset`. The `limit` is nullable because
1556
+ * the backend leaves it unset when no limit was applied.
1128
1557
  */
1129
1558
  interface ChatMessagesResponse {
1130
1559
  messages: ChatMessageResponse[];
1131
- total: number;
1132
- limit: number;
1560
+ limit: number | null;
1133
1561
  offset: number;
1134
- has_next: boolean;
1135
- /** The number of messages actually returned (may differ from `limit` on the last page). */
1136
- actual_count: number;
1137
1562
  }
1138
1563
  /**
1139
1564
  * Parameters for updating a chat's metadata.
1140
1565
  */
1141
1566
  interface UpdateChatParams {
1142
1567
  title?: string;
1143
- isPrivate?: boolean;
1568
+ is_private?: boolean;
1144
1569
  /** Move the chat to a named folder (e.g. `"pinned"`, `"archived"`, or a custom name). */
1145
1570
  folder?: string;
1146
1571
  }
1572
+ /**
1573
+ * A lightweight chat row as returned by the grouped list endpoint. Unlike
1574
+ * {@link ChatResponse}, list rows do NOT include `organization_id`, `messages`,
1575
+ * or `deleted_at`.
1576
+ */
1577
+ interface ChatListItem {
1578
+ id: string;
1579
+ title: string;
1580
+ /** Creator user ID — nullable for system/org-owned chats. */
1581
+ creator_id: string | null;
1582
+ is_private: boolean;
1583
+ running_id: string | null;
1584
+ created_at: string;
1585
+ updated_at: string;
1586
+ }
1147
1587
  /**
1148
1588
  * Grouped chat list response.
1149
1589
  *
@@ -1156,7 +1596,29 @@ interface UpdateChatParams {
1156
1596
  * const pinned = list['pinned'] ?? [];
1157
1597
  * ```
1158
1598
  */
1159
- type ChatListResponse = Record<string, ChatResponse[]>;
1599
+ type ChatListResponse = Record<string, ChatListItem[]>;
1600
+ /**
1601
+ * Payload of the initial `connected` SSE event sent when the stream opens.
1602
+ */
1603
+ interface ChatConnectedEvent {
1604
+ status: 'connected';
1605
+ /** ISO-8601 timestamp of when the connection was established. */
1606
+ timestamp: string;
1607
+ }
1608
+ /**
1609
+ * Payload of a `chat_list_updated` SSE event, emitted when the user's chat list
1610
+ * changes and should be re-fetched via `GET /chats`.
1611
+ */
1612
+ interface ChatListUpdatedEvent {
1613
+ event: 'chat_list_updated';
1614
+ /**
1615
+ * Scope of the change: `"public"` affects all org users, `"private"` affects
1616
+ * only the current user.
1617
+ */
1618
+ type: 'public' | 'private';
1619
+ /** ISO-8601 timestamp of when the change occurred. */
1620
+ timestamp: string;
1621
+ }
1160
1622
 
1161
1623
  /**
1162
1624
  * Types for credential management and MCP server connections.
@@ -1168,18 +1630,38 @@ type ChatListResponse = Record<string, ChatResponse[]>;
1168
1630
  interface CredentialResponse {
1169
1631
  credential_id: string;
1170
1632
  integration_name: string;
1171
- /** Integration category (e.g. `"tool"`, `"llm"`, `"knowledge"`). */
1172
- integration_type: string;
1633
+ /** Integration category (e.g. `"tool"`, `"llm"`, `"knowledge"`). May be `null`. */
1634
+ integration_type: string | null;
1173
1635
  /** Human-readable label for the credential. */
1174
1636
  display_name: string;
1175
1637
  /** Auth mechanism used (e.g. `"api_key"`, `"oauth2"`, `"basic"`). */
1176
1638
  auth_type: string;
1177
1639
  /** Whether this is the default credential for its integration. */
1178
1640
  is_default: boolean;
1179
- created_at: string;
1180
- updated_at: string;
1641
+ created_at: string | null;
1642
+ updated_at: string | null;
1181
1643
  last_used_at?: string | null;
1182
1644
  expires_at?: string | null;
1645
+ /** Arbitrary metadata associated with the credential. */
1646
+ credentials_metadata?: Record<string, unknown> | null;
1647
+ }
1648
+ /**
1649
+ * Detailed credential record returned by `GET /credentials/{id}`.
1650
+ * Extends {@link CredentialResponse} with ownership and masked-auth fields
1651
+ * that are only present on the single-credential detail endpoint.
1652
+ */
1653
+ interface CredentialDetailResponse extends CredentialResponse {
1654
+ /** Organization that owns the credential. */
1655
+ organization_id: string;
1656
+ /** User ID that created the credential, if known. */
1657
+ created_by: string | null;
1658
+ /** Email of the user that created the credential, if known. */
1659
+ created_by_email?: string | null;
1660
+ /**
1661
+ * Masked representation of the auth data when `include_masked=true`
1662
+ * (e.g. `"OAuth2"`, `"sk-proj12...xyz"`). `null` when not requested.
1663
+ */
1664
+ auth_data_masked?: string | null;
1183
1665
  }
1184
1666
  /**
1185
1667
  * Parameters for creating a new credential.
@@ -1301,8 +1783,8 @@ interface CredentialUsageResponse {
1301
1783
  success_rate: number;
1302
1784
  /** Call counts broken down by action / operation name. */
1303
1785
  action_breakdown: Record<string, number>;
1304
- start_date: string;
1305
- end_date: string;
1786
+ start_date: string | null;
1787
+ end_date: string | null;
1306
1788
  }
1307
1789
  /**
1308
1790
  * Query parameters for paginating a credential's audit log.
@@ -1311,6 +1793,27 @@ interface CredentialAuditParams {
1311
1793
  limit?: number;
1312
1794
  offset?: number;
1313
1795
  }
1796
+ /**
1797
+ * A single audit log entry for a credential, as returned by
1798
+ * `GET /credentials/{id}/audit`.
1799
+ */
1800
+ interface AuditLogResponse {
1801
+ id: string;
1802
+ /** ID of the credential this entry belongs to. */
1803
+ credential_id: string;
1804
+ /** Type of event recorded (e.g. `"created"`, `"updated"`, `"used"`). */
1805
+ event_type: string;
1806
+ /** User ID that triggered the event, if known. */
1807
+ user_id: string | null;
1808
+ /** Structured details of what changed during the event. */
1809
+ changes: Record<string, unknown>;
1810
+ /** Source IP address of the request, if recorded. */
1811
+ ip_address: string | null;
1812
+ /** User-agent of the request, if recorded. */
1813
+ user_agent: string | null;
1814
+ /** ISO-8601 timestamp of when the event occurred. */
1815
+ timestamp: string;
1816
+ }
1314
1817
  /**
1315
1818
  * Parameters for connecting a Model Context Protocol (MCP) server as a credential.
1316
1819
  */
@@ -1325,11 +1828,29 @@ interface McpServerParams {
1325
1828
  makeDefault?: boolean;
1326
1829
  }
1327
1830
  /**
1328
- * Response listing tools discovered from an MCP server credential.
1831
+ * Response from creating a Model Context Protocol (MCP) server credential
1832
+ * via `POST /credentials/mcp-server`.
1833
+ *
1834
+ * Note: this is a narrower shape than {@link CredentialResponse} — the
1835
+ * backend `MCPServerCredentialResponse` omits `updated_at`, `integration_type`,
1836
+ * `last_used_at`, and `expires_at`.
1329
1837
  */
1330
- interface McpToolsResponse {
1838
+ interface MCPServerCredentialResponse {
1331
1839
  credential_id: string;
1332
- /** Array of tool descriptors in MCP schema format. */
1840
+ integration_name: string;
1841
+ display_name: string;
1842
+ auth_type: string;
1843
+ is_default: boolean;
1844
+ created_at: string | null;
1845
+ /** Arbitrary metadata associated with the credential. */
1846
+ credentials_metadata?: Record<string, unknown> | null;
1847
+ }
1848
+ /**
1849
+ * Response listing tools discovered from an MCP server credential.
1850
+ */
1851
+ interface McpToolsResponse {
1852
+ credential_id: string;
1853
+ /** Array of tool descriptors in MCP schema format. */
1333
1854
  tools: Record<string, unknown>[];
1334
1855
  total_count: number;
1335
1856
  }
@@ -1344,6 +1865,92 @@ interface RefreshDiscoveryResponse {
1344
1865
  total_tools: number;
1345
1866
  success: boolean;
1346
1867
  }
1868
+ /**
1869
+ * Parameters for initiating an OAuth2 authorization flow via
1870
+ * `POST /credentials/oauth2/initiate`.
1871
+ *
1872
+ * Requires admin/owner role on the target organization.
1873
+ */
1874
+ interface InitiateOAuth2Params {
1875
+ /** Integration name to start the OAuth2 flow for (e.g. `"github"`). */
1876
+ integrationName: string;
1877
+ /** Whether to use ModuleX's managed OAuth app. Defaults to `true` server-side. */
1878
+ useModulexOauth?: boolean;
1879
+ /** Custom OAuth app config; required when `useModulexOauth` is `false`. */
1880
+ customOauthConfig?: Record<string, unknown>;
1881
+ /** Callback URL the provider should redirect back to after authorization. */
1882
+ redirectUri: string;
1883
+ /** Space-separated OAuth scopes to request. Defaults to the integration's scopes. */
1884
+ scope?: string;
1885
+ /** Human-readable label for the credential that will be created. */
1886
+ displayName?: string;
1887
+ /** Whether to set the resulting credential as the default for its integration. */
1888
+ makeDefault?: boolean;
1889
+ /**
1890
+ * Per-user setup environment variables to inject into the persisted
1891
+ * `auth_data`, keyed by raw env-var name.
1892
+ */
1893
+ envVarValues?: Record<string, string>;
1894
+ /** Composer chat ID to atomically resume after the callback completes. */
1895
+ composerChatId?: string;
1896
+ /** Composer interrupt request ID, validated on callback. */
1897
+ composerRequestId?: string;
1898
+ /** LLM provider config used to rebuild the chat model on composer resume. */
1899
+ composerLlmConfig?: Record<string, unknown>;
1900
+ }
1901
+ /**
1902
+ * Response from initiating an OAuth2 flow. The caller should redirect the
1903
+ * user's browser to `authorization_url` to complete authorization.
1904
+ */
1905
+ interface OAuth2InitiateResponse {
1906
+ /** Provider authorization URL the user must visit to grant access. */
1907
+ authorization_url: string;
1908
+ /** Opaque CSRF/state token correlated with this flow. */
1909
+ state: string;
1910
+ }
1911
+ /**
1912
+ * Per-integration status entry emitted in bulk ModuleX-key SSE events.
1913
+ */
1914
+ interface ModulexKeyIntegrationStatus {
1915
+ integration_name: string;
1916
+ integration_type: string;
1917
+ display_name: string;
1918
+ /** Whether a ModuleX-managed key credential already exists for this integration. */
1919
+ has_modulex_key_credential: boolean;
1920
+ }
1921
+ /**
1922
+ * Summary counts emitted in the terminal (`completed`) bulk ModuleX-key event.
1923
+ */
1924
+ interface ModulexKeyBulkSummary {
1925
+ total: number;
1926
+ created: number;
1927
+ already_existed: number;
1928
+ }
1929
+ /**
1930
+ * Typed `data` payload of a bulk ModuleX-key provisioning SSE event.
1931
+ *
1932
+ * Emitted by `POST /credentials/bulk-modulex-keys/stream`. The `phase`
1933
+ * field discriminates the lifecycle stage; phase-specific extras are
1934
+ * optional and only present on the relevant phases.
1935
+ */
1936
+ interface ModulexKeyBulkEventData {
1937
+ /** Lifecycle phase of the bulk provisioning stream. */
1938
+ phase: 'initial_status' | 'creating' | 'retrying' | 'completed';
1939
+ /** Current per-integration statuses. */
1940
+ integrations?: ModulexKeyIntegrationStatus[];
1941
+ /** Whether the overall operation has completed. */
1942
+ completed?: boolean;
1943
+ /** Integrations created during this phase. */
1944
+ just_created?: string[];
1945
+ /** Number of integrations being retried. */
1946
+ retrying_count?: number;
1947
+ /** Final summary counts, present on the `completed` phase. */
1948
+ summary?: ModulexKeyBulkSummary;
1949
+ /** Human-readable status message. */
1950
+ message?: string;
1951
+ /** Error message when a phase fails. */
1952
+ error?: string;
1953
+ }
1347
1954
 
1348
1955
  /**
1349
1956
  * Types for browsing the integration catalog and fetching provider details.
@@ -1369,63 +1976,147 @@ interface BrowseParams {
1369
1976
  pageSize?: number;
1370
1977
  }
1371
1978
  /**
1372
- * Response from the catalog browse endpoint.
1373
- */
1374
- interface BrowseResponse {
1375
- integrations: IntegrationResponse[];
1376
- total: number;
1377
- page?: number;
1378
- page_size?: number;
1379
- total_pages?: number;
1380
- }
1381
- /**
1382
- * Generic integration object as returned by catalog and detail endpoints.
1383
- * Fields beyond the listed ones are provider-specific and accessed via the index signature.
1979
+ * Integration metadata as returned by list/browse endpoints
1980
+ * (`/integrations/browse`, `/integrations/tools`, `/integrations/llm-providers`,
1981
+ * `/integrations/knowledge-providers`).
1982
+ *
1983
+ * Mirrors the backend `IntegrationMetadata` model. Wire field names are
1984
+ * snake_case and are returned as-is by the client (no camelCase conversion).
1985
+ *
1986
+ * Note: when `include_details=false` on browse, the backend strips
1987
+ * `actions`, `models`, and `auth_schemas` from each element, hence those
1988
+ * fields are optional.
1384
1989
  */
1385
- interface IntegrationResponse {
1990
+ interface IntegrationMetadata {
1991
+ /** Canonical integration name / identifier. */
1386
1992
  name: string;
1387
- /** Integration category (e.g. `"tool"`, `"llm_provider"`, `"knowledge_provider"`). */
1388
- type: string;
1389
- display_name?: string;
1390
- description?: string;
1391
- /** Available action/service names. */
1392
- actions?: string[];
1393
- /** Authentication schema descriptors. */
1394
- auth_schemas?: Record<string, unknown>[];
1395
- icon_url?: string;
1993
+ /** Human-readable display name (always present). */
1994
+ display_name: string;
1995
+ /** Human-readable description (always present). */
1996
+ description: string;
1997
+ /** Logo URL, if any. */
1998
+ logo?: string | null;
1999
+ /** Marketing / app URL, if any. */
2000
+ app_url?: string | null;
2001
+ /** Documentation URL, if any. */
2002
+ docs_url?: string | null;
2003
+ /** Categories this integration belongs to. */
2004
+ categories?: string[];
2005
+ /** Integration type (e.g. `"tool"`, `"llm_provider"`, `"knowledge_provider"`). */
2006
+ integration_type: string;
2007
+ /** Integration version, if any. */
2008
+ version?: string | null;
2009
+ /** Lifecycle status (e.g. `"active"`). */
2010
+ status?: string;
2011
+ /** Whether this integration is recommended. */
2012
+ recommended?: boolean;
2013
+ /** Tool action descriptors (present only when details are included). */
2014
+ actions?: Record<string, unknown>[];
2015
+ /** LLM provider model descriptors (present only when details are included). */
2016
+ models?: Record<string, unknown>[];
2017
+ /** Auth requirement descriptors (present only when details are included). */
2018
+ auth_schemas?: AuthSchema[];
1396
2019
  [key: string]: unknown;
1397
2020
  }
1398
2021
  /**
1399
- * Detailed tool integration response including action definitions.
1400
- */
1401
- interface ToolIntegrationResponse {
1402
- integration_name: string;
1403
- display_name?: string;
1404
- description?: string;
1405
- /** Map of action name to action descriptor. */
1406
- actions?: Record<string, unknown>;
1407
- auth_types?: string[];
2022
+ * Authentication schema descriptor as returned by detail endpoints.
2023
+ *
2024
+ * For `oauth2` schemas the backend enriches the descriptor with the
2025
+ * `supports_modulex_oauth` / `supports_custom_oauth` boolean flags.
2026
+ */
2027
+ interface AuthSchema {
2028
+ /** Auth type discriminator (e.g. `"api_key"`, `"oauth2"`). */
2029
+ auth_type?: string;
2030
+ /** Whether ModuleX-managed OAuth is available for this provider (oauth2 only). */
2031
+ supports_modulex_oauth?: boolean;
2032
+ /** Whether custom OAuth credentials are supported (oauth2 only). */
2033
+ supports_custom_oauth?: boolean;
1408
2034
  [key: string]: unknown;
1409
2035
  }
1410
2036
  /**
1411
- * Detailed LLM provider response including available models.
2037
+ * Detailed integration information as returned by the detail endpoints
2038
+ * (`/integrations/{integration_name}`, `/integrations/tools/{name}`,
2039
+ * `/integrations/llm-providers/{name}`, `/integrations/knowledge-providers/{name}`).
2040
+ *
2041
+ * Mirrors the backend `IntegrationDetail` model. Wire field names are
2042
+ * snake_case and are returned as-is by the client (no camelCase conversion).
1412
2043
  */
1413
- interface LLMProviderResponse {
1414
- provider_name: string;
1415
- display_name?: string;
2044
+ interface IntegrationDetail {
2045
+ /** Canonical integration name / identifier. */
2046
+ name: string;
2047
+ /** Human-readable display name (always present). */
2048
+ display_name: string;
2049
+ /** Human-readable description (always present). */
2050
+ description: string;
2051
+ /** Logo URL, if any. */
2052
+ logo?: string | null;
2053
+ /** Marketing / app URL, if any. */
2054
+ app_url?: string | null;
2055
+ /** Documentation URL, if any. */
2056
+ docs_url?: string | null;
2057
+ /** Categories this integration belongs to. */
2058
+ categories?: string[];
2059
+ /** Integration type (e.g. `"tool"`, `"llm_provider"`, `"knowledge_provider"`). */
2060
+ integration_type: string;
2061
+ /** Integration version, if any. */
2062
+ version?: string | null;
2063
+ /** Auth requirement descriptors (OAuth-enriched where applicable). */
2064
+ auth_schemas?: AuthSchema[];
2065
+ /** Tool action descriptors (for tools). */
2066
+ actions?: Record<string, unknown>[];
2067
+ /** LLM provider model descriptors (for LLM providers). */
1416
2068
  models?: Record<string, unknown>[];
1417
- auth_types?: string[];
2069
+ /** Supported feature flags, if any. */
2070
+ features?: string[] | null;
2071
+ /** Arbitrary provider-specific metadata, if any. */
2072
+ metadata?: Record<string, unknown> | null;
1418
2073
  [key: string]: unknown;
1419
2074
  }
1420
2075
  /**
1421
- * Detailed knowledge provider response including supported collection features.
2076
+ * Response from the catalog browse endpoint (`/integrations/browse`).
2077
+ *
2078
+ * Mirrors the backend `BrowseResponse` model. The `integrations` array
2079
+ * carries `IntegrationMetadata` elements (not full details).
1422
2080
  */
1423
- interface KnowledgeProviderResponse {
1424
- provider_name: string;
1425
- display_name?: string;
1426
- auth_types?: string[];
1427
- [key: string]: unknown;
2081
+ interface BrowseResponse {
2082
+ /** Catalog entries for the current page. */
2083
+ integrations: IntegrationMetadata[];
2084
+ /** Total number of matching integrations across all pages. */
2085
+ total: number;
2086
+ /** Current page number (always present). */
2087
+ page: number;
2088
+ /** Page size (always present). */
2089
+ page_size: number;
2090
+ /** Whether more pages are available after the current one. */
2091
+ has_more: boolean;
1428
2092
  }
2093
+ /**
2094
+ * Generic integration detail as returned by `/integrations/{integration_name}`.
2095
+ *
2096
+ * Backend `response_model=IntegrationDetail`.
2097
+ */
2098
+ type IntegrationResponse = IntegrationDetail;
2099
+ /**
2100
+ * Detailed tool integration response, including action definitions, as
2101
+ * returned by `/integrations/tools/{integration_name}`.
2102
+ *
2103
+ * Backend `response_model=IntegrationDetail` (`actions` populated).
2104
+ */
2105
+ type ToolIntegrationResponse = IntegrationDetail;
2106
+ /**
2107
+ * Detailed LLM provider response, including available models, as returned by
2108
+ * `/integrations/llm-providers/{provider_name}`.
2109
+ *
2110
+ * Backend `response_model=IntegrationDetail` (`models` populated).
2111
+ */
2112
+ type LLMProviderResponse = IntegrationDetail;
2113
+ /**
2114
+ * Detailed knowledge provider response as returned by
2115
+ * `/integrations/knowledge-providers/{provider_name}`.
2116
+ *
2117
+ * Backend `response_model=IntegrationDetail`.
2118
+ */
2119
+ type KnowledgeProviderResponse = IntegrationDetail;
1429
2120
 
1430
2121
  /**
1431
2122
  * Types for knowledge base management, document ingestion, and semantic search.
@@ -1433,16 +2124,26 @@ interface KnowledgeProviderResponse {
1433
2124
  */
1434
2125
  /**
1435
2126
  * Configuration for the embedding model used to vectorize documents and queries.
2127
+ *
2128
+ * The backend stores `embedding_config` as a free-form object, but the keys it
2129
+ * actually reads are `credential_id` and `model_id`. Field names here are kept
2130
+ * in snake_case to match the wire shape the embedding pipeline consumes.
1436
2131
  */
1437
2132
  interface EmbeddingConfig {
1438
- /** Credential ID for the embedding provider. */
1439
- provider_credential_id?: string;
2133
+ /**
2134
+ * Credential ID for the embedding provider. This is the key the backend
2135
+ * reads (`embedding_config.credential_id`); the embedding pipeline uses it
2136
+ * to resolve provider authentication.
2137
+ */
2138
+ credential_id?: string;
1440
2139
  /** Provider name (e.g. `"openai"`, `"cohere"`). */
1441
2140
  provider?: string;
1442
2141
  /** Model identifier (e.g. `"text-embedding-3-small"`). */
1443
- model?: string;
2142
+ model_id?: string;
1444
2143
  /** Expected vector dimension for the model. */
1445
2144
  dimension?: number;
2145
+ /** Allow additional provider-specific configuration keys. */
2146
+ [key: string]: unknown;
1446
2147
  }
1447
2148
  /**
1448
2149
  * Configuration for how documents are split into chunks before indexing.
@@ -1452,8 +2153,13 @@ interface ChunkingConfig {
1452
2153
  strategy?: string;
1453
2154
  /** Target token/character count per chunk. */
1454
2155
  chunk_size?: number;
1455
- /** Overlap in tokens/characters between consecutive chunks. */
1456
- overlap?: number;
2156
+ /**
2157
+ * Overlap in tokens/characters between consecutive chunks.
2158
+ *
2159
+ * Wire field name is `chunk_overlap` — the embedding pipeline reads this key.
2160
+ * (Previously named `overlap`, which the backend silently dropped.)
2161
+ */
2162
+ chunk_overlap?: number;
1457
2163
  /** Custom separator strings used by recursive/sentence strategies. */
1458
2164
  separators?: string[];
1459
2165
  }
@@ -1488,14 +2194,24 @@ interface KnowledgeBaseResponse {
1488
2194
  name: string;
1489
2195
  description: string | null;
1490
2196
  organization_id: string;
2197
+ /** User ID of the member who created the knowledge base. */
2198
+ created_by_user_id: string;
2199
+ /** Credential ID associated with the knowledge base, if any. */
2200
+ credential_id: string | null;
1491
2201
  embedding_config: EmbeddingConfig;
1492
2202
  chunking_config: ChunkingConfig;
2203
+ /** Number of documents in the knowledge base. Always present. */
2204
+ document_count: number;
2205
+ /** Total number of indexed chunks. Always present. */
2206
+ total_chunks: number;
2207
+ /** Total number of tokens across all chunks. Always present. */
2208
+ total_tokens: number;
1493
2209
  /** Lifecycle status (e.g. `"active"`, `"building"`, `"error"`). */
1494
2210
  status: string;
1495
- document_count?: number;
1496
- total_chunks?: number;
1497
- created_at: string;
1498
- updated_at: string;
2211
+ created_at: string | null;
2212
+ updated_at: string | null;
2213
+ /** Optional aggregated statistics for the knowledge base. */
2214
+ stats?: Record<string, unknown> | null;
1499
2215
  }
1500
2216
  /**
1501
2217
  * Query parameters for listing knowledge bases.
@@ -1505,21 +2221,22 @@ interface KnowledgeBaseListParams {
1505
2221
  limit?: number;
1506
2222
  offset?: number;
1507
2223
  }
1508
- /**
1509
- * Paginated list of knowledge bases.
1510
- */
1511
- interface KnowledgeBaseListResponse {
1512
- knowledge_bases: KnowledgeBaseResponse[];
1513
- total: number;
1514
- limit: number;
1515
- offset: number;
1516
- }
1517
2224
  /**
1518
2225
  * Aggregated statistics across all knowledge bases in an organization.
1519
- * The shape is extensible; provider-specific fields may be present.
2226
+ *
2227
+ * Mirrors the backend `OrganizationStatsResponse` shape.
1520
2228
  */
1521
2229
  interface KnowledgeBaseStatsResponse {
1522
- [key: string]: unknown;
2230
+ /** Number of knowledge bases in the organization. */
2231
+ knowledge_base_count: number;
2232
+ /** Total number of documents across all knowledge bases. */
2233
+ total_documents: number;
2234
+ /** Total number of indexed chunks across all knowledge bases. */
2235
+ total_chunks: number;
2236
+ /** Total number of tokens across all knowledge bases. */
2237
+ total_tokens: number;
2238
+ /** Combined byte size of all stored files. */
2239
+ total_file_size_bytes: number;
1523
2240
  }
1524
2241
  /**
1525
2242
  * A document record as returned by the API.
@@ -1529,13 +2246,17 @@ interface DocumentResponse {
1529
2246
  knowledge_base_id: string;
1530
2247
  filename: string;
1531
2248
  file_type: string;
1532
- file_size: number;
1533
- /** Processing status (e.g. `"pending"`, `"processing"`, `"ready"`, `"error"`). */
2249
+ /** Size of the source file in bytes. */
2250
+ file_size_bytes: number | null;
2251
+ /** Processing status: `"pending"`, `"processing"`, `"completed"`, or `"failed"`. */
1534
2252
  status: string;
1535
- metadata?: Record<string, unknown>;
1536
- chunk_count?: number;
1537
- created_at: string;
1538
- updated_at: string;
2253
+ /** Number of chunks produced from this document. */
2254
+ chunk_count: number;
2255
+ /** Number of tokens across this document's chunks. */
2256
+ token_count: number;
2257
+ /** Error message if processing failed; `null` otherwise. */
2258
+ error_message: string | null;
2259
+ created_at: string | null;
1539
2260
  }
1540
2261
  /**
1541
2262
  * Query parameters for listing documents within a knowledge base.
@@ -1557,20 +2278,43 @@ interface UploadDocumentParams {
1557
2278
  metadata?: Record<string, unknown>;
1558
2279
  }
1559
2280
  /**
1560
- * Status and progress of a document being processed.
2281
+ * Processing status of a document.
2282
+ *
2283
+ * This endpoint has no `response_model`; it returns the raw service dict.
2284
+ * `document_id`, `status`, `filename`, and `file_type` are always present.
2285
+ * The remaining fields are conditional on `status`.
1561
2286
  */
1562
2287
  interface DocumentStatusResponse {
2288
+ document_id: string;
2289
+ /** Processing status: `"pending"`, `"processing"`, `"completed"`, or `"failed"`. */
1563
2290
  status: string;
1564
- /** Processing progress as a fraction (0–1). */
1565
- progress?: number;
1566
- error?: string;
2291
+ filename: string;
2292
+ file_type: string;
2293
+ /** Human-readable status message. */
2294
+ message?: string;
2295
+ /** Present only when `status` is `"processing"`. */
2296
+ processing_started_at?: string | null;
2297
+ /** Present only when `status` is `"completed"`. */
2298
+ processing_completed_at?: string | null;
2299
+ /** Present only when `status` is `"completed"`. */
2300
+ chunk_count?: number;
2301
+ /** Present only when `status` is `"completed"`. */
2302
+ token_count?: number;
2303
+ /** Present only when `status` is `"failed"`. */
2304
+ error?: string | null;
1567
2305
  }
1568
2306
  /**
1569
2307
  * A single document chunk as returned by the chunks endpoint or a search result.
1570
2308
  */
1571
2309
  interface ChunkResponse {
1572
2310
  id: string;
2311
+ /** ID of the document this chunk belongs to. */
2312
+ document_id?: string;
2313
+ /** Position of this chunk within its document. */
2314
+ chunk_index?: number;
1573
2315
  content: string;
2316
+ /** Number of tokens in this chunk. */
2317
+ token_count?: number;
1574
2318
  metadata?: Record<string, unknown>;
1575
2319
  /** Similarity score (0–1). Present only in search results. */
1576
2320
  score?: number;
@@ -1601,22 +2345,35 @@ interface SearchParams {
1601
2345
  includeMetadata?: boolean;
1602
2346
  }
1603
2347
  /**
1604
- * A single search result entry.
2348
+ * A single search match entry.
2349
+ *
2350
+ * `content` and `metadata` are present only when the request enabled
2351
+ * `includeContent` / `includeMetadata` (both default to `true`).
1605
2352
  */
1606
- interface SearchResult {
2353
+ interface SearchMatch {
1607
2354
  chunk_id: string;
1608
- content: string;
1609
- score: number;
1610
- metadata: Record<string, unknown>;
1611
2355
  document_id: string;
2356
+ /** Filename of the document the matching chunk belongs to. */
2357
+ document_filename: string;
2358
+ /** Position of the matching chunk within its document. */
2359
+ chunk_index: number;
2360
+ score: number;
2361
+ /** Chunk content; omitted when `includeContent` is `false`. */
2362
+ content?: string;
2363
+ /** Chunk metadata; omitted when `includeMetadata` is `false`. */
2364
+ metadata?: Record<string, unknown>;
1612
2365
  }
1613
2366
  /**
1614
2367
  * Response from a knowledge base search.
2368
+ *
2369
+ * Returned by `search`, `searchMultiple`, and `hybridSearch`.
1615
2370
  */
1616
2371
  interface SearchResponse {
1617
- results: SearchResult[];
1618
2372
  query: string;
1619
- total: number;
2373
+ knowledge_base_id: string;
2374
+ top_k: number;
2375
+ total_matches: number;
2376
+ matches: SearchMatch[];
1620
2377
  }
1621
2378
  /**
1622
2379
  * Parameters for searching across multiple knowledge bases simultaneously.
@@ -1697,14 +2454,12 @@ interface CreateScheduleParams {
1697
2454
  * All fields are optional; only provided fields are updated.
1698
2455
  */
1699
2456
  interface UpdateScheduleParams {
1700
- workflowId?: string;
1701
2457
  name?: string;
1702
2458
  description?: string;
1703
2459
  scheduleType?: 'interval' | 'cron';
1704
2460
  intervalSeconds?: number;
1705
2461
  cronExpression?: string;
1706
2462
  timezone?: string;
1707
- isActive?: boolean;
1708
2463
  input?: Record<string, unknown>;
1709
2464
  config?: Record<string, unknown>;
1710
2465
  }
@@ -1714,6 +2469,8 @@ interface UpdateScheduleParams {
1714
2469
  interface ScheduleResponse {
1715
2470
  id: string;
1716
2471
  workflow_id: string;
2472
+ /** Organization that owns this schedule. */
2473
+ organization_id: string;
1717
2474
  name: string;
1718
2475
  description: string | null;
1719
2476
  schedule_type: 'interval' | 'cron';
@@ -1721,14 +2478,23 @@ interface ScheduleResponse {
1721
2478
  cron_expression?: string | null;
1722
2479
  /** IANA timezone name. */
1723
2480
  timezone: string;
2481
+ /** State input passed to the workflow on each scheduled run. Always present (defaults to `{}`). */
2482
+ input: Record<string, unknown>;
2483
+ /** Runtime config overrides applied to each scheduled run. Always present (defaults to `{}`). */
2484
+ config: Record<string, unknown>;
1724
2485
  is_active: boolean;
1725
- input?: Record<string, unknown> | null;
1726
- config?: Record<string, unknown> | null;
1727
2486
  next_run_at?: string | null;
1728
2487
  last_run_at?: string | null;
2488
+ /** Status of the most recent run, or `null` if the schedule has never run. */
2489
+ last_run_status?: string | null;
2490
+ /** Total number of runs recorded for this schedule. */
2491
+ total_runs: number;
2492
+ /** Number of runs that completed successfully. */
2493
+ successful_runs: number;
2494
+ /** Number of runs that failed. */
2495
+ failed_runs: number;
1729
2496
  created_at: string;
1730
2497
  updated_at: string;
1731
- created_by: string;
1732
2498
  }
1733
2499
  /**
1734
2500
  * Query parameters for listing schedules.
@@ -1754,12 +2520,28 @@ interface ScheduleListResponse {
1754
2520
  interface ScheduleRunResponse {
1755
2521
  id: string;
1756
2522
  schedule_id: string;
2523
+ /** Workflow executed by this run, or `null` if not associated. */
2524
+ workflow_id?: string | null;
2525
+ /** Underlying execution run identifier, or `null`. */
2526
+ run_id?: string | null;
2527
+ /** Thread identifier for the run, or `null`. */
2528
+ thread_id?: string | null;
2529
+ /** Time the run was scheduled to execute. */
2530
+ scheduled_at: string;
2531
+ /** Time the run actually started, or `null` if it has not started. */
2532
+ started_at?: string | null;
2533
+ completed_at?: string | null;
2534
+ /** Run duration in seconds, or `null` if unavailable. */
2535
+ duration_seconds?: number | null;
1757
2536
  /** Run status (e.g. `"completed"`, `"failed"`, `"running"`). */
1758
2537
  status: string;
1759
- started_at: string;
1760
- completed_at?: string | null;
1761
- error?: string | null;
1762
- duration_ms?: number | null;
2538
+ /** Failure message when the run failed, or `null`. */
2539
+ error_message?: string | null;
2540
+ /** How the run was triggered (e.g. `"scheduler"`, `"manual"`). */
2541
+ triggered_by: string;
2542
+ /** Deployment used for the run, or `null`. */
2543
+ deployment_id?: string | null;
2544
+ created_at: string;
1763
2545
  }
1764
2546
  /**
1765
2547
  * Query parameters for listing runs belonging to a schedule.
@@ -1769,6 +2551,15 @@ interface ScheduleRunListParams {
1769
2551
  limit?: number;
1770
2552
  offset?: number;
1771
2553
  }
2554
+ /**
2555
+ * Paginated list of scheduled runs.
2556
+ */
2557
+ interface ScheduleRunListResponse {
2558
+ runs: ScheduleRunResponse[];
2559
+ total: number;
2560
+ limit: number;
2561
+ offset: number;
2562
+ }
1772
2563
  /**
1773
2564
  * Query parameters for fetching aggregate run statistics.
1774
2565
  */
@@ -1780,120 +2571,145 @@ interface ScheduleRunStatsParams {
1780
2571
  * Aggregate run statistics for a schedule.
1781
2572
  */
1782
2573
  interface ScheduleRunStatsResponse {
2574
+ /** Number of past days covered by this stats window. */
2575
+ period_days: number;
1783
2576
  total_runs: number;
1784
2577
  successful_runs: number;
1785
2578
  failed_runs: number;
1786
- average_duration_ms: number;
1787
- }
1788
-
1789
- /**
1790
- * Types for workflow templates and creator profiles.
1791
- * @module types/templates
1792
- */
1793
-
1794
- /**
1795
- * Public profile information for a template creator.
1796
- */
1797
- interface CreatorInfo {
1798
- name: string;
1799
- display_photo?: string | null;
1800
- about?: string | null;
1801
- /** Map of social platform name to profile URL. */
1802
- socials?: Record<string, string>;
1803
- }
1804
- /**
1805
- * A template record as returned by the API.
1806
- */
1807
- interface TemplateResponse {
1808
- id: string;
1809
- creator_id: string;
1810
- creator?: CreatorInfo | null;
1811
- name: string;
1812
- description: string | null;
1813
- tags: string[];
1814
- workflow_schema: WorkflowDefinition;
1815
- input?: Record<string, unknown> | null;
1816
- config?: Record<string, unknown> | null;
1817
- schema_image_url?: string | null;
1818
- /** Sharing visibility (e.g. `"private"`, `"public"`). */
1819
- visibility: string;
1820
- /** Lifecycle status (e.g. `"draft"`, `"published"`). */
1821
- status: string;
1822
- like_count: number;
1823
- used_count: number;
1824
- /** Whether the authenticated user has liked this template. */
1825
- is_liked?: boolean;
1826
- edit_version?: number | null;
1827
- created_at: string;
1828
- updated_at: string;
2579
+ /** Fraction of runs that succeeded (0.0–1.0). */
2580
+ success_rate: number;
2581
+ /** Average run duration in seconds, or `null` if no runs. */
2582
+ avg_duration_seconds?: number | null;
2583
+ /** Minimum run duration in seconds, or `null` if no runs. */
2584
+ min_duration_seconds?: number | null;
2585
+ /** Maximum run duration in seconds, or `null` if no runs. */
2586
+ max_duration_seconds?: number | null;
1829
2587
  }
1830
2588
  /**
1831
- * Response from the public template browse endpoint.
2589
+ * Response returned when retrying a scheduled run.
1832
2590
  */
1833
- interface TemplateListResponse {
1834
- templates: TemplateResponse[];
1835
- /** Whether the response was served from cache. */
1836
- cached?: boolean;
2591
+ interface RetryRunResponse {
2592
+ message: string;
2593
+ /** Identifier of the original run that was retried. */
2594
+ original_run_id: string;
1837
2595
  }
1838
2596
  /**
1839
- * Response from listing templates created by the authenticated user.
2597
+ * Response returned when deleting a schedule.
1840
2598
  */
1841
- interface MyTemplatesResponse {
1842
- templates: TemplateResponse[];
1843
- total: number;
2599
+ interface DeleteScheduleResponse {
2600
+ message: string;
1844
2601
  }
2602
+
1845
2603
  /**
1846
- * Parameters for publishing a workflow as a template.
1847
- */
1848
- interface CreateTemplateParams {
1849
- /** ID of the saved workflow to publish as a template. */
1850
- workflowId: string;
1851
- name?: string;
2604
+ * Human-in-the-Loop (HITL) wire contract discriminated unions for structured
2605
+ * questions the agent asks (`UserInputRequest`) and the answers the client sends
2606
+ * back on resume (`UserInputResponse`).
2607
+ *
2608
+ * Shared by the Composer and Assistant resources. Mirrors the backend
2609
+ * `app/models/composer_events.py`. Discriminate on the `kind` field.
2610
+ * @module types/hitl
2611
+ */
2612
+ /** A selectable option in a single/multi choice question. */
2613
+ interface ChoiceOption {
2614
+ value: string;
2615
+ label: string;
1852
2616
  description?: string;
1853
- tags?: string[];
1854
- /** URL to a preview image of the workflow canvas. */
1855
- schemaImageUrl?: string;
2617
+ icon?: string;
2618
+ badge?: string;
1856
2619
  }
1857
- /**
1858
- * Response from using (importing) a template into the user's workspace.
1859
- */
1860
- interface TemplateUseResponse {
1861
- success: boolean;
2620
+ /** One way to authenticate when answering a credential request. */
2621
+ interface CredentialAuthOption {
2622
+ auth_type: 'oauth2' | 'api_key' | 'bearer_token' | 'modulex_key' | 'custom';
2623
+ display_name: string;
2624
+ fields?: Record<string, unknown>[];
2625
+ oauth_initiate_endpoint?: string;
2626
+ setup_instructions?: string[];
2627
+ test_supported: boolean;
2628
+ }
2629
+ /** Fields common to every user-input request. */
2630
+ interface UserInputRequestBase {
2631
+ request_id: string;
2632
+ /** Markdown-supported prompt shown to the user. */
1862
2633
  message: string;
1863
- /** The newly created workflow in the user's workspace. */
1864
- workflow: WorkflowResponse;
1865
- used_count: number;
2634
+ /** Whether the user is allowed to skip. */
2635
+ required: boolean;
2636
+ /** Escape hatch: allow a "write your own" answer. */
2637
+ allow_free_text: boolean;
2638
+ context?: Record<string, unknown> | null;
2639
+ timeout_hint_seconds?: number | null;
2640
+ }
2641
+ interface SingleChoiceRequest extends UserInputRequestBase {
2642
+ kind: 'single_choice';
2643
+ options: ChoiceOption[];
2644
+ }
2645
+ interface MultiChoiceRequest extends UserInputRequestBase {
2646
+ kind: 'multi_choice';
2647
+ options: ChoiceOption[];
2648
+ min_selections: number;
2649
+ max_selections?: number | null;
2650
+ }
2651
+ interface YesNoRequest extends UserInputRequestBase {
2652
+ kind: 'yes_no';
2653
+ yes_label: string;
2654
+ no_label: string;
2655
+ }
2656
+ interface FreeTextRequest extends UserInputRequestBase {
2657
+ kind: 'free_text';
2658
+ placeholder?: string | null;
2659
+ multiline: boolean;
2660
+ min_length: number;
2661
+ max_length?: number | null;
2662
+ }
2663
+ interface CredentialRequest extends UserInputRequestBase {
2664
+ kind: 'credential_request';
2665
+ integration_name: string;
2666
+ integration_display_name: string;
2667
+ integration_logo?: string | null;
2668
+ auth_options: CredentialAuthOption[];
2669
+ pending_node_name?: string | null;
2670
+ }
2671
+ /** A structured question the agent asks while paused. Discriminate on `kind`. */
2672
+ type UserInputRequest = SingleChoiceRequest | MultiChoiceRequest | YesNoRequest | FreeTextRequest | CredentialRequest;
2673
+ interface SingleChoiceResponse {
2674
+ kind: 'single_choice';
2675
+ selected_value?: string;
2676
+ free_text?: string;
2677
+ }
2678
+ interface MultiChoiceResponse {
2679
+ kind: 'multi_choice';
2680
+ selected_values: string[];
2681
+ }
2682
+ interface YesNoResponse {
2683
+ kind: 'yes_no';
2684
+ answer: boolean;
2685
+ }
2686
+ interface FreeTextResponse {
2687
+ kind: 'free_text';
2688
+ text: string;
2689
+ }
2690
+ interface CredentialAddedResponse {
2691
+ kind: 'credential_added';
2692
+ credential_id: string;
2693
+ integration_name: string;
2694
+ auth_type: string;
1866
2695
  }
1867
- /**
1868
- * Response from liking or un-liking a template.
1869
- */
1870
- interface TemplateLikeResponse {
1871
- success: boolean;
1872
- /** `true` if the template is now liked, `false` if the like was removed. */
1873
- liked: boolean;
1874
- like_count: number;
2696
+ /** Reason codes for a failed credential attempt. */
2697
+ type CredentialFailureCode = 'oauth_denied' | 'oauth_provider_error' | 'invalid_credentials' | 'network_error' | 'popup_closed' | 'timeout' | 'unknown';
2698
+ interface CredentialFailedResponse {
2699
+ kind: 'credential_failed';
2700
+ integration_name: string;
2701
+ auth_type: string;
2702
+ error_code: CredentialFailureCode;
2703
+ error_message: string;
2704
+ retryable?: boolean;
2705
+ provider_details?: Record<string, unknown> | null;
1875
2706
  }
1876
- /**
1877
- * Parameters for requesting an update to a published template.
1878
- */
1879
- interface UpdateTemplateRequestParams {
1880
- /** ID of the updated workflow to sync into the template. */
1881
- workflowId: string;
1882
- name?: string;
1883
- description?: string;
1884
- tags?: string[];
1885
- schemaImageUrl?: string;
1886
- }
1887
- /**
1888
- * Parameters for creating or updating a template creator profile.
1889
- */
1890
- interface CreateCreatorParams {
1891
- name: string;
1892
- about?: string;
1893
- displayPhoto?: string;
1894
- /** Map of social platform name to profile URL. */
1895
- socials?: Record<string, string>;
2707
+ interface SkippedResponse {
2708
+ kind: 'skipped';
2709
+ reason?: string;
1896
2710
  }
2711
+ /** The answer the client sends back to resume a paused run. Discriminate on `kind`. */
2712
+ type UserInputResponse = SingleChoiceResponse | MultiChoiceResponse | YesNoResponse | FreeTextResponse | CredentialAddedResponse | CredentialFailedResponse | SkippedResponse;
1897
2713
 
1898
2714
  /**
1899
2715
  * Types for the AI Composer — a chat-driven workflow builder.
@@ -1908,13 +2724,16 @@ interface ComposerChatParams {
1908
2724
  workflowId?: string;
1909
2725
  /** ID of an existing Composer chat to continue. Omit to start a new session. */
1910
2726
  composerChatId?: string;
1911
- /** The user's message to the Composer AI. */
2727
+ /** The user's message to the Composer AI (required). */
1912
2728
  message: string;
1913
- /** Override the LLM used by the Composer AI. */
2729
+ /** Override the LLM. Defaults to the organization's configured composer LLM. */
1914
2730
  llm?: LLMConfig;
1915
2731
  }
1916
2732
  /**
1917
2733
  * Response from starting or continuing a Composer chat session.
2734
+ *
2735
+ * Note: `POST /composer/chat` returns 409 if the chat has a pending HITL
2736
+ * question — answer it via `resume()` before sending a new message.
1918
2737
  */
1919
2738
  interface ComposerChatResponse {
1920
2739
  status: string;
@@ -1930,19 +2749,33 @@ interface ComposerChatResponse {
1930
2749
  */
1931
2750
  interface ComposerMessageResponse {
1932
2751
  id: string;
2752
+ /** Persisted roles are `human`/`ai`; `system` may appear for system entries. */
1933
2753
  role: 'human' | 'ai' | 'system';
1934
2754
  content: string;
2755
+ /** The agent's reasoning trace, when present. */
2756
+ thinking?: string | null;
2757
+ /** Workflow changes produced by this message, when present. */
2758
+ workflow_changes?: Record<string, unknown> | null;
2759
+ /** The run that produced this message, when applicable. */
2760
+ run_id?: string | null;
2761
+ /** Running status of this message, when applicable. */
2762
+ running_status?: string | null;
1935
2763
  created_at: string;
1936
2764
  }
1937
2765
  /**
1938
- * Full Composer chat detail including messages and workflow snapshot status.
2766
+ * Full Composer chat detail including messages and live HITL state.
1939
2767
  */
1940
2768
  interface ComposerChatDetailResponse {
1941
2769
  id: string;
1942
2770
  workflow_id: string | null;
2771
+ title: string;
1943
2772
  messages: ComposerMessageResponse[];
1944
- /** Whether there is a saved workflow snapshot associated with this chat. */
1945
- snapshot_status: string | null;
2773
+ /** The currently-running run ID, or null when idle. */
2774
+ running_id: string | null;
2775
+ /** IDs of every workflow this chat has touched. */
2776
+ touched_workflow_ids: string[];
2777
+ /** The open HITL question awaiting an answer, rehydrated, or null. */
2778
+ pending_user_input_request: UserInputRequest | null;
1946
2779
  /** Whether the AI has produced changes not yet saved to the workflow. */
1947
2780
  has_pending_changes: boolean;
1948
2781
  created_at: string;
@@ -1957,14 +2790,100 @@ interface ComposerStatusResponse {
1957
2790
  is_running: boolean;
1958
2791
  running_id: string | null;
1959
2792
  has_pending_changes: boolean;
1960
- /** Status of the most recent run attached to this Composer session. */
1961
- run_status: string | null;
2793
+ /** True when the run is paused on a HITL question (do NOT re-attach SSE). */
2794
+ awaiting_input: boolean;
2795
+ /** The pending HITL request id when `awaiting_input`, else null. */
2796
+ pending_request_id: string | null;
2797
+ /** The Redis status payload for the latest run, or null. */
2798
+ run_status: Record<string, unknown> | null;
2799
+ }
2800
+ /** Canvas-sync payload returned by save/revert so the client can refresh state. */
2801
+ interface ComposerWorkflowSync {
2802
+ workflow_id: string;
2803
+ edit_version: number;
2804
+ workflow: {
2805
+ nodes: unknown[];
2806
+ edges: unknown[];
2807
+ metadata: Record<string, unknown>;
2808
+ state_schema: Record<string, unknown>;
2809
+ };
2810
+ input: Record<string, unknown> | null;
2811
+ }
2812
+ /** Optional targeting body for save/revert (defaults to the chat's focused workflow). */
2813
+ interface ComposerSaveParams {
2814
+ /** Target a specific touched workflow instead of the focused one. */
2815
+ workflowId?: string;
2816
+ }
2817
+ /** Response from saving Composer changes. */
2818
+ interface ComposerSaveResponse {
2819
+ status: 'saved';
2820
+ workflow_id: string;
2821
+ workflow_name: string;
2822
+ message: string;
2823
+ workflow_sync: ComposerWorkflowSync | null;
2824
+ }
2825
+ /** Response from reverting Composer changes. */
2826
+ interface ComposerRevertResponse {
2827
+ status: 'reverted';
2828
+ workflow_id: string;
2829
+ workflow_name: string;
2830
+ message: string;
2831
+ workflow_sync: ComposerWorkflowSync | null;
1962
2832
  }
1963
2833
  /**
1964
- * Query parameters for listing Composer chat history.
2834
+ * Body for `POST /composer/chat/{id}/resume` — answers an open HITL question.
1965
2835
  */
1966
- interface ComposerHistoryParams {
2836
+ interface ComposerResumeParams {
2837
+ /** The `request_id` of the open question (from the `user_input_request` event). */
2838
+ requestId: string;
2839
+ /** The structured answer (discriminated on `kind`). */
2840
+ response: UserInputResponse;
2841
+ /**
2842
+ * LLM config used to rebuild the chat model on resume. Optional in the wire
2843
+ * schema, but required in production — the backend returns 400 if omitted.
2844
+ */
2845
+ llm?: LLMConfig;
2846
+ }
2847
+ /** Response from resuming a paused Composer run. */
2848
+ interface ComposerResumeResponse {
2849
+ status: 'resuming';
2850
+ composer_chat_id: string;
2851
+ /** A NEW run_id for the resumed execution. */
2852
+ run_id: string;
2853
+ thread_id: string;
2854
+ stream_url: string;
2855
+ }
2856
+ /** Body for `PATCH /composer/chat/{id}/focus`. `null` clears the focus. */
2857
+ interface ComposerFocusParams {
2858
+ /** The workflow to focus, or `null` to clear. The key must be present. */
2859
+ workflowId: string | null;
2860
+ }
2861
+ /** Response from changing a chat's focused workflow. */
2862
+ interface ComposerFocusResponse {
2863
+ composer_chat_id: string;
2864
+ workflow_id: string | null;
2865
+ updated_at: string;
2866
+ }
2867
+ /** Query parameters for listing the user's Composer chats. */
2868
+ interface ComposerListParams {
2869
+ /** Page size, 1–100 (default 20). */
1967
2870
  limit?: number;
2871
+ /** ISO `updated_at` timestamp cursor for the next page. */
2872
+ cursor?: string;
2873
+ }
2874
+ /** A row in the user's Composer chat list. */
2875
+ interface ComposerChatListItem {
2876
+ id: string;
2877
+ workflow_id: string | null;
2878
+ title: string;
2879
+ created_at: string;
2880
+ updated_at: string;
2881
+ is_running: boolean;
2882
+ }
2883
+ /** Cursor-paginated list of the user's Composer chats. */
2884
+ interface ComposerChatListResponse {
2885
+ items: ComposerChatListItem[];
2886
+ next_cursor: string | null;
1968
2887
  }
1969
2888
  /**
1970
2889
  * Parameters for deleting a Composer chat session.
@@ -1973,11 +2892,236 @@ interface ComposerDeleteParams {
1973
2892
  /** If `true`, also permanently delete the associated workflow. */
1974
2893
  permanent?: boolean;
1975
2894
  }
2895
+ /** Response from deleting a Composer chat session. */
2896
+ interface ComposerDeleteResponse {
2897
+ status: 'deleted';
2898
+ composer_chat_id: string;
2899
+ permanent: boolean;
2900
+ }
2901
+ /** Response from cancelling a Composer chat's in-progress run. */
2902
+ interface ComposerCancelResponse {
2903
+ status: 'cancelled';
2904
+ composer_chat_id: string;
2905
+ run_id: string;
2906
+ }
2907
+ /**
2908
+ * A Composer SSE frame. This is a data-only stream; discriminate on `type`.
2909
+ * The `user_input_request` frame carries the open HITL question — answer it
2910
+ * with `composer.resume()`.
2911
+ */
2912
+ type ComposerSSEEvent = ({
2913
+ type: 'metadata';
2914
+ } & Record<string, unknown>) | ({
2915
+ type: 'tool_call';
2916
+ } & Record<string, unknown>) | ({
2917
+ type: 'tool_result';
2918
+ } & Record<string, unknown>) | ({
2919
+ type: 'workflow_change';
2920
+ } & Record<string, unknown>) | ({
2921
+ type: 'response_chunk';
2922
+ } & Record<string, unknown>) | ({
2923
+ type: 'subagent_start';
2924
+ } & Record<string, unknown>) | {
2925
+ type: 'user_input_request';
2926
+ data: UserInputRequest;
2927
+ } | ({
2928
+ type: 'workflow_sync';
2929
+ } & Record<string, unknown>) | ({
2930
+ type: 'cancelled';
2931
+ } & Record<string, unknown>) | ({
2932
+ type: 'done';
2933
+ } & Record<string, unknown>) | ({
2934
+ type: 'error';
2935
+ } & Record<string, unknown>);
2936
+
2937
+ /**
2938
+ * Types for the Assistant — a chat agent with HITL, NOT bound to any workflow.
2939
+ *
2940
+ * Mirrors `/assistant` (app/api/assistant.py). Structurally similar to Composer
2941
+ * but with NO workflow fields (`workflow_id`/`snapshot_status`/`has_pending_changes`).
2942
+ * @module types/assistant
2943
+ */
2944
+
2945
+ /**
2946
+ * Parameters for starting a new Assistant chat or sending a message.
2947
+ */
2948
+ interface AssistantChatParams {
2949
+ /** The user's message (required; v1 is text-only). */
2950
+ message: string;
2951
+ /** ID of an existing Assistant chat to continue. Omit to start a new session. */
2952
+ chatId?: string;
2953
+ /** Override the LLM. Defaults to the organization's configured composer LLM. */
2954
+ llm?: LLMConfig;
2955
+ }
2956
+ /**
2957
+ * Response from starting or continuing an Assistant chat.
2958
+ *
2959
+ * Errors: 409 if the chat has a pending HITL question or a run is already in
2960
+ * progress; 402/403/429 at the billing gate.
2961
+ */
2962
+ interface AssistantChatResponse {
2963
+ status: string;
2964
+ chat_id: string;
2965
+ run_id: string;
2966
+ thread_id: string;
2967
+ /** `/assistant/chat/{chat_id}/listen/{run_id}` */
2968
+ stream_url: string;
2969
+ }
2970
+ /**
2971
+ * A single message within an Assistant chat.
2972
+ */
2973
+ interface AssistantMessageResponse {
2974
+ id: string;
2975
+ role: 'human' | 'ai' | 'system';
2976
+ content: string;
2977
+ /** The agent's reasoning trace, when present. */
2978
+ thinking?: string | null;
2979
+ run_id?: string | null;
2980
+ running_status?: string | null;
2981
+ created_at: string;
2982
+ }
2983
+ /**
2984
+ * Full Assistant chat detail including messages and any open HITL question.
2985
+ */
2986
+ interface AssistantChatDetailResponse {
2987
+ id: string;
2988
+ title: string | null;
2989
+ running_id: string | null;
2990
+ /** The open HITL question awaiting an answer, or null. */
2991
+ pending_user_input_request: UserInputRequest | null;
2992
+ messages: AssistantMessageResponse[];
2993
+ created_at: string;
2994
+ updated_at: string;
2995
+ }
2996
+ /**
2997
+ * Real-time status of an Assistant chat.
2998
+ */
2999
+ interface AssistantStatusResponse {
3000
+ chat_id: string;
3001
+ is_running: boolean;
3002
+ /** True when paused on a HITL question (do NOT re-attach SSE). */
3003
+ awaiting_input: boolean;
3004
+ pending_request_id: string | null;
3005
+ running_id: string | null;
3006
+ /** The Redis status payload for the latest run, or null. */
3007
+ run_status: Record<string, unknown> | null;
3008
+ }
3009
+ /**
3010
+ * Body for `POST /assistant/chat/{id}/resume` — answers an open HITL question.
3011
+ */
3012
+ interface AssistantResumeParams {
3013
+ /** The `request_id` of the open question (from the `user_input_request` event). */
3014
+ requestId: string;
3015
+ /** The structured answer (discriminated on `kind`). */
3016
+ response: UserInputResponse;
3017
+ /** LLM config to rebuild the chat model. Required by this endpoint (400 if omitted). */
3018
+ llm: LLMConfig;
3019
+ }
3020
+ /** Response from resuming a paused Assistant run. */
3021
+ interface AssistantResumeResponse {
3022
+ status: 'resuming';
3023
+ chat_id: string;
3024
+ /** A NEW run_id for the resumed execution. */
3025
+ run_id: string;
3026
+ thread_id: string;
3027
+ stream_url: string;
3028
+ }
3029
+ /** Query parameters for listing the user's Assistant chats. */
3030
+ interface AssistantListParams {
3031
+ /** Page size, 1–100 (default 20). */
3032
+ limit?: number;
3033
+ /** ISO `updated_at` timestamp cursor for the next page. */
3034
+ cursor?: string;
3035
+ }
3036
+ /** A row in the user's Assistant chat list. */
3037
+ interface AssistantChatSummary {
3038
+ id: string;
3039
+ title: string;
3040
+ created_at: string;
3041
+ updated_at: string;
3042
+ is_running: boolean;
3043
+ }
3044
+ /** Cursor-paginated list of the user's Assistant chats. */
3045
+ interface AssistantChatListResponse {
3046
+ items: AssistantChatSummary[];
3047
+ next_cursor: string | null;
3048
+ }
3049
+ /** Parameters for deleting an Assistant chat. */
3050
+ interface AssistantDeleteParams {
3051
+ /** `false` (default) soft-deletes; `true` hard-deletes the chat. */
3052
+ permanent?: boolean;
3053
+ }
3054
+ /** Response from deleting an Assistant chat. */
3055
+ interface AssistantDeleteResponse {
3056
+ status: 'deleted';
3057
+ chat_id: string;
3058
+ permanent: boolean;
3059
+ }
3060
+ /** Response from cancelling an Assistant run. `run_id` is the cancelled run. */
3061
+ interface AssistantCancelResponse {
3062
+ status: 'cancelled';
3063
+ chat_id: string;
3064
+ run_id: string;
3065
+ }
3066
+ /**
3067
+ * An Assistant SSE frame. Data-only stream; discriminate on `type`. The
3068
+ * `user_input_request` frame carries the open HITL question — answer it with
3069
+ * `assistant.resume()`. (No `workflow_change`/`workflow_sync` — Assistant has
3070
+ * no workflow.)
3071
+ */
3072
+ type AssistantSSEEvent = ({
3073
+ type: 'metadata';
3074
+ } & Record<string, unknown>) | ({
3075
+ type: 'response_chunk';
3076
+ } & Record<string, unknown>) | ({
3077
+ type: 'tool_call';
3078
+ } & Record<string, unknown>) | ({
3079
+ type: 'tool_result';
3080
+ } & Record<string, unknown>) | {
3081
+ type: 'user_input_request';
3082
+ data: UserInputRequest;
3083
+ } | ({
3084
+ type: 'run_resumed';
3085
+ } & Record<string, unknown>) | ({
3086
+ type: 'guidance';
3087
+ } & Record<string, unknown>) | ({
3088
+ type: 'done';
3089
+ } & Record<string, unknown>) | ({
3090
+ type: 'error';
3091
+ } & Record<string, unknown>) | ({
3092
+ type: 'cancelled';
3093
+ } & Record<string, unknown>) | ({
3094
+ type: 'heartbeat';
3095
+ } & Record<string, unknown>);
1976
3096
 
1977
3097
  /**
1978
3098
  * Types for the organization dashboard — activity logs, analytics, and user management.
1979
3099
  * @module types/dashboard
1980
3100
  */
3101
+ /**
3102
+ * Error envelope returned by dashboard endpoints. All five dashboard routes
3103
+ * return HTTP 200 even on failure, with `success: false` and this `error`
3104
+ * object (instead of the success-shaped `data`/`users`/`filters` keys).
3105
+ */
3106
+ interface DashboardErrorEnvelope {
3107
+ success: false;
3108
+ /** Machine-readable error code (e.g. `"AUDIT_LOGS_ERROR"`, `"ANALYTICS_ERROR"`, `"USER_ERROR"`). */
3109
+ error: {
3110
+ code: string;
3111
+ message: string;
3112
+ /** Stringified underlying exception detail. */
3113
+ details: string;
3114
+ };
3115
+ }
3116
+ /**
3117
+ * Per-organization monthly credit usage, embedded in several analytics payloads.
3118
+ */
3119
+ interface CurrentMonthCreditUsage {
3120
+ used_credit: number;
3121
+ max_credit: number;
3122
+ /** ISO-8601 timestamp of the next credit reset, or `null`. */
3123
+ next_reset_date: string | null;
3124
+ }
1981
3125
  /**
1982
3126
  * Query parameters for fetching organization activity logs.
1983
3127
  */
@@ -1994,20 +3138,22 @@ interface DashboardLogsParams {
1994
3138
  endDate?: string;
1995
3139
  }
1996
3140
  /**
1997
- * A single activity log entry.
3141
+ * A single activity (audit) log entry, as emitted by `GET /dashboard/logs`.
1998
3142
  */
1999
3143
  interface ActivityLogEntry {
2000
3144
  id: string;
3145
+ /** ISO-8601 timestamp of the audited event; `null` when unset. */
3146
+ audit_time?: string | null;
2001
3147
  category: string;
2002
3148
  operation: string;
2003
- user_id: string;
2004
- resource_id?: string | null;
2005
- resource_type?: string | null;
3149
+ /** Email of the acting user; `null` when the actor row is missing (outer join). */
3150
+ actor_email?: string | null;
3151
+ /** Human-readable description of the audited event. */
3152
+ message: string;
2006
3153
  metadata?: Record<string, unknown>;
2007
- created_at: string;
2008
3154
  }
2009
3155
  /**
2010
- * Pagination metadata embedded in log responses.
3156
+ * Pagination payload embedded in the logs response (offset-based).
2011
3157
  */
2012
3158
  interface LogsPaginationData {
2013
3159
  logs: ActivityLogEntry[];
@@ -2018,33 +3164,90 @@ interface LogsPaginationData {
2018
3164
  has_previous: boolean;
2019
3165
  }
2020
3166
  /**
2021
- * Response from the dashboard logs endpoint.
3167
+ * Concrete shape of the `filters` echo returned by the logs endpoint.
2022
3168
  */
2023
- interface DashboardLogsResponse {
2024
- success: boolean;
3169
+ interface DashboardLogsFilters {
3170
+ category: string | null;
3171
+ operation: string | null;
3172
+ /** ISO-8601 start date echoed back, or `null`. */
3173
+ start_date: string | null;
3174
+ /** ISO-8601 end date echoed back, or `null`. */
3175
+ end_date: string | null;
3176
+ }
3177
+ /**
3178
+ * Success response from the dashboard logs endpoint.
3179
+ */
3180
+ interface DashboardLogsSuccess {
3181
+ success: true;
2025
3182
  organization_id: string;
2026
3183
  data: LogsPaginationData;
2027
- filters: Record<string, unknown>;
3184
+ filters: DashboardLogsFilters;
2028
3185
  meta: Record<string, unknown>;
2029
3186
  }
3187
+ /**
3188
+ * Response from the dashboard logs endpoint — success or error envelope.
3189
+ */
3190
+ type DashboardLogsResponse = DashboardLogsSuccess | DashboardErrorEnvelope;
2030
3191
  /**
2031
3192
  * Query parameters for the analytics overview endpoint.
2032
3193
  */
2033
- interface AnalyticsOverviewParams {
2034
- limit?: number;
2035
- offset?: number;
3194
+ interface AnalyticsOverviewParams {
3195
+ limit?: number;
3196
+ offset?: number;
3197
+ }
3198
+ /**
3199
+ * Billing subscription window for the organization.
3200
+ */
3201
+ interface AnalyticsSubscription {
3202
+ /** ISO-8601 start of the current billing period (always present). */
3203
+ current_period_start: string;
3204
+ /** ISO-8601 end of the current billing period (always present). */
3205
+ current_period_end: string;
3206
+ }
3207
+ /**
3208
+ * A single credential-usage log row in the overview payload.
3209
+ *
3210
+ * Unlike the tools/LLM usage rows, overview rows include `auth_type`.
3211
+ */
3212
+ interface OverviewCredentialUsageLog {
3213
+ integration_name: string;
3214
+ service_name: string;
3215
+ /** Raw auth type of the credential (e.g. `"modulex_key"`, `"oauth2"`). */
3216
+ auth_type: string;
3217
+ credential_display_name: string | null;
3218
+ success: boolean;
3219
+ /** ISO-8601 execution timestamp; `null` when unset. */
3220
+ executed_at: string | null;
3221
+ /** Email of the executing user; `null` when the user row is missing (outer join). */
3222
+ user_email: string | null;
3223
+ }
3224
+ /**
3225
+ * Structured analytics overview payload.
3226
+ */
3227
+ interface AnalyticsOverview {
3228
+ active_member_count: number;
3229
+ configured_integrations_count: number;
3230
+ total_integrations_count: number;
3231
+ total_credentials_count: number;
3232
+ current_month_credit_usage: CurrentMonthCreditUsage;
3233
+ subscription: AnalyticsSubscription;
3234
+ credential_usage_logs: OverviewCredentialUsageLog[];
2036
3235
  }
2037
3236
  /**
2038
- * Response from the analytics overview endpoint.
3237
+ * Success response from the analytics overview endpoint.
2039
3238
  */
2040
- interface AnalyticsOverviewResponse {
2041
- success: boolean;
3239
+ interface AnalyticsOverviewSuccess {
3240
+ success: true;
2042
3241
  organization_id: string;
2043
3242
  data: {
2044
- overview: Record<string, unknown>;
3243
+ overview: AnalyticsOverview;
2045
3244
  };
2046
3245
  meta: Record<string, unknown>;
2047
3246
  }
3247
+ /**
3248
+ * Response from the analytics overview endpoint — success or error envelope.
3249
+ */
3250
+ type AnalyticsOverviewResponse = AnalyticsOverviewSuccess | DashboardErrorEnvelope;
2048
3251
  /**
2049
3252
  * Query parameters for the tools analytics endpoint.
2050
3253
  */
@@ -2055,30 +3258,120 @@ interface AnalyticsToolsParams {
2055
3258
  offset?: number;
2056
3259
  }
2057
3260
  /**
2058
- * Response from the tools analytics endpoint.
3261
+ * Most-used action within the requested period.
2059
3262
  */
2060
- interface AnalyticsToolsResponse {
2061
- success: boolean;
3263
+ interface MostUsedAction {
3264
+ action_name: string;
3265
+ integration_name: string;
3266
+ }
3267
+ /**
3268
+ * A single tool-usage log row.
3269
+ */
3270
+ interface ToolUsage {
3271
+ /** Email of the executing user; `null` when the user row is missing (outer join). */
3272
+ user_email: string | null;
3273
+ integration_name: string;
3274
+ action_name: string;
3275
+ /** ISO-8601 execution timestamp; `null` when unset. */
3276
+ executed_at: string | null;
3277
+ execution_duration_ms: number | null;
3278
+ /** Derived status from the underlying `success` boolean. */
3279
+ status: 'success' | 'error';
3280
+ /** Display name (`"Modulex Key"` for managed-key credentials), or `null`. */
3281
+ credential_display_name: string | null;
3282
+ }
3283
+ /**
3284
+ * Structured tools analytics payload.
3285
+ */
3286
+ interface AnalyticsToolsData {
3287
+ total_tool_executions: number;
3288
+ current_month_total_tool_executions: number;
3289
+ current_month_credit_usage: CurrentMonthCreditUsage;
3290
+ success_rate: number;
3291
+ /** Most used action in the period, or `null` when there is none. */
3292
+ most_used_action: MostUsedAction | null;
3293
+ configured_integrations_count: number;
3294
+ total_integrations_count: number;
3295
+ tool_usages: ToolUsage[];
3296
+ }
3297
+ /**
3298
+ * Success response from the tools analytics endpoint.
3299
+ */
3300
+ interface AnalyticsToolsSuccess {
3301
+ success: true;
2062
3302
  organization_id: string;
2063
- data: Record<string, unknown>;
3303
+ data: AnalyticsToolsData;
2064
3304
  meta: Record<string, unknown>;
2065
3305
  }
2066
3306
  /**
2067
- * Response from the LLM usage analytics endpoint.
3307
+ * Response from the tools analytics endpoint — success or error envelope.
2068
3308
  */
2069
- interface AnalyticsLLMUsageResponse {
2070
- success: boolean;
3309
+ type AnalyticsToolsResponse = AnalyticsToolsSuccess | DashboardErrorEnvelope;
3310
+ /**
3311
+ * Query parameters for the LLM usage analytics endpoint.
3312
+ *
3313
+ * Mirrors {@link AnalyticsToolsParams}; declared separately for clarity.
3314
+ */
3315
+ interface AnalyticsLLMUsageParams {
3316
+ /** Aggregation period (e.g. `"24h"`, `"7d"`, `"30d"`, `"90d"`). */
3317
+ period?: string;
3318
+ limit?: number;
3319
+ offset?: number;
3320
+ }
3321
+ /**
3322
+ * A single LLM-usage log row.
3323
+ *
3324
+ * Note the renamed keys relative to tool usage: `provider` (integration),
3325
+ * `model` (service), `request_time` (executed_at), `request_duration`
3326
+ * (execution_duration_ms).
3327
+ */
3328
+ interface LLMUsage {
3329
+ /** Email of the requesting user; `null` when the user row is missing (outer join). */
3330
+ user_email: string | null;
3331
+ provider: string;
3332
+ model: string;
3333
+ prompt_tokens: number;
3334
+ completion_tokens: number;
3335
+ /** ISO-8601 request timestamp; `null` when unset. */
3336
+ request_time: string | null;
3337
+ request_duration: number | null;
3338
+ /** Derived status from the underlying `success` boolean. */
3339
+ status: 'success' | 'error';
3340
+ /** Display name (`"Modulex Key"` for managed-key credentials), or `null`. */
3341
+ credential_display_name: string | null;
3342
+ }
3343
+ /**
3344
+ * Structured LLM usage analytics payload.
3345
+ */
3346
+ interface AnalyticsLLMUsageData {
3347
+ total_llm_call: number;
3348
+ current_month_total_llm_call: number;
3349
+ current_month_credit_usage: CurrentMonthCreditUsage;
3350
+ request_success_rate: number;
3351
+ total_completion_tokens: number;
3352
+ total_prompt_tokens: number;
3353
+ llm_usages: LLMUsage[];
3354
+ }
3355
+ /**
3356
+ * Success response from the LLM usage analytics endpoint.
3357
+ */
3358
+ interface AnalyticsLLMUsageSuccess {
3359
+ success: true;
2071
3360
  organization_id: string;
2072
- data: Record<string, unknown>;
3361
+ data: AnalyticsLLMUsageData;
2073
3362
  meta: Record<string, unknown>;
2074
3363
  }
3364
+ /**
3365
+ * Response from the LLM usage analytics endpoint — success or error envelope.
3366
+ */
3367
+ type AnalyticsLLMUsageResponse = AnalyticsLLMUsageSuccess | DashboardErrorEnvelope;
2075
3368
  /**
2076
3369
  * Query parameters for listing organization members from the dashboard.
2077
3370
  */
2078
3371
  interface DashboardUsersParams {
2079
3372
  search?: string;
2080
- /** Filter by member status (e.g. `"active"`, `"invited"`, `"suspended"`). */
2081
- status?: string;
3373
+ /** Filter by member status. Only `"active"` and `"inactive"` are honored by the backend. */
3374
+ status?: 'active' | 'inactive';
2082
3375
  /** Field to sort by (e.g. `"created_at"`, `"email"`). */
2083
3376
  sortBy?: string;
2084
3377
  /** Sort direction — `"asc"` or `"desc"`. */
@@ -2087,12 +3380,61 @@ interface DashboardUsersParams {
2087
3380
  limit?: number;
2088
3381
  }
2089
3382
  /**
2090
- * Response from the dashboard users endpoint.
3383
+ * A dashboard user row representing an active organization member.
2091
3384
  */
2092
- interface DashboardUsersResponse {
2093
- success: boolean;
3385
+ interface DashboardMemberUser {
3386
+ id: string;
3387
+ email: string;
3388
+ username: string | null;
3389
+ avatar: string | null;
3390
+ role: string;
3391
+ is_active: boolean;
3392
+ /** ISO-8601 creation timestamp; `null` when unset. */
3393
+ created_at: string | null;
3394
+ /** ISO-8601 last-update timestamp; `null` when unset. */
3395
+ updated_at: string | null;
3396
+ /** ISO-8601 last-active timestamp; `null` when unset. */
3397
+ last_active_at: string | null;
3398
+ current_month_credit_usage: number;
3399
+ }
3400
+ /**
3401
+ * A dashboard user row representing a pending invitation (prepended to the list).
3402
+ */
3403
+ interface DashboardInvitationUser {
3404
+ id: string;
3405
+ email: string;
3406
+ username: null;
3407
+ avatar: null;
3408
+ role: string;
3409
+ is_active: false;
3410
+ /** ISO-8601 creation timestamp; `null` when unset. */
3411
+ created_at: string | null;
3412
+ updated_at: null;
3413
+ last_active_at: null;
3414
+ current_month_credit_usage: number;
3415
+ /** Discriminant flag marking this row as an invitation. */
3416
+ is_invitation: true;
3417
+ /** Invitation status (e.g. `"pending"`, `"rejected"`, `"expired"`, `"canceled"`). */
3418
+ invitation_status: string;
3419
+ /** ISO-8601 expiry timestamp; `null` when unset. */
3420
+ invitation_expires_at: string | null;
3421
+ /** ID of the invited user if already registered, else `null`. */
3422
+ invited_user_id: string | null;
3423
+ /** ISO-8601 invitation timestamp; `null` when unset. */
3424
+ invited_at: string | null;
3425
+ }
3426
+ /**
3427
+ * A dashboard user row — either an active member or a pending invitation.
3428
+ * Discriminate on the optional `is_invitation` flag.
3429
+ */
3430
+ type DashboardUser = DashboardMemberUser | DashboardInvitationUser;
3431
+ /**
3432
+ * Success response from the dashboard users endpoint (page-based pagination).
3433
+ */
3434
+ interface DashboardUsersSuccess {
3435
+ success: true;
2094
3436
  organization_id: string;
2095
- users: Record<string, unknown>[];
3437
+ users: DashboardUser[];
2096
3438
  invitation_count: number;
2097
3439
  max_seats: number;
2098
3440
  total: number;
@@ -2102,131 +3444,185 @@ interface DashboardUsersResponse {
2102
3444
  has_next: boolean;
2103
3445
  has_previous: boolean;
2104
3446
  }
2105
-
2106
3447
  /**
2107
- * Types for subscription plans, billing, and payment portal management.
2108
- * @module types/subscriptions
3448
+ * Response from the dashboard users endpoint success or error envelope.
2109
3449
  */
3450
+ type DashboardUsersResponse = DashboardUsersSuccess | DashboardErrorEnvelope;
3451
+
2110
3452
  /**
2111
- * A single price option for a plan (monthly or yearly).
2112
- */
2113
- interface PlanPrice {
2114
- price: number;
2115
- /** Billing interval (e.g. `"month"`, `"year"`). */
2116
- interval: string;
2117
- /** ISO-4217 currency code (e.g. `"usd"`). */
2118
- currency: string;
2119
- }
2120
- /**
2121
- * A subscription plan available to organizations.
3453
+ * Types for organization notifications.
3454
+ * @module types/notifications
2122
3455
  */
2123
- interface Plan {
2124
- id: string;
2125
- name: string;
2126
- /** Display sort order on the pricing page. */
2127
- sort_order: number;
2128
- is_enterprise: boolean;
2129
- /** Discount percentage (0–100). */
2130
- discount: number;
2131
- prices: PlanPrice[];
2132
- /** List of feature descriptions included in this plan. */
2133
- features: string[];
2134
- /** Whether the plan can be self-selected (vs. sales-only). */
2135
- is_selectable?: boolean;
2136
- }
2137
- /**
2138
- * Response from listing available organization plans.
2139
- */
2140
- interface OrganizationPlansResponse {
2141
- plans: Plan[];
2142
- total: number;
2143
- }
2144
3456
  /**
2145
- * An active subscription record.
3457
+ * Topic of an organization notification.
3458
+ *
3459
+ * Mirrors the backend `notification_topic` enum for organization
3460
+ * notifications (`integration` | `attention`).
2146
3461
  */
2147
- interface Subscription {
2148
- id: string;
2149
- /** Stripe/payment-provider subscription status (e.g. `"active"`, `"past_due"`). */
2150
- status: string;
2151
- current_period_start: string;
2152
- current_period_end: string;
2153
- /** Current billing interval (`"month"` or `"year"`). */
2154
- billing_interval: string;
2155
- current_price: number;
2156
- created_at: string;
2157
- }
3462
+ type OrganizationNotificationTopic = 'integration' | 'attention';
2158
3463
  /**
2159
- * Billing information for an organization.
3464
+ * Topic of a system notification.
3465
+ *
3466
+ * Mirrors the backend `notification_topic` enum for system
3467
+ * notifications (`notice` | `incident` | `changelog`).
2160
3468
  */
2161
- interface BillingResponse {
2162
- has_subscription: boolean;
2163
- subscription?: Subscription;
2164
- plan?: Plan;
2165
- }
3469
+ type SystemNotificationTopic = 'notice' | 'incident' | 'changelog';
2166
3470
  /**
2167
- * Parameters for creating a Stripe Checkout session.
3471
+ * Fields shared by every notification variant returned from
3472
+ * `GET /notifications`.
2168
3473
  */
2169
- interface CheckoutParams {
2170
- planId: string;
2171
- interval: 'month' | 'year';
3474
+ interface NotificationBase {
3475
+ /** Unique identifier of the notification (or invitation) record. */
3476
+ id: string;
3477
+ /** Human-readable notification message. */
3478
+ message: string;
3479
+ /** ISO-8601 creation timestamp. May be null for some system/organization rows. */
3480
+ created_at: string | null;
3481
+ /** ISO-8601 expiration timestamp, or `null` when it never expires. */
3482
+ expires_at?: string | null;
2172
3483
  }
2173
3484
  /**
2174
- * Response from creating a Checkout session.
2175
- */
2176
- interface CheckoutResponse {
2177
- /** Stripe Checkout URL redirect the user here to complete payment. */
2178
- url: string;
3485
+ * An invitation surfaced through the notifications feed.
3486
+ *
3487
+ * Produced by the invitation branch of the backend notification service.
3488
+ * Note: invitation rows do **not** carry `notification_topic`,
3489
+ * `notification_url` or `notified_at`. `organization_id` may be `null`
3490
+ * because it is derived from the invitation's organization payload.
3491
+ */
3492
+ interface InvitationNotification extends NotificationBase {
3493
+ notification_type: 'invitation';
3494
+ /** Inviting organization id; may be `null` if unavailable. */
3495
+ organization_id?: string | null;
3496
+ /** Display name of the inviting organization. */
3497
+ organization_name: string;
3498
+ /** Role the user is invited to assume. */
3499
+ role: string;
3500
+ /** Email of the user who issued the invitation, when known. */
3501
+ invited_by_email?: string | null;
3502
+ /** Optional custom message attached to the invitation. */
3503
+ invitation_message?: string | null;
2179
3504
  }
2180
3505
  /**
2181
- * Response from creating a Stripe Customer Portal session.
2182
- */
2183
- interface PortalResponse {
2184
- /** Stripe Portal URL — redirect the user here to manage billing. */
2185
- url: string;
3506
+ * A system-wide notification.
3507
+ *
3508
+ * System notifications are not scoped to an organization, so they carry
3509
+ * **no** `organization_id` field.
3510
+ */
3511
+ interface SystemNotification extends NotificationBase {
3512
+ notification_type: 'system';
3513
+ /** System notification topic. */
3514
+ notification_topic: SystemNotificationTopic;
3515
+ /** Optional deep-link URL associated with the notification. */
3516
+ notification_url?: string | null;
3517
+ /** ISO-8601 timestamp of when the notification was emitted. */
3518
+ notified_at?: string | null;
2186
3519
  }
2187
-
2188
- /**
2189
- * Types for organization notifications.
2190
- * @module types/notifications
2191
- */
2192
3520
  /**
2193
- * A notification record as returned by the API.
3521
+ * An organization-scoped notification.
2194
3522
  */
2195
- interface NotificationResponse {
2196
- id: string;
3523
+ interface OrganizationNotification extends NotificationBase {
3524
+ notification_type: 'organization';
3525
+ /** Owning organization id (always present for this variant). */
2197
3526
  organization_id: string;
2198
- user_id: string | null;
2199
- notification_topic: string;
2200
- message: string;
3527
+ /** Organization notification topic. */
3528
+ notification_topic: OrganizationNotificationTopic;
3529
+ /** Optional deep-link URL associated with the notification. */
2201
3530
  notification_url?: string | null;
2202
- is_read: boolean;
2203
- expires_at?: string | null;
2204
- created_at: string;
2205
- updated_at: string;
3531
+ /** ISO-8601 timestamp of when the notification was emitted. */
3532
+ notified_at?: string | null;
3533
+ /**
3534
+ * `true` when the notification was broadcast to all org members
3535
+ * (i.e. `notified_to` was null), `false` when targeted at a user.
3536
+ */
3537
+ is_broadcast: boolean;
2206
3538
  }
2207
3539
  /**
2208
- * Response from listing notifications for an organization.
3540
+ * A notification record as returned by `GET /notifications`.
3541
+ *
3542
+ * This is a discriminated union keyed on `notification_type`. The backend
3543
+ * merges invitations, system notifications and organization notifications
3544
+ * into a single feed, so consumers should switch on `notification_type`
3545
+ * before accessing variant-specific fields.
3546
+ */
3547
+ type NotificationResponse = InvitationNotification | SystemNotification | OrganizationNotification;
3548
+ /**
3549
+ * Response from listing notifications for the current user / organization.
3550
+ *
3551
+ * `organization_id` reflects the resolved `X-Organization-ID` header and is
3552
+ * `null` when no (valid) organization context was supplied.
2209
3553
  */
2210
3554
  interface NotificationListResponse {
2211
3555
  success: boolean;
2212
3556
  notifications: NotificationResponse[];
2213
3557
  total: number;
2214
- organization_id: string;
3558
+ organization_id: string | null;
2215
3559
  }
2216
3560
  /**
2217
3561
  * Parameters for creating an organization notification.
3562
+ *
3563
+ * Backend validation constraints (not enforced client-side):
3564
+ * - `message`: 1-5000 characters.
3565
+ * - `notificationUrl`: at most 500 characters.
3566
+ * - `expiresAt`: must be a valid ISO-8601 datetime.
2218
3567
  */
2219
3568
  interface CreateNotificationParams {
2220
3569
  /** The category / channel for the notification. */
2221
- notificationTopic: 'integration' | 'attention';
3570
+ notificationTopic: OrganizationNotificationTopic;
3571
+ /** Notification message (1-5000 characters). */
2222
3572
  message: string;
2223
3573
  /** User ID to direct the notification to. Omit to send to all org members. */
2224
3574
  notifiedTo?: string;
2225
- /** Deep-link URL associated with the notification. */
3575
+ /** Deep-link URL associated with the notification (max 500 characters). */
2226
3576
  notificationUrl?: string;
2227
3577
  /** ISO-8601 datetime after which the notification should be hidden. */
2228
3578
  expiresAt?: string;
2229
3579
  }
3580
+ /**
3581
+ * The notification object echoed back by
3582
+ * `POST /notifications/organization` after creation.
3583
+ */
3584
+ interface CreatedNotification {
3585
+ id: string;
3586
+ organization_id: string;
3587
+ notification_topic: OrganizationNotificationTopic;
3588
+ message: string;
3589
+ notification_url?: string | null;
3590
+ created_at: string;
3591
+ notified_at: string;
3592
+ expires_at?: string | null;
3593
+ /** `true` when broadcast to all members, `false` when targeted. */
3594
+ is_broadcast: boolean;
3595
+ /** Target user id, or `null` for a broadcast notification. */
3596
+ notified_to?: string | null;
3597
+ }
3598
+ /**
3599
+ * Response envelope from `POST /notifications/organization`.
3600
+ */
3601
+ interface CreateNotificationResponse {
3602
+ success: boolean;
3603
+ notification: CreatedNotification;
3604
+ }
3605
+
3606
+ /**
3607
+ * Types for the System timezone endpoints.
3608
+ * @module types/system
3609
+ */
3610
+ /** A single selectable timezone option. */
3611
+ interface TimezoneOption {
3612
+ value: string;
3613
+ label: string;
3614
+ offset: string;
3615
+ }
3616
+ /** A group of timezones under a region heading. */
3617
+ interface TimezoneGroup {
3618
+ region: string;
3619
+ timezones: TimezoneOption[];
3620
+ }
3621
+ /** Response from `GET /system/timezones`. */
3622
+ interface TimezoneListResponse {
3623
+ popular: TimezoneGroup[];
3624
+ all_timezones: string[];
3625
+ }
2230
3626
 
2231
3627
  /**
2232
3628
  * Auth resource — identity and organization membership endpoints.
@@ -2260,9 +3656,10 @@ declare class Auth extends BaseResource {
2260
3656
  /**
2261
3657
  * POST /auth/invitations/{id}/accept
2262
3658
  *
2263
- * Accepts a pending organization invitation.
3659
+ * Accepts a pending organization invitation. On success the response
3660
+ * includes the joined organization and the granted role.
2264
3661
  */
2265
- acceptInvitation(invitationId: string, options?: RequestOptions): Promise<SuccessResponse>;
3662
+ acceptInvitation(invitationId: string, options?: RequestOptions): Promise<InvitationResponse>;
2266
3663
  /**
2267
3664
  * POST /auth/invitations/{id}/reject
2268
3665
  *
@@ -2338,7 +3735,9 @@ declare class Organizations extends BaseResource {
2338
3735
  /**
2339
3736
  * POST /organizations/invite
2340
3737
  *
2341
- * Sends an invitation email to add a user to the current organization.
3738
+ * Sends an invitation email to add a user to the current organization. The
3739
+ * invited user joins as `admin`; the org `member` role was retired, so the
3740
+ * backend rejects `role: 'member'` with HTTP 422.
2342
3741
  */
2343
3742
  invite(params: InviteParams, options?: RequestOptions): Promise<SuccessResponse>;
2344
3743
  /**
@@ -2356,7 +3755,9 @@ declare class Organizations extends BaseResource {
2356
3755
  /**
2357
3756
  * PUT /organizations/{orgId}/users/{userId}/role
2358
3757
  *
2359
- * Updates a member's role within an organization.
3758
+ * Updates a member's role within an organization. Only `'admin'` is accepted —
3759
+ * the org `member` role was retired, so the backend rejects `role: 'member'`
3760
+ * with HTTP 422.
2360
3761
  */
2361
3762
  updateRole(organizationId: string, userId: string, params: RoleUpdateParams, options?: RequestOptions): Promise<RoleUpdateResponse>;
2362
3763
  /**
@@ -2365,6 +3766,51 @@ declare class Organizations extends BaseResource {
2365
3766
  * Removes a user from an organization. Requires owner permission.
2366
3767
  */
2367
3768
  removeUser(organizationId: string, userId: string, options?: RequestOptions): Promise<SuccessResponse>;
3769
+ /**
3770
+ * POST /organizations/invite/preview
3771
+ *
3772
+ * Previews the prorated cost of adding one seat to the current organization,
3773
+ * for displaying to the user before confirming an invite. The organization is
3774
+ * resolved from the `X-Organization-ID` header, so no request body is sent.
3775
+ *
3776
+ * Returns a discriminated union on `preview_available`: when `false`, the
3777
+ * organization has no active paid subscription (a `reason` is provided); when
3778
+ * `true`, full prorated pricing detail is returned.
3779
+ *
3780
+ * @remarks Admin-only: requires organization admin (or owner) permission.
3781
+ */
3782
+ invitePreview(options?: RequestOptions): Promise<InvitePreviewResponse>;
3783
+ /**
3784
+ * GET /organizations/settings
3785
+ *
3786
+ * Returns the per-organization preference settings (model visibility and the
3787
+ * default composer LLM) for the current organization. The organization is
3788
+ * resolved from the `X-Organization-ID` header.
3789
+ *
3790
+ * @remarks Available to any organization member.
3791
+ */
3792
+ getSettings(options?: RequestOptions): Promise<SettingsResponse>;
3793
+ /**
3794
+ * PUT /organizations/settings/llm-model-visibility
3795
+ *
3796
+ * Sets which models are visible in the dropdown for a single integration.
3797
+ * Send the FULL desired visible list; an empty `models` array resets that
3798
+ * integration's visibility to the catalog default. The organization is
3799
+ * resolved from the `X-Organization-ID` header.
3800
+ *
3801
+ * @remarks Admin-only: requires organization admin (or owner) permission.
3802
+ */
3803
+ setModelVisibility(params: SetModelVisibilityParams, options?: RequestOptions): Promise<SetModelVisibilityResponse>;
3804
+ /**
3805
+ * PUT /organizations/settings/composer-llm
3806
+ *
3807
+ * Persists the organization's default composer LLM. Composer requests that
3808
+ * omit an explicit LLM fall back to this value. The organization is resolved
3809
+ * from the `X-Organization-ID` header.
3810
+ *
3811
+ * @remarks Admin-only: requires organization admin (or owner) permission.
3812
+ */
3813
+ setComposerLlm(params: ComposerLLMParams, options?: RequestOptions): Promise<ComposerLLMResponse>;
2368
3814
  }
2369
3815
 
2370
3816
  /**
@@ -2379,7 +3825,13 @@ declare class Workflows extends BaseResource {
2379
3825
  /**
2380
3826
  * POST /workflows
2381
3827
  *
2382
- * Creates a new workflow with the given schema.
3828
+ * Creates a new workflow with the given schema. Returns HTTP 201.
3829
+ * Requires organization admin/owner role.
3830
+ *
3831
+ * `params.visibility` is passed through unchanged with no client-side default;
3832
+ * omit it to let the backend default to `"organization"`. `"private"` is no
3833
+ * longer creator-only — it behaves like `"organization"` (any org admin/owner
3834
+ * can view/run/resume).
2383
3835
  */
2384
3836
  create(params: CreateWorkflowParams, options?: RequestOptions): Promise<WorkflowResponse>;
2385
3837
  /**
@@ -2405,12 +3857,15 @@ declare class Workflows extends BaseResource {
2405
3857
  * PUT /workflows/{workflowId}
2406
3858
  *
2407
3859
  * Updates an existing workflow. Only provided fields are changed.
3860
+ * Requires organization admin/owner role.
2408
3861
  */
2409
3862
  update(workflowId: string, params: UpdateWorkflowParams, options?: RequestOptions): Promise<WorkflowResponse>;
2410
3863
  /**
2411
3864
  * DELETE /workflows/{workflowId}
2412
3865
  *
2413
- * Soft-deletes a workflow.
3866
+ * Permanently (hard) deletes a workflow. This is IRREVERSIBLE — the workflow
3867
+ * row and its schema are removed from the database, not soft-deleted.
3868
+ * Requires organization admin/owner role.
2414
3869
  */
2415
3870
  delete(workflowId: string, options?: RequestOptions): Promise<DeleteWorkflowResponse>;
2416
3871
  /**
@@ -2420,23 +3875,41 @@ declare class Workflows extends BaseResource {
2420
3875
  * the visual workflow builder. Results are cached for 60 minutes.
2421
3876
  */
2422
3877
  builderDetails(params?: BuilderDetailsParams, options?: RequestOptions): Promise<BuilderDetailsResponse>;
3878
+ /**
3879
+ * GET /workflows/{workflowId}/changes — SSE stream
3880
+ *
3881
+ * Opens a Server-Sent Events stream of real-time collaboration changes for a
3882
+ * workflow (canvas/composer sync). This is a data-only stream: each yielded
3883
+ * value is a {@link WorkflowChangeEvent} discriminated on its `type` field
3884
+ * (`connected`, `workflow_updated`, `user_joined`, `user_left`).
3885
+ */
3886
+ listenChanges(workflowId: string, options?: RequestOptions): AsyncGenerator<WorkflowChangeEvent>;
2423
3887
  }
2424
3888
 
2425
3889
  /**
2426
- * Executions resource — workflow run, resume, cancel, listen, and state endpoints.
3890
+ * Executions resource — ephemeral workflow execution control under `/workflows`
3891
+ * (run, state, resume, cancel, listen).
3892
+ *
3893
+ * For durable run history (list/get persisted runs) see the {@link WorkflowRuns}
3894
+ * resource (`client.workflowRuns`).
2427
3895
  * @module resources/executions
2428
3896
  */
2429
3897
 
2430
3898
  /**
2431
- * Provides methods for workflow execution endpoints under `/workflows`.
3899
+ * Provides methods for workflow execution-control endpoints under `/workflows`.
2432
3900
  */
2433
3901
  declare class Executions extends BaseResource {
2434
3902
  /**
2435
3903
  * POST /workflows/run
2436
3904
  *
2437
- * Initiates a workflow run. Supports four modes: existing workflow, ad-hoc
2438
- * workflow, direct LLM call, and system workflow. Returns immediately with
2439
- * run metadata; stream events via `listen()`.
3905
+ * Initiates a workflow run. Supports two modes: a saved workflow (`workflowId`,
3906
+ * which requires an active deployment the backend returns 400 otherwise) or
3907
+ * an inline ad-hoc definition (`workflow`). Returns immediately with run
3908
+ * metadata (`status` is `"running"` for streaming runs); stream events via
3909
+ * `listen()`.
3910
+ *
3911
+ * The legacy direct-LLM mode was removed; an `llm_config`-only request now
3912
+ * returns HTTP 410 — use `client.assistant.chat()` instead.
2440
3913
  */
2441
3914
  run(params: WorkflowRunParams, options?: RequestOptions): Promise<WorkflowRunResponse>;
2442
3915
  /**
@@ -2444,18 +3917,33 @@ declare class Executions extends BaseResource {
2444
3917
  *
2445
3918
  * Returns the persisted state snapshot of a workflow thread at its latest
2446
3919
  * checkpoint.
3920
+ *
3921
+ * Throws `NotFoundError` on HTTP 404 — the thread does not exist OR is not
3922
+ * owned by your organization. Ownership failures return an identical 404 (not
3923
+ * 403) by design, so there is no existence leak.
2447
3924
  */
2448
3925
  getState(threadId: string, options?: RequestOptions): Promise<WorkflowStateResponse>;
2449
3926
  /**
2450
3927
  * POST /workflows/resume/{threadId}
2451
3928
  *
2452
3929
  * Resumes a workflow that is waiting at an interrupt node.
3930
+ *
3931
+ * Guard responses: 400 (missing `resumeValue` or `runId`); 404 — a
3932
+ * `NotFoundError` — when there is no checkpoint for the thread OR the
3933
+ * run/thread is not owned by your organization. Ownership failures return an
3934
+ * identical 404 (not 403) by design, so there is no existence leak.
2453
3935
  */
2454
3936
  resume(params: WorkflowResumeParams, options?: RequestOptions): Promise<WorkflowResumeResponse>;
2455
3937
  /**
2456
3938
  * POST /workflows/cancel/{runId}
2457
3939
  *
2458
- * Requests cancellation of an in-progress workflow run.
3940
+ * Requests cancellation of an in-progress workflow run. On success the
3941
+ * response `status` is `"cancellation_requested"`.
3942
+ *
3943
+ * Guard responses: 404 — a `NotFoundError` — when the run is unknown OR is not
3944
+ * owned by your organization (ownership failures return an identical 404, not
3945
+ * 403, by design, so there is no existence leak); 400 (the run is not in a
3946
+ * `running`/`interrupted` state).
2459
3947
  */
2460
3948
  cancel(runId: string, params?: {
2461
3949
  reason?: string;
@@ -2463,12 +3951,53 @@ declare class Executions extends BaseResource {
2463
3951
  /**
2464
3952
  * GET /workflows/listen/{runId} — SSE stream
2465
3953
  *
2466
- * Opens a Server-Sent Events stream for real-time execution events of
2467
- * an in-progress workflow run. Yields typed `WorkflowSSEEvent` values.
3954
+ * Opens a Server-Sent Events stream for real-time execution events of an
3955
+ * in-progress workflow run. This is a data-only stream: each yielded value is
3956
+ * a {@link WorkflowSSEEvent} discriminated on its `type` field (`metadata`,
3957
+ * `node_started`, `node_update`, `interrupt`, `resumed`, `done`, `cancelled`,
3958
+ * `error`). The stream ends after a `done` or `error` event.
3959
+ *
3960
+ * A 404 on connect throws `NotFoundError` before any event is yielded — the
3961
+ * run does not exist OR is not owned by your organization (ownership failures
3962
+ * return an identical 404, not 403). The stream does NOT auto-reconnect on a
3963
+ * 404.
2468
3964
  */
2469
3965
  listen(runId: string, options?: RequestOptions): AsyncGenerator<WorkflowSSEEvent>;
2470
3966
  }
2471
3967
 
3968
+ /**
3969
+ * WorkflowRuns resource — durable run-history read endpoints under `/workflow-runs`.
3970
+ *
3971
+ * These are distinct from the ephemeral execution-control endpoints in the
3972
+ * {@link Executions} resource: this resource reads the persisted `workflow_runs`
3973
+ * table (history, input/output snapshots, attribution).
3974
+ * @module resources/workflow-runs
3975
+ */
3976
+
3977
+ /**
3978
+ * Provides read access to durable workflow run history under `/workflow-runs`.
3979
+ */
3980
+ declare class WorkflowRuns extends BaseResource {
3981
+ /**
3982
+ * GET /workflow-runs
3983
+ *
3984
+ * Lists workflow runs for the organization, newest first. Pass `workflowId`
3985
+ * for per-workflow history. Pagination is via `has_more` (no total count).
3986
+ */
3987
+ list(params?: WorkflowRunListParams, options?: RequestOptions): Promise<WorkflowRunListResponse>;
3988
+ /**
3989
+ * GET /workflow-runs/{runPk}
3990
+ *
3991
+ * Returns the full durable run record (including input/output snapshots).
3992
+ *
3993
+ * NOTE: `runPk` is the run table primary key (the `id` field of a
3994
+ * {@link WorkflowRunListItem} / {@link WorkflowRunDetail}), NOT the string
3995
+ * `run_id` used by `executions.listen()` / `executions.cancel()`. Passing a
3996
+ * `run_id` here returns 404.
3997
+ */
3998
+ get(runPk: string, options?: RequestOptions): Promise<WorkflowRunDetail>;
3999
+ }
4000
+
2472
4001
  /**
2473
4002
  * Deployments resource — workflow deployment management endpoints.
2474
4003
  * @module resources/deployments
@@ -2585,15 +4114,18 @@ declare class Credentials extends BaseResource {
2585
4114
  /**
2586
4115
  * GET /credentials/{credentialId}
2587
4116
  *
2588
- * Returns a single credential record.
4117
+ * Returns a single credential record, including ownership and (optionally
4118
+ * masked) auth detail fields not present on the list endpoint.
2589
4119
  */
2590
4120
  get(credentialId: string, params?: {
2591
4121
  includeMasked?: boolean;
2592
- }, options?: RequestOptions): Promise<CredentialResponse>;
4122
+ }, options?: RequestOptions): Promise<CredentialDetailResponse>;
2593
4123
  /**
2594
4124
  * POST /credentials
2595
4125
  *
2596
4126
  * Creates a new credential. The auth data is encrypted at rest.
4127
+ *
4128
+ * @remarks Requires admin/owner role on the organization.
2597
4129
  */
2598
4130
  create(params: CreateCredentialParams, options?: RequestOptions): Promise<CredentialResponse>;
2599
4131
  /**
@@ -2631,18 +4163,25 @@ declare class Credentials extends BaseResource {
2631
4163
  * GET /credentials/{credentialId}/usage
2632
4164
  *
2633
4165
  * Returns usage statistics for a credential.
4166
+ *
4167
+ * @remarks Requires admin/owner role on the organization.
2634
4168
  */
2635
4169
  usage(credentialId: string, params?: CredentialUsageParams, options?: RequestOptions): Promise<CredentialUsageResponse>;
2636
4170
  /**
2637
4171
  * GET /credentials/{credentialId}/audit
2638
4172
  *
2639
- * Returns the audit log for a credential.
4173
+ * Returns the audit log for a credential as an array of entries.
4174
+ *
4175
+ * @remarks Requires admin/owner role on the organization.
2640
4176
  */
2641
- audit(credentialId: string, params?: CredentialAuditParams, options?: RequestOptions): Promise<Record<string, unknown>>;
4177
+ audit(credentialId: string, params?: CredentialAuditParams, options?: RequestOptions): Promise<AuditLogResponse[]>;
2642
4178
  /**
2643
4179
  * POST /credentials/bulk-modulex-keys/stream — SSE
2644
4180
  *
2645
- * Streams bulk ModuleX managed key provisioning events.
4181
+ * Streams bulk ModuleX managed key provisioning events. Each event's
4182
+ * `data` field can be parsed as a {@link ModulexKeyBulkEventData}.
4183
+ *
4184
+ * @remarks Requires admin/owner role on the organization.
2646
4185
  */
2647
4186
  bulkModulexKeys(options?: RequestOptions): AsyncGenerator<SSEEvent>;
2648
4187
  /**
@@ -2650,7 +4189,7 @@ declare class Credentials extends BaseResource {
2650
4189
  *
2651
4190
  * Creates a credential for a Model Context Protocol (MCP) server.
2652
4191
  */
2653
- mcpServer(params: McpServerParams, options?: RequestOptions): Promise<CredentialResponse>;
4192
+ mcpServer(params: McpServerParams, options?: RequestOptions): Promise<MCPServerCredentialResponse>;
2654
4193
  /**
2655
4194
  * POST /credentials/{credentialId}/refresh-discovery
2656
4195
  *
@@ -2663,6 +4202,25 @@ declare class Credentials extends BaseResource {
2663
4202
  * Returns the tools discovered from an MCP server credential.
2664
4203
  */
2665
4204
  mcpTools(credentialId: string, options?: RequestOptions): Promise<McpToolsResponse>;
4205
+ /**
4206
+ * POST /credentials/oauth2/initiate
4207
+ *
4208
+ * Initiates an OAuth2 authorization flow for an integration and returns the
4209
+ * authorization URL the user should be redirected to, along with a `state`
4210
+ * token correlating the flow.
4211
+ *
4212
+ * @remarks Requires admin/owner role on the organization.
4213
+ */
4214
+ initiateOAuth2(params: InitiateOAuth2Params, options?: RequestOptions): Promise<OAuth2InitiateResponse>;
4215
+ /**
4216
+ * POST /credentials/{credentialId}/oauth2/refresh
4217
+ *
4218
+ * Manually refreshes the access token of an existing OAuth2 credential and
4219
+ * returns the updated credential record.
4220
+ *
4221
+ * @remarks Requires admin/owner role on the organization.
4222
+ */
4223
+ refreshOAuth2(credentialId: string, options?: RequestOptions): Promise<CredentialResponse>;
2666
4224
  }
2667
4225
 
2668
4226
  /**
@@ -2687,7 +4245,7 @@ declare class Integrations extends BaseResource {
2687
4245
  */
2688
4246
  tools(params?: {
2689
4247
  category?: string;
2690
- }, options?: RequestOptions): Promise<Record<string, unknown>>;
4248
+ }, options?: RequestOptions): Promise<IntegrationMetadata[]>;
2691
4249
  /**
2692
4250
  * GET /integrations/tools/{integrationName}
2693
4251
  *
@@ -2701,7 +4259,7 @@ declare class Integrations extends BaseResource {
2701
4259
  */
2702
4260
  llmProviders(params?: {
2703
4261
  category?: string;
2704
- }, options?: RequestOptions): Promise<Record<string, unknown>>;
4262
+ }, options?: RequestOptions): Promise<IntegrationMetadata[]>;
2705
4263
  /**
2706
4264
  * GET /integrations/llm-providers/{providerName}
2707
4265
  *
@@ -2715,7 +4273,7 @@ declare class Integrations extends BaseResource {
2715
4273
  */
2716
4274
  knowledgeProviders(params?: {
2717
4275
  category?: string;
2718
- }, options?: RequestOptions): Promise<Record<string, unknown>>;
4276
+ }, options?: RequestOptions): Promise<IntegrationMetadata[]>;
2719
4277
  /**
2720
4278
  * GET /integrations/knowledge-providers/{providerName}
2721
4279
  *
@@ -2743,12 +4301,17 @@ declare class Knowledge extends BaseResource {
2743
4301
  * GET /knowledge-bases
2744
4302
  *
2745
4303
  * Lists knowledge bases for the current organization.
4304
+ *
4305
+ * The backend returns a bare JSON array (no pagination envelope); the
4306
+ * `limit`/`offset`/`status` query params control which records are returned.
2746
4307
  */
2747
- list(params?: KnowledgeBaseListParams, options?: RequestOptions): Promise<KnowledgeBaseListResponse>;
4308
+ list(params?: KnowledgeBaseListParams, options?: RequestOptions): Promise<KnowledgeBaseResponse[]>;
2748
4309
  /**
2749
4310
  * POST /knowledge-bases
2750
4311
  *
2751
4312
  * Creates a new knowledge base.
4313
+ *
4314
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2752
4315
  */
2753
4316
  create(params: CreateKnowledgeBaseParams, options?: RequestOptions): Promise<KnowledgeBaseResponse>;
2754
4317
  /**
@@ -2767,6 +4330,8 @@ declare class Knowledge extends BaseResource {
2767
4330
  * PUT /knowledge-bases/{kbId}
2768
4331
  *
2769
4332
  * Updates a knowledge base's name, description, or configuration.
4333
+ *
4334
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2770
4335
  */
2771
4336
  update(knowledgeBaseId: string, params: UpdateKnowledgeBaseParams, options?: RequestOptions): Promise<KnowledgeBaseResponse>;
2772
4337
  /**
@@ -2774,6 +4339,8 @@ declare class Knowledge extends BaseResource {
2774
4339
  *
2775
4340
  * Deletes a knowledge base. Pass `deleteFiles: true` to also remove
2776
4341
  * the underlying stored files.
4342
+ *
4343
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2777
4344
  */
2778
4345
  delete(knowledgeBaseId: string, params?: {
2779
4346
  deleteFiles?: boolean;
@@ -2782,19 +4349,27 @@ declare class Knowledge extends BaseResource {
2782
4349
  * POST /knowledge-bases/{kbId}/archive
2783
4350
  *
2784
4351
  * Archives a knowledge base, pausing ingestion without deleting data.
4352
+ * Returns the updated knowledge base record.
4353
+ *
4354
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2785
4355
  */
2786
- archive(knowledgeBaseId: string, options?: RequestOptions): Promise<SuccessResponse>;
4356
+ archive(knowledgeBaseId: string, options?: RequestOptions): Promise<KnowledgeBaseResponse>;
2787
4357
  /**
2788
4358
  * GET /knowledge-bases/{kbId}/documents
2789
4359
  *
2790
4360
  * Returns documents within a knowledge base.
4361
+ *
4362
+ * The backend returns a bare JSON array; the `limit`/`offset`/`status`
4363
+ * query params control which records are returned.
2791
4364
  */
2792
- documents(knowledgeBaseId: string, params?: DocumentListParams, options?: RequestOptions): Promise<Record<string, unknown>>;
4365
+ documents(knowledgeBaseId: string, params?: DocumentListParams, options?: RequestOptions): Promise<DocumentResponse[]>;
2793
4366
  /**
2794
4367
  * POST /knowledge-bases/{kbId}/documents — multipart upload
2795
4368
  *
2796
4369
  * Uploads a document file to a knowledge base for ingestion.
2797
4370
  * Builds a `FormData` with the file and optional metadata JSON.
4371
+ *
4372
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2798
4373
  */
2799
4374
  uploadDocument(knowledgeBaseId: string, params: UploadDocumentParams, options?: RequestOptions): Promise<DocumentResponse>;
2800
4375
  /**
@@ -2806,7 +4381,8 @@ declare class Knowledge extends BaseResource {
2806
4381
  /**
2807
4382
  * GET /knowledge-bases/{kbId}/documents/{docId}/status
2808
4383
  *
2809
- * Returns the processing status and progress of a document.
4384
+ * Returns the processing status of a document. Some fields are conditional
4385
+ * on the document's `status` value.
2810
4386
  */
2811
4387
  documentStatus(knowledgeBaseId: string, documentId: string, options?: RequestOptions): Promise<DocumentStatusResponse>;
2812
4388
  /**
@@ -2814,6 +4390,8 @@ declare class Knowledge extends BaseResource {
2814
4390
  *
2815
4391
  * Deletes a document and its chunks from the knowledge base.
2816
4392
  * Pass `deleteFile: true` to also remove the source file from storage.
4393
+ *
4394
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2817
4395
  */
2818
4396
  deleteDocument(knowledgeBaseId: string, documentId: string, params?: {
2819
4397
  deleteFile?: boolean;
@@ -2821,9 +4399,11 @@ declare class Knowledge extends BaseResource {
2821
4399
  /**
2822
4400
  * POST /knowledge-bases/{kbId}/documents/{docId}/retry
2823
4401
  *
2824
- * Retries ingestion of a failed document.
4402
+ * Retries ingestion of a failed document. Returns the updated document record.
4403
+ *
4404
+ * Requires an organization admin or owner role; non-admin keys receive 403.
2825
4405
  */
2826
- retryDocument(knowledgeBaseId: string, documentId: string, options?: RequestOptions): Promise<Record<string, unknown>>;
4406
+ retryDocument(knowledgeBaseId: string, documentId: string, options?: RequestOptions): Promise<DocumentResponse>;
2827
4407
  /**
2828
4408
  * GET /knowledge-bases/{kbId}/documents/{docId}/chunks
2829
4409
  *
@@ -2901,25 +4481,26 @@ declare class Schedules extends BaseResource {
2901
4481
  *
2902
4482
  * Deletes a schedule and cancels all pending executions.
2903
4483
  */
2904
- delete(scheduleId: string, options?: RequestOptions): Promise<SuccessResponse>;
4484
+ delete(scheduleId: string, options?: RequestOptions): Promise<DeleteScheduleResponse>;
2905
4485
  /**
2906
4486
  * POST /schedules/{scheduleId}/pause
2907
4487
  *
2908
4488
  * Pauses a schedule, preventing future runs until resumed.
4489
+ * Returns the updated schedule.
2909
4490
  */
2910
- pause(scheduleId: string, options?: RequestOptions): Promise<SuccessResponse>;
4491
+ pause(scheduleId: string, options?: RequestOptions): Promise<ScheduleResponse>;
2911
4492
  /**
2912
4493
  * POST /schedules/{scheduleId}/resume
2913
4494
  *
2914
- * Resumes a paused schedule.
4495
+ * Resumes a paused schedule. Returns the updated schedule.
2915
4496
  */
2916
- resume(scheduleId: string, options?: RequestOptions): Promise<SuccessResponse>;
4497
+ resume(scheduleId: string, options?: RequestOptions): Promise<ScheduleResponse>;
2917
4498
  /**
2918
4499
  * GET /schedules/{scheduleId}/runs
2919
4500
  *
2920
4501
  * Returns the run history for a schedule.
2921
4502
  */
2922
- runs(scheduleId: string, params?: ScheduleRunListParams, options?: RequestOptions): Promise<Record<string, unknown>>;
4503
+ runs(scheduleId: string, params?: ScheduleRunListParams, options?: RequestOptions): Promise<ScheduleRunListResponse>;
2923
4504
  /**
2924
4505
  * GET /schedules/{scheduleId}/runs/stats
2925
4506
  *
@@ -2937,139 +4518,204 @@ declare class Schedules extends BaseResource {
2937
4518
  *
2938
4519
  * Retries a failed scheduled run.
2939
4520
  */
2940
- retryRun(scheduleId: string, runId: string, options?: RequestOptions): Promise<Record<string, unknown>>;
4521
+ retryRun(scheduleId: string, runId: string, options?: RequestOptions): Promise<RetryRunResponse>;
2941
4522
  }
2942
4523
 
2943
4524
  /**
2944
- * Templates resource — workflow template and creator profile endpoints.
2945
- * @module resources/templates
4525
+ * Composer resource — AI-driven workflow builder chat endpoints.
4526
+ * @module resources/composer
2946
4527
  */
2947
4528
 
2948
4529
  /**
2949
- * Provides methods for the `/templates` API endpoints.
4530
+ * Provides methods for the `/composer` API endpoints.
2950
4531
  */
2951
- declare class Templates extends BaseResource {
4532
+ declare class Composer extends BaseResource {
4533
+ /**
4534
+ * POST /composer/chat
4535
+ *
4536
+ * Starts a new Composer chat or sends a message to an existing session.
4537
+ * Returns a run ID that can be used to listen to the SSE stream.
4538
+ *
4539
+ * Errors: 409 if the chat has a pending HITL question (answer it via
4540
+ * `resume()` first); 402/403/429 for billing/limit gates.
4541
+ */
4542
+ chat(params: ComposerChatParams, options?: RequestOptions): Promise<ComposerChatResponse>;
4543
+ /**
4544
+ * GET /composer/chats
4545
+ *
4546
+ * Lists the current user's Composer chats, newest first, with cursor
4547
+ * pagination (`next_cursor` is an ISO `updated_at` timestamp).
4548
+ */
4549
+ list(params?: ComposerListParams, options?: RequestOptions): Promise<ComposerChatListResponse>;
2952
4550
  /**
2953
- * GET /templates
4551
+ * GET /composer/chat/{composerChatId}
2954
4552
  *
2955
- * Returns the public template library.
4553
+ * Returns a Composer chat session with its messages, touched workflows, and
4554
+ * any open HITL question (`pending_user_input_request`).
2956
4555
  */
2957
- list(options?: RequestOptions): Promise<TemplateListResponse>;
4556
+ get(composerChatId: string, options?: RequestOptions): Promise<ComposerChatDetailResponse>;
2958
4557
  /**
2959
- * GET /templates/{templateId}
4558
+ * GET /composer/chat/{composerChatId}/listen/{runId} — SSE
4559
+ *
4560
+ * Opens a Server-Sent Events stream for real-time Composer output. This is a
4561
+ * data-only stream: each yielded value is a {@link ComposerSSEEvent}
4562
+ * discriminated on `type`. A `user_input_request` frame signals a HITL pause —
4563
+ * answer it with `resume()`.
2960
4564
  *
2961
- * Returns a single template including its full workflow schema.
4565
+ * A 404 on connect throws `NotFoundError` before any event is yielded — the
4566
+ * chat/run does not exist OR is not owned by your organization (ownership
4567
+ * failures return an identical 404, not 403). The stream does NOT
4568
+ * auto-reconnect on a 404.
2962
4569
  */
2963
- get(templateId: string, options?: RequestOptions): Promise<TemplateResponse>;
4570
+ listen(composerChatId: string, runId: string, options?: RequestOptions): AsyncGenerator<ComposerSSEEvent>;
2964
4571
  /**
2965
- * GET /templates/me
4572
+ * POST /composer/chat/{composerChatId}/resume
2966
4573
  *
2967
- * Returns templates created by the authenticated user.
4574
+ * Answers an open HITL question and resumes the paused run. Returns a NEW
4575
+ * `run_id` to listen on.
4576
+ *
4577
+ * Errors: 404 (a `NotFoundError`) when the chat does not exist OR is not owned
4578
+ * by your organization (ownership failures return an identical 404, not 403);
4579
+ * 410 if the `requestId` is not pending or already consumed; 403 if the caller
4580
+ * is not the user who triggered the question. The `llm` config is required in
4581
+ * production (the backend returns 400 if omitted).
2968
4582
  */
2969
- mine(options?: RequestOptions): Promise<MyTemplatesResponse>;
4583
+ resume(composerChatId: string, params: ComposerResumeParams, options?: RequestOptions): Promise<ComposerResumeResponse>;
2970
4584
  /**
2971
- * POST /templates
4585
+ * PATCH /composer/chat/{composerChatId}/focus
2972
4586
  *
2973
- * Publishes a workflow as a new template.
4587
+ * Sets (or clears, with `workflowId: null`) the chat's focused workflow.
2974
4588
  */
2975
- create(params: CreateTemplateParams, options?: RequestOptions): Promise<TemplateResponse>;
4589
+ focus(composerChatId: string, params: ComposerFocusParams, options?: RequestOptions): Promise<ComposerFocusResponse>;
2976
4590
  /**
2977
- * POST /templates/{templateId}/like
4591
+ * POST /composer/chat/{composerChatId}/save
2978
4592
  *
2979
- * Toggles the authenticated user's like on a template.
4593
+ * Saves the Composer's pending workflow changes. Without `workflowId` it
4594
+ * targets the chat's focused workflow (400 if there is none). Returns a
4595
+ * `workflow_sync` payload for refreshing the canvas.
2980
4596
  */
2981
- like(templateId: string, options?: RequestOptions): Promise<TemplateLikeResponse>;
4597
+ save(composerChatId: string, params?: ComposerSaveParams, options?: RequestOptions): Promise<ComposerSaveResponse>;
2982
4598
  /**
2983
- * POST /templates/{templateId}/use
4599
+ * POST /composer/chat/{composerChatId}/revert
2984
4600
  *
2985
- * Imports a template as a new workflow in the current organization.
4601
+ * Reverts pending changes to the last snapshot. Without `workflowId` it
4602
+ * targets the focused workflow (400 if there is none, or if no snapshot
4603
+ * exists). Returns a `workflow_sync` payload.
2986
4604
  */
2987
- use(templateId: string, options?: RequestOptions): Promise<TemplateUseResponse>;
4605
+ revert(composerChatId: string, params?: ComposerSaveParams, options?: RequestOptions): Promise<ComposerRevertResponse>;
2988
4606
  /**
2989
- * POST /templates/{templateId}/update-request
4607
+ * DELETE /composer/chat/{composerChatId}
2990
4608
  *
2991
- * Submits an update request for a published template.
4609
+ * Deletes a Composer chat session. Pass `permanent: true` for a hard delete
4610
+ * (default is a soft delete). `permanent` is sent as a query parameter.
2992
4611
  */
2993
- updateRequest(templateId: string, params: UpdateTemplateRequestParams, options?: RequestOptions): Promise<SuccessResponse>;
4612
+ delete(composerChatId: string, params?: ComposerDeleteParams, options?: RequestOptions): Promise<ComposerDeleteResponse>;
2994
4613
  /**
2995
- * POST /templates/creators
4614
+ * GET /composer/chat/{composerChatId}/status
2996
4615
  *
2997
- * Creates or updates the authenticated user's template creator profile.
4616
+ * Returns the real-time status of a Composer chat session, including HITL
4617
+ * pause state (`awaiting_input` / `pending_request_id`).
2998
4618
  */
2999
- createCreator(params: CreateCreatorParams, options?: RequestOptions): Promise<Record<string, unknown>>;
4619
+ status(composerChatId: string, options?: RequestOptions): Promise<ComposerStatusResponse>;
3000
4620
  /**
3001
- * GET /templates/creators/me
4621
+ * POST /composer/chat/{composerChatId}/cancel
4622
+ *
4623
+ * Cancels the in-progress run for a Composer chat session.
3002
4624
  *
3003
- * Returns the authenticated user's template creator profile.
4625
+ * Throws `NotFoundError` on HTTP 404 — the chat does not exist OR is not owned
4626
+ * by your organization (ownership failures return an identical 404, not 403,
4627
+ * so there is no existence leak).
3004
4628
  */
3005
- getCreator(options?: RequestOptions): Promise<Record<string, unknown>>;
4629
+ cancel(composerChatId: string, options?: RequestOptions): Promise<ComposerCancelResponse>;
3006
4630
  }
3007
4631
 
3008
4632
  /**
3009
- * Composer resource — AI-driven workflow builder chat endpoints.
3010
- * @module resources/composer
4633
+ * Assistant resource — a chat agent with HITL support under `/assistant`.
4634
+ *
4635
+ * Structurally similar to {@link Composer} but NOT bound to any workflow
4636
+ * (no save/revert/focus). Shares the HITL union types in `types/hitl`.
4637
+ * @module resources/assistant
3011
4638
  */
3012
4639
 
3013
4640
  /**
3014
- * Provides methods for the `/composer` API endpoints.
4641
+ * Provides methods for the `/assistant` API endpoints.
3015
4642
  */
3016
- declare class Composer extends BaseResource {
4643
+ declare class Assistant extends BaseResource {
3017
4644
  /**
3018
- * POST /composer/chat
4645
+ * POST /assistant/chat
3019
4646
  *
3020
- * Starts a new Composer chat or sends a message to an existing session.
3021
- * Returns a run ID that can be used to listen to the SSE stream.
3022
- */
3023
- chat(params: ComposerChatParams, options?: RequestOptions): Promise<ComposerChatResponse>;
3024
- /**
3025
- * GET /composer/chat/{composerChatId}
4647
+ * Starts a new Assistant chat or sends a message to an existing one. Returns
4648
+ * a run ID to listen on.
3026
4649
  *
3027
- * Returns a Composer chat session with its messages and workflow snapshot status.
4650
+ * Errors: 409 if the chat has a pending HITL question or a run is already in
4651
+ * progress (answer via `resume()` / `cancel()` first); 402/403/429 at the
4652
+ * billing gate.
3028
4653
  */
3029
- get(composerChatId: string, options?: RequestOptions): Promise<ComposerChatDetailResponse>;
4654
+ chat(params: AssistantChatParams, options?: RequestOptions): Promise<AssistantChatResponse>;
3030
4655
  /**
3031
- * GET /composer/chat/{composerChatId}/listen/{runId} — SSE
4656
+ * GET /assistant/chats
3032
4657
  *
3033
- * Opens a Server-Sent Events stream for real-time Composer output during a run.
4658
+ * Lists the current user's Assistant chats, newest first, with cursor
4659
+ * pagination (`next_cursor` is an ISO `updated_at` timestamp).
3034
4660
  */
3035
- listen(composerChatId: string, runId: string, options?: RequestOptions): AsyncGenerator<SSEEvent>;
4661
+ list(params?: AssistantListParams, options?: RequestOptions): Promise<AssistantChatListResponse>;
3036
4662
  /**
3037
- * POST /composer/chat/{composerChatId}/save
4663
+ * GET /assistant/chat/{chatId}
3038
4664
  *
3039
- * Saves the Composer's current workflow changes to the associated workflow.
4665
+ * Returns an Assistant chat with its messages and any open HITL question
4666
+ * (`pending_user_input_request`).
3040
4667
  */
3041
- save(composerChatId: string, options?: RequestOptions): Promise<SuccessResponse>;
4668
+ get(chatId: string, options?: RequestOptions): Promise<AssistantChatDetailResponse>;
3042
4669
  /**
3043
- * POST /composer/chat/{composerChatId}/revert
4670
+ * GET /assistant/chat/{chatId}/listen/{runId} — SSE
4671
+ *
4672
+ * Opens a Server-Sent Events stream for real-time Assistant output. This is a
4673
+ * data-only stream: each yielded value is an {@link AssistantSSEEvent}
4674
+ * discriminated on `type`. A `user_input_request` frame signals a HITL pause —
4675
+ * answer it with `resume()`.
3044
4676
  *
3045
- * Reverts the Composer's pending changes, restoring the last saved state.
4677
+ * A 404 on connect throws `NotFoundError` before any event is yielded — the
4678
+ * chat/run does not exist OR is not owned by your organization (ownership
4679
+ * failures return an identical 404, not 403). The stream does NOT
4680
+ * auto-reconnect on a 404.
3046
4681
  */
3047
- revert(composerChatId: string, options?: RequestOptions): Promise<SuccessResponse>;
4682
+ listen(chatId: string, runId: string, options?: RequestOptions): AsyncGenerator<AssistantSSEEvent>;
3048
4683
  /**
3049
- * GET /composer/chat/workflow/{workflowId}/history
4684
+ * POST /assistant/chat/{chatId}/resume
3050
4685
  *
3051
- * Returns the Composer chat history associated with a workflow.
4686
+ * Answers an open HITL question and resumes the paused run. Returns a NEW
4687
+ * `run_id` to listen on.
4688
+ *
4689
+ * Errors: 404 (a `NotFoundError`) when the chat is not found OR is not owned by
4690
+ * your organization (ownership failures return an identical 404, not 403); 410
4691
+ * if the question was already answered or cancelled; 403 if the caller is not
4692
+ * the user who triggered it. `llm` is required (400 if omitted).
3052
4693
  */
3053
- history(workflowId: string, params?: ComposerHistoryParams, options?: RequestOptions): Promise<Record<string, unknown>>;
4694
+ resume(chatId: string, params: AssistantResumeParams, options?: RequestOptions): Promise<AssistantResumeResponse>;
3054
4695
  /**
3055
- * DELETE /composer/chat/{composerChatId}
4696
+ * GET /assistant/chat/{chatId}/status
3056
4697
  *
3057
- * Deletes a Composer chat session. Pass `permanent: true` to also delete
3058
- * the associated workflow.
4698
+ * Returns real-time status including HITL pause state (`awaiting_input` /
4699
+ * `pending_request_id`).
3059
4700
  */
3060
- delete(composerChatId: string, params?: ComposerDeleteParams, options?: RequestOptions): Promise<SuccessResponse>;
4701
+ status(chatId: string, options?: RequestOptions): Promise<AssistantStatusResponse>;
3061
4702
  /**
3062
- * GET /composer/chat/{composerChatId}/status
4703
+ * POST /assistant/chat/{chatId}/cancel
3063
4704
  *
3064
- * Returns the real-time status of a Composer chat session.
4705
+ * Cancels the in-progress run and clears any pending HITL question. The
4706
+ * returned `run_id` is the run that was cancelled. Errors: 404 (a
4707
+ * `NotFoundError`) when the chat is not found OR is not owned by your
4708
+ * organization (ownership failures return an identical 404, not 403); 400 if
4709
+ * there is no active execution.
3065
4710
  */
3066
- status(composerChatId: string, options?: RequestOptions): Promise<ComposerStatusResponse>;
4711
+ cancel(chatId: string, options?: RequestOptions): Promise<AssistantCancelResponse>;
3067
4712
  /**
3068
- * POST /composer/chat/{composerChatId}/cancel
4713
+ * DELETE /assistant/chat/{chatId}
3069
4714
  *
3070
- * Cancels the in-progress run for a Composer chat session.
4715
+ * Deletes an Assistant chat. Pass `permanent: true` for a hard delete
4716
+ * (default is a soft delete).
3071
4717
  */
3072
- cancel(composerChatId: string, options?: RequestOptions): Promise<SuccessResponse>;
4718
+ delete(chatId: string, params?: AssistantDeleteParams, options?: RequestOptions): Promise<AssistantDeleteResponse>;
3073
4719
  }
3074
4720
 
3075
4721
  /**
@@ -3104,7 +4750,7 @@ declare class Dashboard extends BaseResource {
3104
4750
  *
3105
4751
  * Returns LLM token-usage analytics broken down by model and provider.
3106
4752
  */
3107
- analyticsLlmUsage(params?: AnalyticsToolsParams, options?: RequestOptions): Promise<AnalyticsLLMUsageResponse>;
4753
+ analyticsLlmUsage(params?: AnalyticsLLMUsageParams, options?: RequestOptions): Promise<AnalyticsLLMUsageResponse>;
3108
4754
  /**
3109
4755
  * GET /dashboard/users
3110
4756
  *
@@ -3113,42 +4759,6 @@ declare class Dashboard extends BaseResource {
3113
4759
  users(params?: DashboardUsersParams, options?: RequestOptions): Promise<DashboardUsersResponse>;
3114
4760
  }
3115
4761
 
3116
- /**
3117
- * Subscriptions resource — billing and subscription plan management endpoints.
3118
- * @module resources/subscriptions
3119
- */
3120
-
3121
- /**
3122
- * Provides methods for the `/subscriptions` API endpoints.
3123
- */
3124
- declare class Subscriptions extends BaseResource {
3125
- /**
3126
- * GET /subscriptions/organization-plans
3127
- *
3128
- * Returns the list of available organization subscription plans.
3129
- */
3130
- organizationPlans(options?: RequestOptions): Promise<OrganizationPlansResponse>;
3131
- /**
3132
- * GET /subscriptions/organization-billing
3133
- *
3134
- * Returns the current organization's billing status and active subscription.
3135
- */
3136
- billing(options?: RequestOptions): Promise<BillingResponse>;
3137
- /**
3138
- * POST /subscriptions/checkout-link
3139
- *
3140
- * Creates a Stripe Checkout session and returns the redirect URL.
3141
- */
3142
- checkoutLink(params: CheckoutParams, options?: RequestOptions): Promise<CheckoutResponse>;
3143
- /**
3144
- * POST /subscriptions/customer-portal
3145
- *
3146
- * Creates a Stripe Customer Portal session and returns the redirect URL
3147
- * for the user to manage their billing.
3148
- */
3149
- customerPortal(options?: RequestOptions): Promise<PortalResponse>;
3150
- }
3151
-
3152
4762
  /**
3153
4763
  * Notifications resource — organization notification management endpoints.
3154
4764
  * @module resources/notifications
@@ -3168,49 +4778,40 @@ declare class Notifications extends BaseResource {
3168
4778
  * POST /notifications/organization
3169
4779
  *
3170
4780
  * Creates a new notification for the organization or a specific user.
4781
+ *
4782
+ * Requires an organization context: an `X-Organization-ID` header is sent
4783
+ * automatically from the client's configured `organizationId` or from
4784
+ * `options.organizationId`. If neither is set, no header is sent and the
4785
+ * backend responds with HTTP 400 ("X-Organization-ID header is required").
4786
+ *
4787
+ * @returns The created notification wrapped in a `{ success, notification }`
4788
+ * envelope.
3171
4789
  */
3172
- create(params: CreateNotificationParams, options?: RequestOptions): Promise<Record<string, unknown>>;
4790
+ create(params: CreateNotificationParams, options?: RequestOptions): Promise<CreateNotificationResponse>;
3173
4791
  }
3174
4792
 
3175
4793
  /**
3176
- * System resource — health, metrics, and timezone endpoints.
4794
+ * System resource — timezone utilities.
3177
4795
  * @module resources/system
3178
4796
  */
3179
4797
 
3180
4798
  /**
3181
- * Provides methods for the `/system` API endpoints.
4799
+ * Provides methods for the `/system` timezone endpoints.
3182
4800
  */
3183
4801
  declare class System extends BaseResource {
3184
- /**
3185
- * GET /system/health
3186
- *
3187
- * Returns the service health status, name, and version.
3188
- */
3189
- health(options?: RequestOptions): Promise<{
3190
- status: string;
3191
- service: string;
3192
- version: string;
3193
- }>;
3194
- /**
3195
- * GET /system/metrics
3196
- *
3197
- * Returns Prometheus-format metrics as plain text.
3198
- * This endpoint bypasses the JSON-parsing logic of `BaseResource.get()` and
3199
- * reads the raw response body as a string.
3200
- */
3201
- metrics(options?: RequestOptions): Promise<string>;
3202
4802
  /**
3203
4803
  * GET /system/timezones
3204
4804
  *
3205
- * Returns the list of supported IANA timezone identifiers.
4805
+ * Returns popular timezone groups plus the full list of IANA identifiers.
3206
4806
  */
3207
- timezones(options?: RequestOptions): Promise<Record<string, unknown>>;
4807
+ timezones(options?: RequestOptions): Promise<TimezoneListResponse>;
3208
4808
  /**
3209
4809
  * GET /system/timezones/search
3210
4810
  *
3211
- * Searches supported IANA timezone identifiers by query string.
4811
+ * Searches supported IANA timezones by query string. `query` must be at least
4812
+ * 2 characters (the backend returns 422 otherwise). Returns at most 20 results.
3212
4813
  */
3213
- searchTimezones(query: string, options?: RequestOptions): Promise<Record<string, unknown>>;
4814
+ searchTimezones(query: string, options?: RequestOptions): Promise<TimezoneOption[]>;
3214
4815
  }
3215
4816
 
3216
4817
  /**
@@ -3237,16 +4838,16 @@ declare class Modulex {
3237
4838
  private _organizations?;
3238
4839
  private _workflows?;
3239
4840
  private _executions?;
4841
+ private _workflowRuns?;
3240
4842
  private _deployments?;
3241
4843
  private _chats?;
3242
4844
  private _credentials?;
3243
4845
  private _integrations?;
3244
4846
  private _knowledge?;
3245
4847
  private _schedules?;
3246
- private _templates?;
3247
4848
  private _composer?;
4849
+ private _assistant?;
3248
4850
  private _dashboard?;
3249
- private _subscriptions?;
3250
4851
  private _notifications?;
3251
4852
  private _system?;
3252
4853
  constructor(config: ModulexConfig);
@@ -3258,8 +4859,10 @@ declare class Modulex {
3258
4859
  get organizations(): Organizations;
3259
4860
  /** Workflow CRUD endpoints. */
3260
4861
  get workflows(): Workflows;
3261
- /** Workflow execution endpoints (run, resume, cancel, listen). */
4862
+ /** Workflow execution-control endpoints (run, resume, cancel, listen). */
3262
4863
  get executions(): Executions;
4864
+ /** Durable workflow run-history endpoints (list, get persisted runs). */
4865
+ get workflowRuns(): WorkflowRuns;
3263
4866
  /** Workflow deployment endpoints. */
3264
4867
  get deployments(): Deployments;
3265
4868
  /** Chat endpoints. */
@@ -3272,14 +4875,12 @@ declare class Modulex {
3272
4875
  get knowledge(): Knowledge;
3273
4876
  /** Schedule management endpoints. */
3274
4877
  get schedules(): Schedules;
3275
- /** Template endpoints. */
3276
- get templates(): Templates;
3277
4878
  /** Composer (AI workflow builder) endpoints. */
3278
4879
  get composer(): Composer;
4880
+ /** Assistant (HITL chat agent) endpoints. */
4881
+ get assistant(): Assistant;
3279
4882
  /** Dashboard and analytics endpoints. */
3280
4883
  get dashboard(): Dashboard;
3281
- /** Subscription and billing endpoints. */
3282
- get subscriptions(): Subscriptions;
3283
4884
  /** Notification endpoints. */
3284
4885
  get notifications(): Notifications;
3285
4886
  /** System health and utility endpoints. */
@@ -3288,11 +4889,22 @@ declare class Modulex {
3288
4889
 
3289
4890
  /**
3290
4891
  * Base error class for all ModuleX SDK errors.
4892
+ *
4893
+ * When the API returns a structured error envelope — either a dict-shaped
4894
+ * `detail` (e.g. rate-limit) or a flat top-level `{code, reason, ...}` body
4895
+ * (e.g. BillingDenied, which has no `detail` wrapper) — the `code`, `reason`
4896
+ * and `layer` fields are surfaced here for programmatic handling.
3291
4897
  */
3292
4898
  declare class ModulexError extends Error {
3293
4899
  readonly status: number | undefined;
3294
4900
  readonly body: unknown;
3295
4901
  readonly headers: Headers | undefined;
4902
+ /** Machine-readable error code from the API envelope, if present. */
4903
+ readonly code?: string;
4904
+ /** Human-readable reason from the API envelope, if present. */
4905
+ readonly reason?: string;
4906
+ /** The layer/subsystem that produced the error (e.g. "billing", "auth"), if present. */
4907
+ readonly layer?: string;
3296
4908
  constructor(message: string, status: number | undefined, body: unknown, headers: Headers | undefined);
3297
4909
  }
3298
4910
  /** Thrown when the API returns 400 Bad Request. */
@@ -3321,8 +4933,14 @@ declare class ValidationError extends ModulexError {
3321
4933
  }
3322
4934
  /** Thrown when the API returns 429 Too Many Requests. */
3323
4935
  declare class RateLimitError extends ModulexError {
3324
- /** Seconds to wait before retrying (from Retry-After header). */
4936
+ /** Seconds to wait before retrying (from the Retry-After header). */
3325
4937
  readonly retryAfter: number | undefined;
4938
+ /** The rate limit ceiling, from the X-RateLimit-Limit header. */
4939
+ readonly limit: number | undefined;
4940
+ /** Remaining requests in the window, from the X-RateLimit-Remaining header. */
4941
+ readonly remaining: number | undefined;
4942
+ /** Unix epoch (seconds) when the window resets, from the X-RateLimit-Reset header. */
4943
+ readonly reset: number | undefined;
3326
4944
  constructor(message: string, body: unknown, headers: Headers | undefined);
3327
4945
  }
3328
4946
  /** Thrown when the API returns 500 Internal Server Error. */
@@ -3346,4 +4964,4 @@ declare class TimeoutError extends ModulexError {
3346
4964
  constructor(message?: string);
3347
4965
  }
3348
4966
 
3349
- export { type ActivateDeploymentResponse, type AgentNodeConfig, type AnalyticsLLMUsageResponse, type AnalyticsOverviewParams, type AnalyticsOverviewResponse, type AnalyticsToolsParams, type AnalyticsToolsResponse, type ApiKeyListResponse, type ApiKeyResponse, AuthenticationError, BadRequestError, type BillingResponse, type BrowseParams, type BrowseResponse, type BuilderDetailsParams, type BuilderDetailsResponse, type CancelInvitationResponse, type CancelResponse, type ChatListResponse, type ChatMessageResponse, type ChatMessagesParams, type ChatMessagesResponse, type ChatResponse, type CheckoutParams, type CheckoutResponse, type ChunkResponse, type ChunkingConfig, type ComposerChatDetailResponse, type ComposerChatParams, type ComposerChatResponse, type ComposerDeleteParams, type ComposerHistoryParams, type ComposerStatusResponse, type ConditionalBranch, type ConditionalNodeConfig, ConflictError, type CreateApiKeyParams, type CreateApiKeyResponse, type CreateCreatorParams, type CreateCredentialParams, type CreateDeploymentParams, type CreateKnowledgeBaseParams, type CreateNotificationParams, type CreateOrganizationParams, type CreateOrganizationResponse, type CreateScheduleParams, type CreateTemplateParams, type CreateWorkflowParams, type CreatorInfo, type CredentialAuditParams, type CredentialListFlat, type CredentialListGrouped, type CredentialListParams, type CredentialResponse, type CredentialUsageParams, type CredentialUsageResponse, type DashboardLogsParams, type DashboardLogsResponse, type DashboardUsersParams, type DashboardUsersResponse, type DeactivateDeploymentResponse, type DeleteDeploymentResponse, type DeleteWorkflowResponse, type DeploymentDetailResponse, type DeploymentListParams, type DeploymentListResponse, type DeploymentResponse, type DocumentChunksParams, type DocumentChunksResponse, type DocumentListParams, type DocumentResponse, type DocumentStatusResponse, type DoneEventData, type EdgeDefinition, type EmbeddingConfig, type ErrorEventData, ExternalServiceError, type FunctionNodeConfig, type GuardrailsNodeConfig, type HybridSearchParams, type IntegrationResponse, InternalError, type InterruptEventData, type InterruptNodeConfig, type InvitationResponse, type InvitationsResponse, type InviteParams, type KnowledgeBaseListParams, type KnowledgeBaseListResponse, type KnowledgeBaseResponse, type KnowledgeBaseStatsResponse, type KnowledgeNodeConfig, type KnowledgeProviderResponse, type LLMConfig, type LLMNodeConfig, type LLMProviderResponse, type LLMsResponse, type LeaveResponse, type LoopConfig, type McpServerParams, type McpToolsResponse, type MetadataEventData, Modulex, type ModulexConfig, ModulexError, type MultiSearchParams, type MyTemplatesResponse, type NodeDefinition, type NodeType, type NodeUpdateEventData, NotFoundError, type NotificationListResponse, type NotificationResponse, type OrganizationInfo, type OrganizationPlansResponse, type OrganizationsResponse, type PaginatedList, PermissionError, type Plan, type PlanPrice, type PortalResponse, RateLimitError, type RefreshDiscoveryResponse, type RequestOptions, type ResumedEventData, type RetrieveContextParams, type RetrieveContextResponse, type RetryConfig, type RevokeApiKeyResponse, type RoleUpdateParams, type RoleUpdateResponse, type SSEEvent, type ScheduleListParams, type ScheduleListResponse, type ScheduleResponse, type ScheduleRunListParams, type ScheduleRunResponse, type ScheduleRunStatsParams, type ScheduleRunStatsResponse, type SearchParams, type SearchResponse, type SearchResult, ServiceUnavailableError, type StateSchema, type StateSchemaField, StreamError, type Subscription, type SuccessResponse, type SupportedFileTypesResponse, type TemplateLikeResponse, type TemplateListResponse, type TemplateResponse, type TemplateUseResponse, type TestCredentialResponse, type TestTemporaryParams, type TestTemporaryResponse, TimeoutError, type ToolDefinition, type ToolIntegrationResponse, type ToolNodeConfig, type TransformerNodeConfig, type TransformerOperation, type UpdateChatParams, type UpdateCredentialParams, type UpdateKnowledgeBaseParams, type UpdateScheduleParams, type UpdateTemplateRequestParams, type UpdateWorkflowParams, type UploadDocumentParams, type UserResponse, ValidationError, type WorkflowConfig, type WorkflowDefinition, type WorkflowListParams, type WorkflowListResponse, type WorkflowMetadata, type WorkflowResponse, type WorkflowResumeParams, type WorkflowResumeResponse, type WorkflowRunParams, type WorkflowRunResponse, type WorkflowSSEEvent, type WorkflowStateResponse, type WorkflowSummary };
4967
+ export { type AcceptedInvitationOrganization, type ActivateDeploymentResponse, type AgentNodeConfig, type AnalyticsLLMUsageData, type AnalyticsLLMUsageParams, type AnalyticsLLMUsageResponse, type AnalyticsLLMUsageSuccess, type AnalyticsOverview, type AnalyticsOverviewParams, type AnalyticsOverviewResponse, type AnalyticsOverviewSuccess, type AnalyticsSubscription, type AnalyticsToolsData, type AnalyticsToolsParams, type AnalyticsToolsResponse, type AnalyticsToolsSuccess, type ApiKeyListResponse, type ApiKeyResponse, type AssistantCancelResponse, type AssistantChatDetailResponse, type AssistantChatListResponse, type AssistantChatParams, type AssistantChatResponse, type AssistantChatSummary, type AssistantDeleteParams, type AssistantDeleteResponse, type AssistantListParams, type AssistantMessageResponse, type AssistantResumeParams, type AssistantResumeResponse, type AssistantSSEEvent, type AssistantStatusResponse, type AuditLogResponse, type AuthSchema, AuthenticationError, BadRequestError, type BrowseParams, type BrowseResponse, type BuilderDetailsParams, type BuilderDetailsResponse, type BuilderNodeTypeDescriptor, type CancelInvitationResponse, type CancelResponse, type ChatConnectedEvent, type ChatListItem, type ChatListResponse, type ChatListUpdatedEvent, type ChatMessageResponse, type ChatMessagesParams, type ChatMessagesResponse, type ChatResponse, type ChoiceOption, type ChunkResponse, type ChunkingConfig, type ComposerCancelResponse, type ComposerChatDetailResponse, type ComposerChatListItem, type ComposerChatListResponse, type ComposerChatParams, type ComposerChatResponse, type ComposerDeleteParams, type ComposerDeleteResponse, type ComposerFocusParams, type ComposerFocusResponse, type ComposerLLMParams, type ComposerLLMResponse, type ComposerLLMSelection, type ComposerListParams, type ComposerMessageResponse, type ComposerResumeParams, type ComposerResumeResponse, type ComposerRevertResponse, type ComposerSSEEvent, type ComposerSaveParams, type ComposerSaveResponse, type ComposerStatusResponse, type ComposerWorkflowSync, type ConditionalBranch, type ConditionalNodeConfig, ConflictError, type CreateApiKeyParams, type CreateApiKeyResponse, type CreateCredentialParams, type CreateDeploymentParams, type CreateKnowledgeBaseParams, type CreateNotificationParams, type CreateNotificationResponse, type CreateOrganizationParams, type CreateOrganizationResponse, type CreateScheduleParams, type CreateWorkflowParams, type CreatedNotification, type CredentialAddedResponse, type CredentialAuditParams, type CredentialAuthOption, type CredentialDetailResponse, type CredentialFailedResponse, type CredentialFailureCode, type CredentialListFlat, type CredentialListGrouped, type CredentialListParams, type CredentialRequest, type CredentialResponse, type CredentialUsageParams, type CredentialUsageResponse, type CurrentMonthCreditUsage, type DashboardErrorEnvelope, type DashboardInvitationUser, type DashboardLogsFilters, type DashboardLogsParams, type DashboardLogsResponse, type DashboardLogsSuccess, type DashboardMemberUser, type DashboardUser, type DashboardUsersParams, type DashboardUsersResponse, type DashboardUsersSuccess, type DeactivateDeploymentResponse, type DeleteDeploymentResponse, type DeleteScheduleResponse, type DeleteWorkflowResponse, type DeploymentDetailResponse, type DeploymentListParams, type DeploymentListResponse, type DeploymentResponse, type DocumentChunksParams, type DocumentChunksResponse, type DocumentListParams, type DocumentResponse, type DocumentStatusResponse, type DoneEventData, type EdgeDefinition, type EmbeddingConfig, type ErrorEventData, ExternalServiceError, type FreeTextRequest, type FreeTextResponse, type FunctionNodeConfig, type GuardrailsNodeConfig, type HybridSearchParams, type InitiateOAuth2Params, type IntegrationDetail, type IntegrationMetadata, type IntegrationResponse, InternalError, type InterruptEventData, type InterruptNodeConfig, type InvitationInviter, type InvitationNotification, type InvitationObject, type InvitationOrganization, type InvitationResponse, type InvitationsResponse, type InviteParams, type InvitePreviewResponse, type KnowledgeBaseListParams, type KnowledgeBaseResponse, type KnowledgeBaseStatsResponse, type KnowledgeNodeConfig, type KnowledgeProviderResponse, type LLMConfig, type LLMModelEntry, type LLMNodeConfig, type LLMProviderResponse, type LLMUsage, type LLMsResponse, type LeaveResponse, type LoopConfig, type MCPServerCredentialResponse, type McpServerParams, type McpToolsResponse, type MetadataEventData, Modulex, type ModulexConfig, ModulexError, type ModulexKeyBulkEventData, type ModulexKeyBulkSummary, type ModulexKeyIntegrationStatus, type MostUsedAction, type MultiChoiceRequest, type MultiChoiceResponse, type MultiSearchParams, type NodeDefinition, type NodeStartedEventData, type NodeType, type NodeUpdateEventData, NotFoundError, type NotificationBase, type NotificationListResponse, type NotificationResponse, type OAuth2InitiateResponse, type OrganizationInfo, type OrganizationNotification, type OrganizationNotificationTopic, type OrganizationsResponse, type OverviewCredentialUsageLog, type PaginatedList, PermissionError, RateLimitError, type RefreshDiscoveryResponse, type RequestOptions, type ResumedEventData, type RetrieveContextParams, type RetrieveContextResponse, type RetryConfig, type RetryRunResponse, type RevokeApiKeyResponse, type RoleUpdateParams, type RoleUpdateResponse, type SSEEvent, type ScheduleListParams, type ScheduleListResponse, type ScheduleResponse, type ScheduleRunListParams, type ScheduleRunListResponse, type ScheduleRunResponse, type ScheduleRunStatsParams, type ScheduleRunStatsResponse, type SearchMatch, type SearchParams, type SearchResponse, ServiceUnavailableError, type SetModelVisibilityParams, type SetModelVisibilityResponse, type SettingsResponse, type SingleChoiceRequest, type SingleChoiceResponse, type SkippedResponse, type StateSchema, type StateSchemaField, StreamError, type SuccessResponse, type SupportedFileTypesResponse, type SystemNotification, type SystemNotificationTopic, type TestCredentialResponse, type TestTemporaryParams, type TestTemporaryResponse, TimeoutError, type TimezoneGroup, type TimezoneListResponse, type TimezoneOption, type ToolDefinition, type ToolIntegrationResponse, type ToolNodeConfig, type ToolUsage, type TransformerNodeConfig, type TransformerOperation, type UpdateChatParams, type UpdateCredentialParams, type UpdateKnowledgeBaseParams, type UpdateScheduleParams, type UpdateWorkflowParams, type UploadDocumentParams, type UserInputRequest, type UserInputRequestBase, type UserInputResponse, type UserResponse, ValidationError, type WorkflowChangeEvent, type WorkflowConfig, type WorkflowDefinition, type WorkflowListParams, type WorkflowListResponse, type WorkflowMessageEnvelope, type WorkflowMetadata, type WorkflowResponse, type WorkflowResumeParams, type WorkflowResumeResponse, type WorkflowRunDetail, type WorkflowRunListItem, type WorkflowRunListParams, type WorkflowRunListResponse, type WorkflowRunParams, type WorkflowRunResponse, type WorkflowSSEEvent, type WorkflowStateResponse, type WorkflowSummary, type YesNoRequest, type YesNoResponse };