@cadenya/cadenya 1.3.1 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cadenya/cadenya",
3
- "version": "1.3.1",
3
+ "version": "1.5.0",
4
4
  "description": "The official TypeScript SDK for the Cadenya API",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/client.ts CHANGED
@@ -35,7 +35,7 @@ export interface ClientOptions {
35
35
  * Defaults to 60000; a non-finite or <= 0 value disables the deadline.
36
36
  */
37
37
  timeout?: number;
38
- /** Headers sent with every request. */
38
+ /** Additional request headers. Browsers supply their own User-Agent by default. */
39
39
  defaultHeaders?: Record<string, string>;
40
40
  /** Custom fetch implementation. */
41
41
  fetch?: typeof fetch;
@@ -85,7 +85,7 @@ export class Cadenya {
85
85
  authHeader: () => ({ Authorization: `Bearer ${apiKey}` }),
86
86
  maxRetries: options.maxRetries ?? 0,
87
87
  timeout: options.timeout,
88
- defaultHeaders: { 'User-Agent': 'cadenya-typescript/1.3.0 (api 1.0)', ...options.defaultHeaders },
88
+ defaultHeaders: { ...nodeUserAgent('cadenya-typescript/1.5.0 (api 1.0)'), ...options.defaultHeaders },
89
89
  fetch: options.fetch,
90
90
  logger: options.logger,
91
91
  logLevel: options.logLevel,
@@ -112,6 +112,14 @@ export class Cadenya {
112
112
  }
113
113
  }
114
114
 
115
+ // Browser-authored User-Agent headers require CORS permission. Only Node-compatible
116
+ // runtimes receive the SDK default; browsers and workers use their native header.
117
+ function nodeUserAgent(value: string): Record<string, string> {
118
+ const nodeVersion = (globalThis as { process?: { versions?: { node?: string } } })
119
+ .process?.versions?.node;
120
+ return nodeVersion ? { 'User-Agent': value } : {};
121
+ }
122
+
115
123
  function readEnv(name: string): string | undefined {
116
124
  const env = (globalThis as { process?: { env?: Record<string, string | undefined> } })
117
125
  .process?.env;
@@ -141,7 +141,7 @@ export class WidgetSessions {
141
141
  *
142
142
  * @example
143
143
  * ```ts
144
- * const widgetSession = await client.widgetSessions.create({ spec: { widgetId: 'sample' } });
144
+ * const widgetSession = await client.widgetSessions.create({ spec: { subject: { id: 'sample' }, tenant: { id: 'sample' }, widgetId: 'sample' } });
145
145
  * ```
146
146
  */
147
147
  create(params: WidgetSessionCreateParams, options?: RequestOptions): APIPromise<WidgetSession> {
package/src/types.ts CHANGED
@@ -2499,6 +2499,10 @@ export interface ObjectiveError {
2499
2499
  }
2500
2500
 
2501
2501
  export interface ObjectiveEvent {
2502
+ /**
2503
+ * Durable events use objevt_ IDs, the only IDs accepted as reconnect
2504
+ * cursors. Live-only heartbeats use hb_ IDs and have no SSE id: field.
2505
+ */
2502
2506
  metadata: OperationMetadata;
2503
2507
  data: ObjectiveEventData;
2504
2508
  contextWindowId: string;
@@ -2538,7 +2542,8 @@ export type ObjectiveEventData =
2538
2542
  | ObjectiveEventData_Notice
2539
2543
  | ObjectiveEventData_TimedOut
2540
2544
  | ObjectiveEventData_Reasoning
2541
- | ObjectiveEventData_StateChanged;
2545
+ | ObjectiveEventData_StateChanged
2546
+ | ObjectiveEventData_Heartbeat;
2542
2547
 
2543
2548
  export interface ObjectiveEventInfo {
2544
2549
  objective?: OperationMetadata;
@@ -2596,6 +2601,15 @@ export interface ObjectiveFinalized {
2596
2601
  output?: Record<string, unknown>;
2597
2602
  }
2598
2603
 
2604
+ /**
2605
+ * ObjectiveHeartbeat reports recent execution liveness. It is transient:
2606
+ * delivered only on live streams, never stored in event history or delivered
2607
+ * to webhooks. Its hb_ event ID is not a reconnect cursor. Heartbeats do not
2608
+ * change objective state or promise progress from the model.
2609
+ */
2610
+ export interface ObjectiveHeartbeat {
2611
+ }
2612
+
2599
2613
  /**
2600
2614
  * ObjectiveInfo provides read-only aggregated statistics about an objective's execution
2601
2615
  */
@@ -3502,6 +3516,10 @@ export interface SetToolCallContentRequest_TextBlock {
3502
3516
  text: string;
3503
3517
  }
3504
3518
 
3519
+ export type StatusDetails =
3520
+ | WidgetSessionErrorInfo
3521
+ | GoogleProtobufAny;
3522
+
3505
3523
  /**
3506
3524
  * The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).
3507
3525
  */
@@ -3517,7 +3535,7 @@ export interface Status {
3517
3535
  /**
3518
3536
  * A list of messages that carry the error details. There is a common set of message types for APIs to use.
3519
3537
  */
3520
- details?: Array<GoogleProtobufAny>;
3538
+ details?: Array<StatusDetails>;
3521
3539
  }
3522
3540
 
3523
3541
  export interface SubAgentSpawned {
@@ -4860,7 +4878,7 @@ export type WebhookDeliveryDataStatus = 'WEBHOOK_DELIVERY_STATUS_UNSPECIFIED' |
4860
4878
  /**
4861
4879
  * The type of objective event that triggered this webhook delivery
4862
4880
  */
4863
- export type WebhookDeliveryDataEventType = 'OBJECTIVE_EVENT_TYPE_UNSPECIFIED' | 'OBJECTIVE_EVENT_TYPE_USER_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVAL_REQUESTED' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVED' | 'OBJECTIVE_EVENT_TYPE_TOOL_DENIED' | 'OBJECTIVE_EVENT_TYPE_TOOL_CALLED' | 'OBJECTIVE_EVENT_TYPE_ERROR' | 'OBJECTIVE_EVENT_TYPE_ASSISTANT_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_RESULT' | 'OBJECTIVE_EVENT_TYPE_TOOL_ERROR' | 'OBJECTIVE_EVENT_TYPE_CONTEXT_WINDOW_COMPACTED' | 'OBJECTIVE_EVENT_TYPE_MEMORY_READ' | 'OBJECTIVE_EVENT_TYPE_CANCELLED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_SPAWNED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_UPDATED' | 'OBJECTIVE_EVENT_TYPE_FINALIZED' | 'OBJECTIVE_EVENT_TYPE_NOTICE' | 'OBJECTIVE_EVENT_TYPE_TIMED_OUT' | 'OBJECTIVE_EVENT_TYPE_REASONING' | 'OBJECTIVE_EVENT_TYPE_STATE_CHANGED';
4881
+ export type WebhookDeliveryDataEventType = 'OBJECTIVE_EVENT_TYPE_UNSPECIFIED' | 'OBJECTIVE_EVENT_TYPE_USER_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVAL_REQUESTED' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVED' | 'OBJECTIVE_EVENT_TYPE_TOOL_DENIED' | 'OBJECTIVE_EVENT_TYPE_TOOL_CALLED' | 'OBJECTIVE_EVENT_TYPE_ERROR' | 'OBJECTIVE_EVENT_TYPE_ASSISTANT_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_RESULT' | 'OBJECTIVE_EVENT_TYPE_TOOL_ERROR' | 'OBJECTIVE_EVENT_TYPE_CONTEXT_WINDOW_COMPACTED' | 'OBJECTIVE_EVENT_TYPE_MEMORY_READ' | 'OBJECTIVE_EVENT_TYPE_CANCELLED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_SPAWNED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_UPDATED' | 'OBJECTIVE_EVENT_TYPE_FINALIZED' | 'OBJECTIVE_EVENT_TYPE_NOTICE' | 'OBJECTIVE_EVENT_TYPE_TIMED_OUT' | 'OBJECTIVE_EVENT_TYPE_REASONING' | 'OBJECTIVE_EVENT_TYPE_STATE_CHANGED' | 'OBJECTIVE_EVENT_TYPE_HEARTBEAT';
4864
4882
 
4865
4883
  export interface WebhookDeliveryData {
4866
4884
  /**
@@ -4956,8 +4974,9 @@ export type WidgetSessionState = 'STATE_UNSPECIFIED' | 'STATE_ACTIVE' | 'STATE_E
4956
4974
  * a widget, minted server-to-server by the customer's backend. The session
4957
4975
  * carries all customer-asserted context — tenant, subject, labels, secrets —
4958
4976
  * and every conversation (objective) created through the widget inherits it.
4959
- * The bearer token returned at mint is short-lived and refreshed at the
4960
- * widget host; the session row is what makes revocation possible.
4977
+ * The browser renews short-lived bearer tokens at the widget host with
4978
+ * RenewWidgetSession, authenticated by its existing token. Renewal preserves
4979
+ * this bounded grant and does not extend its hard expiry.
4961
4980
  */
4962
4981
  export interface WidgetSession {
4963
4982
  metadata: OperationMetadata;
@@ -4974,6 +4993,45 @@ export interface WidgetSession {
4974
4993
  * headers server-side — never returned by any API.
4975
4994
  */
4976
4995
  secrets: Array<WidgetSession_Secret>;
4996
+ /**
4997
+ * Present only on creation. The same envelope is returned by
4998
+ * RenewWidgetSession on the widget host. Omitted on reads, lists, and revocation.
4999
+ * Existing spec.token/spec.token_expires_at and info.host remain populated
5000
+ * on creation for v1 compatibility and agree with these credentials.
5001
+ */
5002
+ credentials?: WidgetSessionCredentials;
5003
+ }
5004
+
5005
+ /**
5006
+ * WidgetSessionCredentials is the only credential envelope the customer's
5007
+ * backend forwards to the browser. Never log or persist its token. Responses
5008
+ * containing credentials use Cache-Control: no-store. Both initial and later
5009
+ * issuance use the same schema; no refresh token or management key is included.
5010
+ */
5011
+ export interface WidgetSessionCredentials {
5012
+ /**
5013
+ * Canonical wsess_ identifier. Ordinary renewal cannot change the session.
5014
+ */
5015
+ sessionId: string;
5016
+ /**
5017
+ * Authoritative hostname, without a scheme or path. Use HTTPS with this
5018
+ * host; never construct it or accept a host change during renewal.
5019
+ */
5020
+ host: string;
5021
+ /**
5022
+ * Short-lived bearer credential for the widget host only.
5023
+ */
5024
+ token: string;
5025
+ /**
5026
+ * Exact token expiry, at most 15 minutes after issuance and never later
5027
+ * than session_expires_at. Equals JWT exp without the 60-second validation
5028
+ * tolerance added. Renew proactively before this timestamp.
5029
+ */
5030
+ tokenExpiresAt: string;
5031
+ /**
5032
+ * Immutable hard session expiry. Issuance never extends this deadline.
5033
+ */
5034
+ sessionExpiresAt: string;
4977
5035
  }
4978
5036
 
4979
5037
  /**
@@ -5010,7 +5068,7 @@ export interface WidgetSessionInfo {
5010
5068
  messageCount: number;
5011
5069
  /**
5012
5070
  * When the session last created a conversation, sent a message, or
5013
- * refreshed a token.
5071
+ * received a newly issued token.
5014
5072
  */
5015
5073
  lastActiveAt?: string;
5016
5074
  }
@@ -5025,18 +5083,19 @@ export interface WidgetSessionSpec {
5025
5083
  */
5026
5084
  widgetId: string;
5027
5085
  /**
5028
- * Optional tenant assertion — the customer's org/company identifier for the
5029
- * visitor. Upserts the tenant record in the workspace and tags the session
5030
- * and every conversation it creates. Conversation listing at the widget
5031
- * host is scoped to this tenant.
5086
+ * Required tenant assertion — the customer's organization identifier.
5087
+ * Upserts the tenant record in the workspace. Every conversation created
5088
+ * through this session inherits the tenant and subject identity.
5032
5089
  */
5033
- tenant?: TenantAssertion;
5090
+ tenant: TenantAssertion;
5034
5091
  /**
5035
- * Optional subject assertion — the visitor within the tenant (e.g. their
5036
- * user id in the customer's namespace). Requires `tenant`; a subject
5037
- * asserted without a tenant is rejected with InvalidArgument.
5092
+ * Required subject assertion — the visitor's ID within the tenant.
5093
+ * Sessions with the same tenant and subject share conversation history on
5094
+ * the same widget and agent, subject to the current session's permissions.
5095
+ * A static ID deliberately shares that history; use a distinct ID per
5096
+ * visitor when their conversations should be separate.
5038
5097
  */
5039
- subject?: SubjectAssertion;
5098
+ subject: SubjectAssertion;
5040
5099
  /**
5041
5100
  * Hard session expiry. Tokens never outlive it; after it passes the session
5042
5101
  * transitions to STATE_EXPIRED. Defaults to a server-chosen horizon when
@@ -5044,14 +5103,14 @@ export interface WidgetSessionSpec {
5044
5103
  */
5045
5104
  expiresAt?: string;
5046
5105
  /**
5047
- * The session bearer token. Returned only on creation — subsequent reads
5048
- * omit it. The token is short-lived; the widget refreshes it at the widget
5049
- * host without involving the customer's backend.
5106
+ * Legacy creation-only alias of credentials.token; omitted on reads.
5107
+ * Supported throughout v1. New clients should consume credentials.
5108
+ * The browser obtains replacements with RenewWidgetSession at the widget host.
5050
5109
  */
5051
5110
  token: string;
5052
5111
  /**
5053
- * Expiry of the token returned in `token`. Distinct from `expires_at`,
5054
- * which bounds the session itself.
5112
+ * Legacy creation-only alias of credentials.token_expires_at, supported
5113
+ * throughout v1. Distinct from expires_at, which bounds the session itself.
5055
5114
  */
5056
5115
  tokenExpiresAt?: string;
5057
5116
  /**
@@ -5559,6 +5618,11 @@ export interface ObjectiveEventData_StateChanged {
5559
5618
  stateChanged: ObjectiveStateChanged;
5560
5619
  }
5561
5620
 
5621
+ export interface ObjectiveEventData_Heartbeat {
5622
+ type: 'heartbeat';
5623
+ heartbeat: ObjectiveHeartbeat;
5624
+ }
5625
+
5562
5626
  export interface CallableTool_Tool {
5563
5627
  type: 'tool';
5564
5628
  tool: ResourceMetadata;
@@ -5816,13 +5880,31 @@ export interface ModelSpec_Capability_Caching {
5816
5880
  caching: Capability_Caching;
5817
5881
  }
5818
5882
 
5883
+ /**
5884
+ * TOKEN_EXPIRED identifies access-token expiry beyond the 60-second clock-skew tolerance. That token cannot renew; use already-installed newer credentials or require explicit app reauthentication. SESSION_* reasons are terminal. Never infer renewability from HTTP status alone.
5885
+ */
5886
+ export type WidgetSessionErrorReason = 'TOKEN_EXPIRED' | 'SESSION_REVOKED' | 'SESSION_EXPIRED' | 'SESSION_EXHAUSTED';
5887
+
5888
+ /**
5889
+ * google.rpc.ErrorInfo detail for widget lifecycle failures. Match both domain and reason; ignore unknown reasons rather than renewing automatically.
5890
+ */
5891
+ export interface WidgetSessionErrorInfo {
5892
+ '@type': 'type.googleapis.com/google.rpc.ErrorInfo';
5893
+ domain: 'api.cadenya.com';
5894
+ reason: WidgetSessionErrorReason;
5895
+ /**
5896
+ * Optional non-sensitive context. Never contains tokens or secrets.
5897
+ */
5898
+ metadata?: Record<string, string>;
5899
+ }
5900
+
5819
5901
  export type AgentServiceListAgentsState = 'STATE_UNSPECIFIED' | 'STATE_DRAFT' | 'STATE_PUBLISHED' | 'STATE_ARCHIVED';
5820
5902
 
5821
5903
  export type AgentServiceListAgentsVariationSelectionMode = 'VARIATION_SELECTION_MODE_UNSPECIFIED' | 'VARIATION_SELECTION_MODE_RANDOM' | 'VARIATION_SELECTION_MODE_WEIGHTED';
5822
5904
 
5823
5905
  export type AgentServiceListAgentFeedbackSentiment = 'FEEDBACK_SENTIMENT_UNSPECIFIED' | 'FEEDBACK_SENTIMENT_POSITIVE' | 'FEEDBACK_SENTIMENT_NEGATIVE';
5824
5906
 
5825
- export type AgentServiceListAgentWebhookDeliveriesEventType = 'OBJECTIVE_EVENT_TYPE_UNSPECIFIED' | 'OBJECTIVE_EVENT_TYPE_USER_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVAL_REQUESTED' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVED' | 'OBJECTIVE_EVENT_TYPE_TOOL_DENIED' | 'OBJECTIVE_EVENT_TYPE_TOOL_CALLED' | 'OBJECTIVE_EVENT_TYPE_ERROR' | 'OBJECTIVE_EVENT_TYPE_ASSISTANT_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_RESULT' | 'OBJECTIVE_EVENT_TYPE_TOOL_ERROR' | 'OBJECTIVE_EVENT_TYPE_CONTEXT_WINDOW_COMPACTED' | 'OBJECTIVE_EVENT_TYPE_MEMORY_READ' | 'OBJECTIVE_EVENT_TYPE_CANCELLED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_SPAWNED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_UPDATED' | 'OBJECTIVE_EVENT_TYPE_FINALIZED' | 'OBJECTIVE_EVENT_TYPE_NOTICE' | 'OBJECTIVE_EVENT_TYPE_TIMED_OUT' | 'OBJECTIVE_EVENT_TYPE_REASONING' | 'OBJECTIVE_EVENT_TYPE_STATE_CHANGED';
5907
+ export type AgentServiceListAgentWebhookDeliveriesEventType = 'OBJECTIVE_EVENT_TYPE_UNSPECIFIED' | 'OBJECTIVE_EVENT_TYPE_USER_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVAL_REQUESTED' | 'OBJECTIVE_EVENT_TYPE_TOOL_APPROVED' | 'OBJECTIVE_EVENT_TYPE_TOOL_DENIED' | 'OBJECTIVE_EVENT_TYPE_TOOL_CALLED' | 'OBJECTIVE_EVENT_TYPE_ERROR' | 'OBJECTIVE_EVENT_TYPE_ASSISTANT_MESSAGE' | 'OBJECTIVE_EVENT_TYPE_TOOL_RESULT' | 'OBJECTIVE_EVENT_TYPE_TOOL_ERROR' | 'OBJECTIVE_EVENT_TYPE_CONTEXT_WINDOW_COMPACTED' | 'OBJECTIVE_EVENT_TYPE_MEMORY_READ' | 'OBJECTIVE_EVENT_TYPE_CANCELLED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_SPAWNED' | 'OBJECTIVE_EVENT_TYPE_SUB_AGENT_UPDATED' | 'OBJECTIVE_EVENT_TYPE_FINALIZED' | 'OBJECTIVE_EVENT_TYPE_NOTICE' | 'OBJECTIVE_EVENT_TYPE_TIMED_OUT' | 'OBJECTIVE_EVENT_TYPE_REASONING' | 'OBJECTIVE_EVENT_TYPE_STATE_CHANGED' | 'OBJECTIVE_EVENT_TYPE_HEARTBEAT';
5826
5908
 
5827
5909
  export type MemoryServiceListMemoryLayersType = 'MEMORY_LAYER_TYPE_UNSPECIFIED' | 'MEMORY_LAYER_TYPE_EPISODIC' | 'MEMORY_LAYER_TYPE_SKILLS';
5828
5910
 
@@ -5898,18 +5980,19 @@ export interface WidgetSessionSpecParam {
5898
5980
  */
5899
5981
  widgetId: string;
5900
5982
  /**
5901
- * Optional tenant assertion — the customer's org/company identifier for the
5902
- * visitor. Upserts the tenant record in the workspace and tags the session
5903
- * and every conversation it creates. Conversation listing at the widget
5904
- * host is scoped to this tenant.
5983
+ * Required tenant assertion — the customer's organization identifier.
5984
+ * Upserts the tenant record in the workspace. Every conversation created
5985
+ * through this session inherits the tenant and subject identity.
5905
5986
  */
5906
- tenant?: TenantAssertion;
5987
+ tenant: TenantAssertion;
5907
5988
  /**
5908
- * Optional subject assertion — the visitor within the tenant (e.g. their
5909
- * user id in the customer's namespace). Requires `tenant`; a subject
5910
- * asserted without a tenant is rejected with InvalidArgument.
5989
+ * Required subject assertion — the visitor's ID within the tenant.
5990
+ * Sessions with the same tenant and subject share conversation history on
5991
+ * the same widget and agent, subject to the current session's permissions.
5992
+ * A static ID deliberately shares that history; use a distinct ID per
5993
+ * visitor when their conversations should be separate.
5911
5994
  */
5912
- subject?: SubjectAssertion;
5995
+ subject: SubjectAssertion;
5913
5996
  /**
5914
5997
  * Hard session expiry. Tokens never outlive it; after it passes the session
5915
5998
  * transitions to STATE_EXPIRED. Defaults to a server-chosen horizon when