@ziggs-ai/api-client 0.40.2 → 0.40.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.40.3
6
+
7
+ - `InboxClient` takes `sharedHost` in its session options: it sends `X-Ziggs-Inbox-Hosts: shared`, so several processes can host one agent at once, and `getInbox({ capacity })` says how many more threads this host can start. `InboxEnvelope.host` reports whether this host leads.
8
+
5
9
  ## 0.40.2
6
10
 
7
11
  - A task on an agreement priced at completion with no stated charge is free; the outcome's metering line says so. `charge` docs say the same.
@@ -4,6 +4,10 @@ import type { InboxAckResult, InboxEnvelope, InboxPeek, InboxReadOptions, InboxC
4
4
  * since its last ack — never content. Flow: inbox → read → act → ack
5
5
  *. Wraps `GET /inbox` and `POST /inbox/ack`.
6
6
  */
7
+ /** Several processes host this agent at once (value `shared`). */
8
+ export declare const INBOX_HOSTS_HEADER = "X-Ziggs-Inbox-Hosts";
9
+ /** With shared hosts: how many more threads this host can start now. */
10
+ export declare const INBOX_CAPACITY_HEADER = "X-Ziggs-Inbox-Capacity";
7
11
  export declare class InboxClient {
8
12
  private readonly operatorKey;
9
13
  private readonly agentId?;
@@ -23,6 +27,13 @@ export declare class InboxClient {
23
27
  workspaceIds?: string;
24
28
  app?: string;
25
29
  sessionName?: string;
30
+ /**
31
+ * This process is one of several hosting the agent at once. The server
32
+ * then treats a second host as a member rather than a conflict: each
33
+ * host takes its own threads, and the one holding the inbox lease
34
+ * (`envelope.host.leader`) gets the standing lists.
35
+ */
36
+ sharedHost?: boolean;
26
37
  });
27
38
  private headers;
28
39
  private inboxUrl;
@@ -35,6 +46,8 @@ export declare class InboxClient {
35
46
  }): Promise<InboxEnvelope>;
36
47
  getInbox(opts?: InboxReadOptions & {
37
48
  signal?: AbortSignal;
49
+ /** Shared hosts: how many more threads this host can start now. */
50
+ capacity?: number;
38
51
  }): Promise<InboxEnvelope>;
39
52
  /**
40
53
  * Wait for assigned mail without taking the host lease.
@@ -7,6 +7,10 @@ import { INBOX_HOST_CLAIMANT_HEADER, hostIdentity, } from '../instanceIdentity.j
7
7
  * since its last ack — never content. Flow: inbox → read → act → ack
8
8
  *. Wraps `GET /inbox` and `POST /inbox/ack`.
9
9
  */
10
+ /** Several processes host this agent at once (value `shared`). */
11
+ export const INBOX_HOSTS_HEADER = 'X-Ziggs-Inbox-Hosts';
12
+ /** With shared hosts: how many more threads this host can start now. */
13
+ export const INBOX_CAPACITY_HEADER = 'X-Ziggs-Inbox-Capacity';
10
14
  export class InboxClient {
11
15
  operatorKey;
12
16
  agentId;
@@ -48,6 +52,8 @@ export class InboxClient {
48
52
  headers['X-Ziggs-App'] = this.session.app;
49
53
  if (this.session?.sessionName)
50
54
  headers['X-Ziggs-Session-Name'] = this.session.sessionName;
55
+ if (this.session?.sharedHost)
56
+ headers[INBOX_HOSTS_HEADER] = 'shared';
51
57
  return headers;
52
58
  }
53
59
  inboxUrl(path, opts) {
@@ -80,8 +86,12 @@ export class InboxClient {
80
86
  return JSON.parse(body);
81
87
  }
82
88
  async getInbox(opts = {}) {
89
+ const headers = this.headers();
90
+ if (this.session?.sharedHost && opts.capacity !== undefined) {
91
+ headers[INBOX_CAPACITY_HEADER] = String(Math.max(0, Math.floor(opts.capacity)));
92
+ }
83
93
  const res = await fetch(this.inboxUrl('/inbox', opts), {
84
- headers: this.headers(),
94
+ headers,
85
95
  ...(opts.signal ? { signal: opts.signal } : {}),
86
96
  });
87
97
  const body = await res.text().catch(() => '');
package/dist/types.d.ts CHANGED
@@ -413,6 +413,15 @@ export type { InboxPlanAckRef } from '@ziggs-ai/contracts';
413
413
  * read them as empty.
414
414
  */
415
415
  export interface InboxEnvelope extends InboxRequestChannel, Partial<InboxPlanAckChannel> {
416
+ /**
417
+ * Present when this read was made as one of several hosts of the agent
418
+ * (`sharedHost`). `leader` is the host holding the inbox lease: it gets the
419
+ * standing lists and runs the agent's polls and timers.
420
+ */
421
+ host?: {
422
+ shared: true;
423
+ leader: boolean;
424
+ };
416
425
  asOf: string;
417
426
  /**
418
427
  * The mailboxes this reader's view merges — its owner's, plus whatever
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.40.2",
3
+ "version": "0.40.3",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {