@cadraos/sdk 0.3.14 → 0.3.16-dev.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.
@@ -68,7 +68,8 @@ interface RequestOptions {
68
68
  /**
69
69
  * Per-request timeout in milliseconds. Overrides the client-wide
70
70
  * `config.timeout` for this call only (p93 AIF-010: a paid AI-function run
71
- * may take up to 60 s while every other call keeps the 30 s default).
71
+ * waits for the server's route ceiling while every other call keeps the
72
+ * 30 s default).
72
73
  */
73
74
  timeoutMs?: number;
74
75
  }
@@ -80,6 +81,8 @@ declare class HttpClient {
80
81
  private tokenRefreshAttempts;
81
82
  private readonly maxTokenRefreshAttempts;
82
83
  constructor(config: HttpClientConfig);
84
+ /** The client-wide request timeout (ms) this client was configured with. */
85
+ get timeoutMs(): number;
83
86
  /**
84
87
  * Get authorization header value
85
88
  */
@@ -390,6 +393,51 @@ interface ExecuteResponse {
390
393
  /** Initial status */
391
394
  status: ExecutionStatus;
392
395
  }
396
+ /**
397
+ * Languages an agent message can be stored and rendered in.
398
+ */
399
+ type AgentMessageLang = 'en' | 'es' | 'id';
400
+ /**
401
+ * One saved agent message (e.g. `handoff.requested`), text per language.
402
+ */
403
+ interface AgentMessage {
404
+ /** Lowercase dotted key, e.g. `chat.welcome` */
405
+ key: string;
406
+ /** Text per language; `en` is the fallback language */
407
+ text: Partial<Record<AgentMessageLang, string>>;
408
+ /** `{word}` placeholder names found in any language */
409
+ placeholders: string[];
410
+ }
411
+ /**
412
+ * Response of `client.agents.messages.list()`
413
+ */
414
+ interface AgentMessageList {
415
+ /** The resolved agent (a team uuid resolves to its lead agent) */
416
+ agentUuid: string;
417
+ /** The agent's saved messages, sorted by key */
418
+ messages: AgentMessage[];
419
+ /** Every key the platform knows about, for pickers (saved or not) */
420
+ knownKeys: string[];
421
+ }
422
+ /**
423
+ * Options for `client.agents.messages.render()`
424
+ */
425
+ interface AgentMessageRenderOptions {
426
+ /** Requested language; falls back to `en` server-side */
427
+ lang?: AgentMessageLang;
428
+ /** Values for `{word}` placeholders; unknown placeholders are left as-is */
429
+ vars?: Record<string, string | number>;
430
+ }
431
+ /**
432
+ * Response of `client.agents.messages.render()`
433
+ */
434
+ interface AgentMessageRenderResult {
435
+ key: string;
436
+ /** The language actually rendered */
437
+ lang: AgentMessageLang;
438
+ /** Filled text, or `null` when the agent has no message for this key */
439
+ text: string | null;
440
+ }
393
441
 
394
442
  /**
395
443
  * Skill types
@@ -1646,6 +1694,46 @@ interface StreamImagesResult {
1646
1694
  executionId: string;
1647
1695
  }
1648
1696
 
1697
+ /**
1698
+ * Agent Messages Resource API (p13)
1699
+ *
1700
+ * Read-only access to an agent's saved messages (welcome, handoff, fallback
1701
+ * copy, ...). Reached as `client.agents.messages`.
1702
+ * - list(): the agent's saved messages + every known key
1703
+ * - render(): one message filled with vars, in a language (falls back to en)
1704
+ */
1705
+
1706
+ declare class AgentMessagesAPI extends BaseResourceAPI {
1707
+ constructor(http: HttpClient);
1708
+ /**
1709
+ * List an agent's saved messages and the known keys
1710
+ *
1711
+ * @param agentUuid - Agent UUID (a team UUID resolves to its lead agent)
1712
+ *
1713
+ * @example
1714
+ * ```typescript
1715
+ * const { messages, knownKeys } = await client.agents.messages.list('agent-uuid');
1716
+ * ```
1717
+ */
1718
+ list(agentUuid: string): Promise<AgentMessageList>;
1719
+ /**
1720
+ * Render one message with placeholders filled
1721
+ *
1722
+ * Resolves with `text: null` when the agent has no message for the key.
1723
+ * Throws `ValidationError` before any request when the key is not a
1724
+ * lowercase dotted key (see `MESSAGE_KEY_PATTERN`).
1725
+ *
1726
+ * @example
1727
+ * ```typescript
1728
+ * const { text } = await client.agents.messages.render('agent-uuid', 'handoff.requested', {
1729
+ * lang: 'es',
1730
+ * vars: { agentName: 'Ana' },
1731
+ * });
1732
+ * ```
1733
+ */
1734
+ render(agentUuid: string, key: string, options?: AgentMessageRenderOptions): Promise<AgentMessageRenderResult>;
1735
+ }
1736
+
1649
1737
  /**
1650
1738
  * Agents Resource API
1651
1739
  *
@@ -1661,6 +1749,8 @@ interface StreamImagesResult {
1661
1749
  */
1662
1750
  declare class AgentsAPI extends BaseResourceAPI {
1663
1751
  private readonly getStreamConfig;
1752
+ /** Saved agent messages (p13): `list()` and `render()` */
1753
+ readonly messages: AgentMessagesAPI;
1664
1754
  constructor(http: HttpClient, getStreamConfig: () => StreamConfig);
1665
1755
  /**
1666
1756
  * List all agents in the organization
@@ -68,7 +68,8 @@ interface RequestOptions {
68
68
  /**
69
69
  * Per-request timeout in milliseconds. Overrides the client-wide
70
70
  * `config.timeout` for this call only (p93 AIF-010: a paid AI-function run
71
- * may take up to 60 s while every other call keeps the 30 s default).
71
+ * waits for the server's route ceiling while every other call keeps the
72
+ * 30 s default).
72
73
  */
73
74
  timeoutMs?: number;
74
75
  }
@@ -80,6 +81,8 @@ declare class HttpClient {
80
81
  private tokenRefreshAttempts;
81
82
  private readonly maxTokenRefreshAttempts;
82
83
  constructor(config: HttpClientConfig);
84
+ /** The client-wide request timeout (ms) this client was configured with. */
85
+ get timeoutMs(): number;
83
86
  /**
84
87
  * Get authorization header value
85
88
  */
@@ -390,6 +393,51 @@ interface ExecuteResponse {
390
393
  /** Initial status */
391
394
  status: ExecutionStatus;
392
395
  }
396
+ /**
397
+ * Languages an agent message can be stored and rendered in.
398
+ */
399
+ type AgentMessageLang = 'en' | 'es' | 'id';
400
+ /**
401
+ * One saved agent message (e.g. `handoff.requested`), text per language.
402
+ */
403
+ interface AgentMessage {
404
+ /** Lowercase dotted key, e.g. `chat.welcome` */
405
+ key: string;
406
+ /** Text per language; `en` is the fallback language */
407
+ text: Partial<Record<AgentMessageLang, string>>;
408
+ /** `{word}` placeholder names found in any language */
409
+ placeholders: string[];
410
+ }
411
+ /**
412
+ * Response of `client.agents.messages.list()`
413
+ */
414
+ interface AgentMessageList {
415
+ /** The resolved agent (a team uuid resolves to its lead agent) */
416
+ agentUuid: string;
417
+ /** The agent's saved messages, sorted by key */
418
+ messages: AgentMessage[];
419
+ /** Every key the platform knows about, for pickers (saved or not) */
420
+ knownKeys: string[];
421
+ }
422
+ /**
423
+ * Options for `client.agents.messages.render()`
424
+ */
425
+ interface AgentMessageRenderOptions {
426
+ /** Requested language; falls back to `en` server-side */
427
+ lang?: AgentMessageLang;
428
+ /** Values for `{word}` placeholders; unknown placeholders are left as-is */
429
+ vars?: Record<string, string | number>;
430
+ }
431
+ /**
432
+ * Response of `client.agents.messages.render()`
433
+ */
434
+ interface AgentMessageRenderResult {
435
+ key: string;
436
+ /** The language actually rendered */
437
+ lang: AgentMessageLang;
438
+ /** Filled text, or `null` when the agent has no message for this key */
439
+ text: string | null;
440
+ }
393
441
 
394
442
  /**
395
443
  * Skill types
@@ -1646,6 +1694,46 @@ interface StreamImagesResult {
1646
1694
  executionId: string;
1647
1695
  }
1648
1696
 
1697
+ /**
1698
+ * Agent Messages Resource API (p13)
1699
+ *
1700
+ * Read-only access to an agent's saved messages (welcome, handoff, fallback
1701
+ * copy, ...). Reached as `client.agents.messages`.
1702
+ * - list(): the agent's saved messages + every known key
1703
+ * - render(): one message filled with vars, in a language (falls back to en)
1704
+ */
1705
+
1706
+ declare class AgentMessagesAPI extends BaseResourceAPI {
1707
+ constructor(http: HttpClient);
1708
+ /**
1709
+ * List an agent's saved messages and the known keys
1710
+ *
1711
+ * @param agentUuid - Agent UUID (a team UUID resolves to its lead agent)
1712
+ *
1713
+ * @example
1714
+ * ```typescript
1715
+ * const { messages, knownKeys } = await client.agents.messages.list('agent-uuid');
1716
+ * ```
1717
+ */
1718
+ list(agentUuid: string): Promise<AgentMessageList>;
1719
+ /**
1720
+ * Render one message with placeholders filled
1721
+ *
1722
+ * Resolves with `text: null` when the agent has no message for the key.
1723
+ * Throws `ValidationError` before any request when the key is not a
1724
+ * lowercase dotted key (see `MESSAGE_KEY_PATTERN`).
1725
+ *
1726
+ * @example
1727
+ * ```typescript
1728
+ * const { text } = await client.agents.messages.render('agent-uuid', 'handoff.requested', {
1729
+ * lang: 'es',
1730
+ * vars: { agentName: 'Ana' },
1731
+ * });
1732
+ * ```
1733
+ */
1734
+ render(agentUuid: string, key: string, options?: AgentMessageRenderOptions): Promise<AgentMessageRenderResult>;
1735
+ }
1736
+
1649
1737
  /**
1650
1738
  * Agents Resource API
1651
1739
  *
@@ -1661,6 +1749,8 @@ interface StreamImagesResult {
1661
1749
  */
1662
1750
  declare class AgentsAPI extends BaseResourceAPI {
1663
1751
  private readonly getStreamConfig;
1752
+ /** Saved agent messages (p13): `list()` and `render()` */
1753
+ readonly messages: AgentMessagesAPI;
1664
1754
  constructor(http: HttpClient, getStreamConfig: () => StreamConfig);
1665
1755
  /**
1666
1756
  * List all agents in the organization
@@ -291,6 +291,10 @@ var HttpClient = class {
291
291
  constructor(config) {
292
292
  this.config = config;
293
293
  }
294
+ /** The client-wide request timeout (ms) this client was configured with. */
295
+ get timeoutMs() {
296
+ return this.config.timeout;
297
+ }
294
298
  /**
295
299
  * Get authorization header value
296
300
  */
@@ -1806,13 +1810,69 @@ function executionCancelPath(executionId) {
1806
1810
  return `${EXECUTION_PATH}/${executionId}/cancel`;
1807
1811
  }
1808
1812
 
1813
+ // src/utils/message-key.ts
1814
+ var MESSAGE_KEY_PATTERN = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+$/;
1815
+ function isValidMessageKey(key) {
1816
+ return MESSAGE_KEY_PATTERN.test(key);
1817
+ }
1818
+
1819
+ // src/resources/agent-messages.ts
1820
+ var AgentMessagesAPI = class extends BaseResourceAPI {
1821
+ constructor(http) {
1822
+ super(http, "/api/v1/agents");
1823
+ }
1824
+ /**
1825
+ * List an agent's saved messages and the known keys
1826
+ *
1827
+ * @param agentUuid - Agent UUID (a team UUID resolves to its lead agent)
1828
+ *
1829
+ * @example
1830
+ * ```typescript
1831
+ * const { messages, knownKeys } = await client.agents.messages.list('agent-uuid');
1832
+ * ```
1833
+ */
1834
+ async list(agentUuid) {
1835
+ return this.httpGet(`/${agentUuid}/messages`);
1836
+ }
1837
+ /**
1838
+ * Render one message with placeholders filled
1839
+ *
1840
+ * Resolves with `text: null` when the agent has no message for the key.
1841
+ * Throws `ValidationError` before any request when the key is not a
1842
+ * lowercase dotted key (see `MESSAGE_KEY_PATTERN`).
1843
+ *
1844
+ * @example
1845
+ * ```typescript
1846
+ * const { text } = await client.agents.messages.render('agent-uuid', 'handoff.requested', {
1847
+ * lang: 'es',
1848
+ * vars: { agentName: 'Ana' },
1849
+ * });
1850
+ * ```
1851
+ */
1852
+ async render(agentUuid, key, options = {}) {
1853
+ if (!isValidMessageKey(key)) {
1854
+ throw new ValidationError(`Invalid message key "${key}"`, [
1855
+ { field: "key", message: "Must be a lowercase dotted key, e.g. chat.welcome" }
1856
+ ]);
1857
+ }
1858
+ return this.httpPost(`/${agentUuid}/messages/render`, {
1859
+ key,
1860
+ ...options.lang ? { lang: options.lang } : {},
1861
+ ...options.vars ? { vars: options.vars } : {}
1862
+ });
1863
+ }
1864
+ };
1865
+
1809
1866
  // src/resources/agents.ts
1810
1867
  var AgentsAPI = class extends BaseResourceAPI {
1811
1868
  constructor(http, getStreamConfig) {
1812
1869
  super(http, "/api/v1/agents");
1813
1870
  this.getStreamConfig = getStreamConfig;
1871
+ this.messages = new AgentMessagesAPI(http);
1814
1872
  }
1815
1873
  getStreamConfig;
1874
+ /** Saved agent messages (p13): `list()` and `render()` */
1875
+ messages;
1816
1876
  // ===== LIST Operations =====
1817
1877
  /**
1818
1878
  * List all agents in the organization
@@ -3407,7 +3467,7 @@ var RemoteRunnersAPI = class extends BaseResourceAPI {
3407
3467
  };
3408
3468
 
3409
3469
  // src/resources/ai-functions.ts
3410
- var AI_FUNCTION_RUN_TIMEOUT_MS = 6e4;
3470
+ var AI_FUNCTION_RUN_TIMEOUT_MS = 31e4;
3411
3471
  var AI_FUNCTION_DESCRIPTOR_TTL_MS = 6e4;
3412
3472
  function checkAiFunctionParameters(parameters, variables) {
3413
3473
  const issues = [];
@@ -3520,7 +3580,7 @@ var AiFunctionsAPI = class extends BaseResourceAPI {
3520
3580
  try {
3521
3581
  return await this.httpPost("/run", body, {
3522
3582
  skipRetry: true,
3523
- timeoutMs: AI_FUNCTION_RUN_TIMEOUT_MS
3583
+ timeoutMs: Math.max(AI_FUNCTION_RUN_TIMEOUT_MS, this.http.timeoutMs ?? 0)
3524
3584
  });
3525
3585
  } catch (error) {
3526
3586
  throw this.mapRunError(error, functionKey);