@cadenya/cadenya 1.6.0 → 1.7.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.6.0",
3
+ "version": "1.7.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
@@ -87,7 +87,7 @@ export class Cadenya {
87
87
  authHeader: () => ({ Authorization: `Bearer ${apiKey}` }),
88
88
  maxRetries: options.maxRetries ?? 0,
89
89
  timeout: options.timeout,
90
- defaultHeaders: { ...nodeUserAgent('cadenya-typescript/1.5.0 (api 1.0)'), ...options.defaultHeaders },
90
+ defaultHeaders: { ...nodeUserAgent('cadenya-typescript/1.6.0 (api 1.0)'), ...options.defaultHeaders },
91
91
  fetch: options.fetch,
92
92
  logger: options.logger,
93
93
  logLevel: options.logLevel,
@@ -3,7 +3,7 @@
3
3
  import { HttpClient, RequestOptions, RequestSpec, APIPromise, pathSegment, snapshotParams } from '../core/http.js';
4
4
  import { Page } from '../core/pagination.js';
5
5
  import { Stream } from '../core/sse.js';
6
- import type { AgentVariationSpec_CompactionConfig, CompactObjectiveResponse, CreateObjectiveRequest_Secret, CreateOperationMetadata, GetObjectiveDiagnosticsResponse, ListObjectiveContextWindowsResponse, ListObjectiveEventsResponse, ListObjectiveFeedbackResponse, ListObjectiveToolCallsResponse, ListObjectiveToolsResponse, ListObjectivesResponse, MemoryReference, Objective, ObjectiveContextWindow, ObjectiveEpisodicConfigParam, ObjectiveEvent, ObjectiveFeedback, ObjectiveFeedbackData, ObjectiveServiceListObjectiveToolCallsExecutionStatus, ObjectiveServiceListObjectiveToolCallsStatus, ObjectiveServiceListObjectivesState, ObjectiveTool, ObjectiveToolCall, ObjectiveToolCallWithResult, SetToolCallContentRequest_ContentBlock, SubjectAssertion, TenantAssertion } from '../types.js';
6
+ import type { AgentVariationSpec_CompactionConfig, ContinueObjectiveResponse, CreateAndStreamObjectiveRequest_Metadata, CreateAndStreamObjectiveResponse, CreateObjectiveRequest_Secret, CreateOperationMetadata, GetObjectiveDiagnosticsResponse, ListObjectiveContextWindowsResponse, ListObjectiveEventsResponse, ListObjectiveFeedbackResponse, ListObjectiveQueuedActionsResponse, ListObjectiveToolCallsResponse, ListObjectiveToolsResponse, ListObjectivesResponse, MemoryReference, Objective, ObjectiveContextWindow, ObjectiveEpisodicConfigParam, ObjectiveEvent, ObjectiveFeedback, ObjectiveFeedbackData, ObjectiveQueuedAction, ObjectiveServiceListObjectiveQueuedActionsState, ObjectiveServiceListObjectiveToolCallsExecutionStatus, ObjectiveServiceListObjectiveToolCallsStatus, ObjectiveServiceListObjectivesState, ObjectiveTool, ObjectiveToolCall, ObjectiveToolCallWithResult, SetToolCallContentRequest_ContentBlock, SubjectAssertion, TenantAssertion } from '../types.js';
7
7
  import { wireObjectiveEpisodicConfig } from '../types.js';
8
8
 
9
9
  export interface ObjectiveListParams {
@@ -75,12 +75,6 @@ export interface ObjectiveListParams {
75
75
 
76
76
  export interface ObjectiveCreateParams {
77
77
  agentId: string;
78
- /**
79
- * Arbitrary data rendered into the selected variation's system_prompt_template
80
- * (liquid) to produce the objective's system prompt. If the agent has a
81
- * system_prompt_data_schema, this must satisfy it.
82
- */
83
- systemPromptData: Record<string, unknown>;
84
78
  /**
85
79
  * Defaults to the client-level `workspaceId` option or the CADENYA_WORKSPACE_ID environment variable.
86
80
  */
@@ -90,6 +84,12 @@ export interface ObjectiveCreateParams {
90
84
  */
91
85
  variationId?: string;
92
86
  metadata?: CreateOperationMetadata;
87
+ /**
88
+ * Arbitrary data rendered into the selected variation's system_prompt_template
89
+ * (liquid) to produce the objective's system prompt. If the agent has a
90
+ * system_prompt_data_schema, this must satisfy it.
91
+ */
92
+ systemPromptData?: Record<string, unknown>;
93
93
  /**
94
94
  * Optional explicit first user message for the LLM chat history. When not set,
95
95
  * the selected variation's first_user_message_template is rendered with
@@ -267,6 +267,36 @@ export interface ObjectiveCreateFeedbackParams {
267
267
  workspaceId?: string;
268
268
  }
269
269
 
270
+ export interface ObjectiveListQueuedActionsParams {
271
+ /**
272
+ * Defaults to the client-level `workspaceId` option or the CADENYA_WORKSPACE_ID environment variable.
273
+ */
274
+ workspaceId?: string;
275
+ /**
276
+ * Maximum number of results to return
277
+ */
278
+ limit?: number;
279
+ /**
280
+ * Pagination cursor from previous response
281
+ */
282
+ cursor?: string;
283
+ /**
284
+ * Only return actions in this state. When unset, actions in every state are returned.
285
+ */
286
+ state?: ObjectiveServiceListObjectiveQueuedActionsState;
287
+ }
288
+
289
+ export interface ObjectiveRemoveQueuedActionParams {
290
+ /**
291
+ * The ID of the queued action to remove.
292
+ */
293
+ queuedActionId: string;
294
+ /**
295
+ * Defaults to the client-level `workspaceId` option or the CADENYA_WORKSPACE_ID environment variable.
296
+ */
297
+ workspaceId?: string;
298
+ }
299
+
270
300
  export interface ObjectiveListToolCallsParams {
271
301
  /**
272
302
  * Defaults to the client-level `workspaceId` option or the CADENYA_WORKSPACE_ID environment variable.
@@ -379,7 +409,7 @@ export interface ObjectiveCompactParams {
379
409
 
380
410
  export interface ObjectiveContinueParams {
381
411
  /**
382
- * The message to continue an objective that has completed (or you are enqueing)
412
+ * The user message to send to the objective.
383
413
  */
384
414
  message: string;
385
415
  /**
@@ -387,11 +417,108 @@ export interface ObjectiveContinueParams {
387
417
  */
388
418
  workspaceId?: string;
389
419
  /**
390
- * When set to true, the message will be enqueued for when the agent loop is available to process it.
420
+ * When false, the objective must be waiting and the message is sent immediately.
421
+ * When true, a waiting objective still receives the message immediately; an
422
+ * objective whose agent loop is busy queues it instead, and the agent picks it
423
+ * up before its next assistant turn. Queued messages can be listed and removed
424
+ * until then.
391
425
  */
392
426
  enqueue?: boolean;
393
427
  }
394
428
 
429
+ export interface ObjectiveInterruptParams {
430
+ /**
431
+ * Defaults to the client-level `workspaceId` option or the CADENYA_WORKSPACE_ID environment variable.
432
+ */
433
+ workspaceId?: string;
434
+ }
435
+
436
+ export interface ObjectiveCreateAndStreamParams {
437
+ agentId: string;
438
+ /**
439
+ * Required here, though Create objective leaves it optional: the external
440
+ * ID inside it is the idempotency key that makes a retry of this request
441
+ * resume the objective instead of starting another.
442
+ */
443
+ metadata: CreateAndStreamObjectiveRequest_Metadata;
444
+ /**
445
+ * Defaults to the client-level `workspaceId` option or the CADENYA_WORKSPACE_ID environment variable.
446
+ */
447
+ workspaceId?: string;
448
+ /**
449
+ * Optional explicit variation selection. Overrides the agent's variation_selection_mode.
450
+ */
451
+ variationId?: string;
452
+ /**
453
+ * Arbitrary data rendered into the selected variation's system_prompt_template
454
+ * (liquid) to produce the objective's system prompt. If the agent has a
455
+ * system_prompt_data_schema, this must satisfy it.
456
+ */
457
+ systemPromptData?: Record<string, unknown>;
458
+ /**
459
+ * Optional explicit first user message for the LLM chat history. When not set,
460
+ * the selected variation's first_user_message_template is rendered with
461
+ * first_user_message_data instead. If neither this field nor a
462
+ * first_user_message_template is present, the request is rejected with InvalidArgument.
463
+ */
464
+ firstUserMessage?: string;
465
+ /**
466
+ * Secrets that can be used in the headers for tool calls using the secret interpolation format.
467
+ */
468
+ secrets?: Array<CreateObjectiveRequest_Secret>;
469
+ /**
470
+ * Memory layers/entries layered over the baseline cascade inherited
471
+ * from the selected variation — element-level rules over inherited
472
+ * styles, in CSS terms.
473
+ *
474
+ * Array order is resolution order: EARLIER elements are more specific
475
+ * and are consulted first. Entries pinned via memory_entry_id behave
476
+ * as single-entry layers at their position.
477
+ *
478
+ * System-managed layers (e.g., episodic) cannot be referenced here;
479
+ * they attach themselves automatically based on the episodic key.
480
+ *
481
+ * Size cap: the TOTAL effective cascade (this field + the variation's
482
+ * memory layer assignments) must not exceed 10 entries. A request
483
+ * that would produce a larger cascade is rejected with
484
+ * InvalidArgument.
485
+ */
486
+ memoryCascade?: Array<MemoryReference>;
487
+ /**
488
+ * Arbitrary data rendered into the selected variation's first_user_message_template
489
+ * (liquid) to produce the first user message. Separate from `system_prompt_data`,
490
+ * which renders the system prompt template.
491
+ */
492
+ firstUserMessageData?: Record<string, unknown>;
493
+ /**
494
+ * If the agent variation that is selected has episodic memory enabled, then this key is used to create/update a memory layer
495
+ * specific to the episodic memory. The layer may have a TTL configured by the variation.
496
+ */
497
+ episodicMemory?: ObjectiveEpisodicConfigParam;
498
+ /**
499
+ * Optional tenant assertion — the customer's org/company identifier for the
500
+ * end user this objective serves. Upserts the tenant record in the
501
+ * workspace and associates the objective with it.
502
+ */
503
+ tenant?: TenantAssertion;
504
+ /**
505
+ * Optional subject assertion — the person within the tenant this objective
506
+ * serves. Requires `tenant`; a subject asserted without a tenant is
507
+ * rejected with InvalidArgument.
508
+ */
509
+ subject?: SubjectAssertion;
510
+ /**
511
+ * Parameters forced onto this objective's tool calls. A pinned parameter
512
+ * is removed from the tool schema the LLM sees, and its value is always
513
+ * overwritten server-side with the pinned value — the model cannot choose
514
+ * a different value for it. By default a pinned key applies to every tool
515
+ * with a top-level parameter of the same name; a tool set's overlays
516
+ * (ToolSetSpec.overlays) can bind pinned keys to nested paths, differently
517
+ * named parameters, or a subset of tools.
518
+ */
519
+ pinnedParameters?: Record<string, string>;
520
+ }
521
+
395
522
  export class Objectives {
396
523
  constructor(private readonly _client: HttpClient) {}
397
524
 
@@ -419,7 +546,7 @@ export class Objectives {
419
546
  *
420
547
  * @example
421
548
  * ```ts
422
- * const objective = await client.objectives.create({ agentId: 'sample', systemPromptData: { } });
549
+ * const objective = await client.objectives.create({ agentId: 'sample' });
423
550
  * ```
424
551
  */
425
552
  create(params: ObjectiveCreateParams, options?: RequestOptions): APIPromise<Objective> {
@@ -554,6 +681,41 @@ export class Objectives {
554
681
  }, options);
555
682
  }
556
683
 
684
+ /**
685
+ * List objective queued actions
686
+ *
687
+ * @example
688
+ * ```ts
689
+ * const page = await client.objectives.listQueuedActions('objective_123');
690
+ * for await (const item of page) {
691
+ * // auto-fetches every page
692
+ * }
693
+ * ```
694
+ */
695
+ async listQueuedActions(objectiveId: string, params?: ObjectiveListQueuedActionsParams, options?: RequestOptions): Promise<Page<ObjectiveQueuedAction>> {
696
+ const workspaceId = String(params?.workspaceId ?? this._client.defaults['workspaceId'] ?? '').trim() || undefined;
697
+ if (workspaceId === undefined) throw new Error("Missing 'workspaceId': pass it in params, set it on the client, or set the CADENYA_WORKSPACE_ID environment variable.");
698
+ const _base = snapshotParams(params);
699
+ const response = await this._client.request<ListObjectiveQueuedActionsResponse>({ method: 'GET', path: `/v1/workspaces/${pathSegment('workspaceId', workspaceId)}/objectives/${pathSegment('objectiveId', objectiveId)}/queued_actions`, query: { limit: params?.limit, cursor: params?.cursor, state: params?.state } }, options);
700
+ return new Page(response.items ?? [], response.pagination?.nextCursor, (cursor) => this.listQueuedActions(objectiveId, { ..._base, cursor: cursor }, options));
701
+ }
702
+
703
+ /**
704
+ * Remove a queued action
705
+ *
706
+ * @example
707
+ * ```ts
708
+ * const objectiveQueuedAction = await client.objectives.removeQueuedAction('objective_123', { queuedActionId: 'queued_action_123' });
709
+ * ```
710
+ */
711
+ removeQueuedAction(objectiveId: string, params: ObjectiveRemoveQueuedActionParams, options?: RequestOptions): APIPromise<ObjectiveQueuedAction> {
712
+ return this._client.requestAPI<ObjectiveQueuedAction>(() => {
713
+ const workspaceId = String(params.workspaceId ?? this._client.defaults['workspaceId'] ?? '').trim() || undefined;
714
+ if (workspaceId === undefined) throw new Error("Missing 'workspaceId': pass it in params, set it on the client, or set the CADENYA_WORKSPACE_ID environment variable.");
715
+ return { method: 'POST', path: `/v1/workspaces/${pathSegment('workspaceId', workspaceId)}/objectives/${pathSegment('objectiveId', objectiveId)}/queued_actions/${pathSegment('queuedActionId', params.queuedActionId)}:remove` };
716
+ }, options);
717
+ }
718
+
557
719
  /**
558
720
  * List objective tool calls
559
721
  *
@@ -677,11 +839,11 @@ export class Objectives {
677
839
  *
678
840
  * @example
679
841
  * ```ts
680
- * const compactObjectiveResponse = await client.objectives.compact('objective_123');
842
+ * const objectiveQueuedAction = await client.objectives.compact('objective_123');
681
843
  * ```
682
844
  */
683
- compact(objectiveId: string, params?: ObjectiveCompactParams, options?: RequestOptions): APIPromise<CompactObjectiveResponse> {
684
- return this._client.requestAPI<CompactObjectiveResponse>(() => {
845
+ compact(objectiveId: string, params?: ObjectiveCompactParams, options?: RequestOptions): APIPromise<ObjectiveQueuedAction> {
846
+ return this._client.requestAPI<ObjectiveQueuedAction>(() => {
685
847
  const workspaceId = String(params?.workspaceId ?? this._client.defaults['workspaceId'] ?? '').trim() || undefined;
686
848
  if (workspaceId === undefined) throw new Error("Missing 'workspaceId': pass it in params, set it on the client, or set the CADENYA_WORKSPACE_ID environment variable.");
687
849
  return { method: 'POST', path: `/v1/workspaces/${pathSegment('workspaceId', workspaceId)}/objectives/${pathSegment('objectiveId', objectiveId)}:compact`, body: { compactionConfig: params?.compactionConfig } };
@@ -693,14 +855,49 @@ export class Objectives {
693
855
  *
694
856
  * @example
695
857
  * ```ts
696
- * const objectiveEvent = await client.objectives.continue('objective_123', { message: 'sample' });
858
+ * const continueObjectiveResponse = await client.objectives.continue('objective_123', { message: 'sample' });
697
859
  * ```
698
860
  */
699
- continue(objectiveId: string, params: ObjectiveContinueParams, options?: RequestOptions): APIPromise<ObjectiveEvent> {
700
- return this._client.requestAPI<ObjectiveEvent>(() => {
861
+ continue(objectiveId: string, params: ObjectiveContinueParams, options?: RequestOptions): APIPromise<ContinueObjectiveResponse> {
862
+ return this._client.requestAPI<ContinueObjectiveResponse>(() => {
701
863
  const workspaceId = String(params.workspaceId ?? this._client.defaults['workspaceId'] ?? '').trim() || undefined;
702
864
  if (workspaceId === undefined) throw new Error("Missing 'workspaceId': pass it in params, set it on the client, or set the CADENYA_WORKSPACE_ID environment variable.");
703
865
  return { method: 'POST', path: `/v1/workspaces/${pathSegment('workspaceId', workspaceId)}/objectives/${pathSegment('objectiveId', objectiveId)}:continue`, body: { message: params.message, enqueue: params.enqueue } };
704
866
  }, options);
705
867
  }
868
+
869
+ /**
870
+ * Interrupt an objective
871
+ *
872
+ * @example
873
+ * ```ts
874
+ * const objectiveEvent = await client.objectives.interrupt('objective_123');
875
+ * ```
876
+ */
877
+ interrupt(objectiveId: string, params?: ObjectiveInterruptParams, options?: RequestOptions): APIPromise<ObjectiveEvent> {
878
+ return this._client.requestAPI<ObjectiveEvent>(() => {
879
+ const workspaceId = String(params?.workspaceId ?? this._client.defaults['workspaceId'] ?? '').trim() || undefined;
880
+ if (workspaceId === undefined) throw new Error("Missing 'workspaceId': pass it in params, set it on the client, or set the CADENYA_WORKSPACE_ID environment variable.");
881
+ return { method: 'POST', path: `/v1/workspaces/${pathSegment('workspaceId', workspaceId)}/objectives/${pathSegment('objectiveId', objectiveId)}:interrupt` };
882
+ }, options);
883
+ }
884
+
885
+ /**
886
+ * Create an objective and stream its events
887
+ *
888
+ * @example
889
+ * ```ts
890
+ * const stream = await client.objectives.createAndStream({ agentId: 'sample', metadata: { externalId: 'sample' } });
891
+ * for await (const event of stream) {
892
+ * // typed event payloads; housekeeping frames are skipped
893
+ * }
894
+ * ```
895
+ */
896
+ async createAndStream(params: ObjectiveCreateAndStreamParams, options?: RequestOptions): Promise<Stream<CreateAndStreamObjectiveResponse>> {
897
+ const workspaceId = String(params.workspaceId ?? this._client.defaults['workspaceId'] ?? '').trim() || undefined;
898
+ if (workspaceId === undefined) throw new Error("Missing 'workspaceId': pass it in params, set it on the client, or set the CADENYA_WORKSPACE_ID environment variable.");
899
+ const _spec: RequestSpec = { method: 'POST', path: `/v1/workspaces/${pathSegment('workspaceId', workspaceId)}/objectives:stream`, body: { agentId: params.agentId, variationId: params.variationId, metadata: params.metadata, systemPromptData: params.systemPromptData, firstUserMessage: params.firstUserMessage, secrets: params.secrets, memoryCascade: params.memoryCascade, firstUserMessageData: params.firstUserMessageData, episodicMemory: wireObjectiveEpisodicConfig(params.episodicMemory), tenant: params.tenant, subject: params.subject, pinnedParameters: params.pinnedParameters }, stream: true };
900
+ const response = await this._client.rawRequest(_spec, options);
901
+ return new Stream<CreateAndStreamObjectiveResponse>(response, options?.signal, options?.lastEventId, ['ping', 'open'], options?.reconnect === false ? undefined : (lastEventId, signal) => this._client.rawRequest(_spec, { ...options, lastEventId, signal }));
902
+ }
706
903
  }
@@ -1,7 +1,7 @@
1
1
  // Generated by redwood. Do not edit by hand.
2
2
 
3
3
  import { HttpClient, RequestOptions, APIPromise } from '../core/http.js';
4
- import type { Profile } from '../types.js';
4
+ import type { WhoamiResponse } from '../types.js';
5
5
 
6
6
  export class Profiles {
7
7
  constructor(private readonly _client: HttpClient) {}
@@ -11,11 +11,11 @@ export class Profiles {
11
11
  *
12
12
  * @example
13
13
  * ```ts
14
- * const profile = await client.profiles.whoami();
14
+ * const whoamiResponse = await client.profiles.whoami();
15
15
  * ```
16
16
  */
17
- whoami(options?: RequestOptions): APIPromise<Profile> {
18
- return this._client.requestAPI<Profile>(() => {
17
+ whoami(options?: RequestOptions): APIPromise<WhoamiResponse> {
18
+ return this._client.requestAPI<WhoamiResponse>(() => {
19
19
  return { method: 'GET', path: `/v1/whoami` };
20
20
  }, options);
21
21
  }