@ziggs-ai/api-client 0.37.15 → 0.37.16

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.37.16
6
+
7
+ - `messages` can ask for the newest page. A forward delta still needs a timestamp.
8
+
5
9
  ## 0.37.15
6
10
 
7
11
  - A caller can leave one pending proposal unshouted. Later inbox reads name it as parked.
@@ -4,6 +4,14 @@ export interface ListMessagesOptions {
4
4
  /** Page size, default 100, hard cap 1000. */
5
5
  limit?: number;
6
6
  }
7
+ /**
8
+ * The chat message URL.
9
+ *
10
+ * `after` is a forward delta: the server returns that page only when both
11
+ * `after` and `direction=forward` are set. Omitting both is the newest page,
12
+ * which is how a person asks what just happened without already knowing a time.
13
+ */
14
+ export declare function messagesListUrl(base: string, chatId: string, opts?: ListMessagesOptions): string;
7
15
  export interface ListMessagesResult {
8
16
  messages: unknown[];
9
17
  latestSequence: string | null;
@@ -21,5 +29,12 @@ export declare class MessagesClient {
21
29
  private readonly agentId;
22
30
  constructor(operatorKey: string, agentId: string);
23
31
  list(chatId: string, opts?: ListMessagesOptions): Promise<ListMessagesResult>;
32
+ /**
33
+ * Newest page. No `after`, so the server walks backward from now.
34
+ * `list` is the forward delta and cannot answer "what just happened".
35
+ */
36
+ listLatest(chatId: string, opts?: {
37
+ limit?: number;
38
+ }): Promise<ListMessagesResult>;
24
39
  private _headers;
25
40
  }
@@ -2,6 +2,23 @@ import { decodeOperatorKeyClaims } from '../shared/operatorKey.js';
2
2
  import { buildOperatorHeaders } from './operatorHeaders.js';
3
3
  import { getBackendUrl } from '../utils/urlUtils.js';
4
4
  import { throwApiError } from '../shared/apiError.js';
5
+ /**
6
+ * The chat message URL.
7
+ *
8
+ * `after` is a forward delta: the server returns that page only when both
9
+ * `after` and `direction=forward` are set. Omitting both is the newest page,
10
+ * which is how a person asks what just happened without already knowing a time.
11
+ */
12
+ export function messagesListUrl(base, chatId, opts = {}) {
13
+ const url = new URL(`${base}/chats/${encodeURIComponent(chatId)}/messages`);
14
+ if (opts.after) {
15
+ url.searchParams.set('direction', 'forward');
16
+ url.searchParams.set('after', opts.after);
17
+ }
18
+ if (opts.limit != null)
19
+ url.searchParams.set('limit', String(opts.limit));
20
+ return url.toString();
21
+ }
5
22
  /**
6
23
  * Read-side client for forward-delta message reads.
7
24
  *
@@ -24,17 +41,16 @@ export class MessagesClient {
24
41
  async list(chatId, opts = {}) {
25
42
  if (!chatId)
26
43
  return { messages: [], latestSequence: null };
27
- const url = new URL(`${getBackendUrl()}/chats/${encodeURIComponent(chatId)}/messages`);
28
44
  // Forward-delta read mode. Backend routes to `listMessagesForward`
29
45
  // only when BOTH `after` and `direction=forward` are present; without
30
46
  // `after` the same handler falls into backward pagination and returns
31
47
  // a different envelope. Default `after` to the unix epoch so the
32
48
  // forward branch always wins when callers want "from the beginning".
33
- url.searchParams.set('direction', 'forward');
34
- url.searchParams.set('after', opts.after || '1970-01-01T00:00:00.000Z');
35
- if (opts.limit != null)
36
- url.searchParams.set('limit', String(opts.limit));
37
- const res = await fetch(url.toString(), { headers: this._headers() });
49
+ const url = messagesListUrl(getBackendUrl(), chatId, {
50
+ after: opts.after || '1970-01-01T00:00:00.000Z',
51
+ limit: opts.limit,
52
+ });
53
+ const res = await fetch(url, { headers: this._headers() });
38
54
  if (!res.ok) {
39
55
  const body = await res.text().catch(() => '');
40
56
  // Callers branch on ApiError.status (404 = chat deleted/not visible).
@@ -42,6 +58,20 @@ export class MessagesClient {
42
58
  }
43
59
  return (await res.json());
44
60
  }
61
+ /**
62
+ * Newest page. No `after`, so the server walks backward from now.
63
+ * `list` is the forward delta and cannot answer "what just happened".
64
+ */
65
+ async listLatest(chatId, opts = {}) {
66
+ if (!chatId)
67
+ return { messages: [], latestSequence: null };
68
+ const res = await fetch(messagesListUrl(getBackendUrl(), chatId, { limit: opts.limit }), { headers: this._headers() });
69
+ if (!res.ok) {
70
+ const body = await res.text().catch(() => '');
71
+ throwApiError(res, body, `MessagesClient.listLatest failed: ${res.status}`);
72
+ }
73
+ return (await res.json());
74
+ }
45
75
  _headers() {
46
76
  return {
47
77
  'content-type': 'application/json',
@@ -3,7 +3,7 @@ export * from './AgreementClient.js';
3
3
  export * from './MarketplaceClient.js';
4
4
  export * from './agreementFlows.js';
5
5
  export * from './ChatClient.js';
6
- export { MessagesClient } from './MessagesClient.js';
6
+ export { MessagesClient, messagesListUrl } from './MessagesClient.js';
7
7
  export type { ListMessagesOptions, ListMessagesResult } from './MessagesClient.js';
8
8
  export { ArtifactsClient, artifactScopeForSession, AGREEMENT_LANE_PREFIX, ARTIFACT_INLINE_TEXT_MAX_CHARS, ARTIFACT_INLINE_TEXT_OVER_LIMIT_HINT, } from './ArtifactsClient.js';
9
9
  export type { ArtifactVisibility, ListArtifactsOptions, ListArtifactsQuery, ListArtifactsResult, WriteArtifactInput, } from './ArtifactsClient.js';
@@ -3,7 +3,7 @@ export * from './AgreementClient.js';
3
3
  export * from './MarketplaceClient.js';
4
4
  export * from './agreementFlows.js';
5
5
  export * from './ChatClient.js';
6
- export { MessagesClient } from './MessagesClient.js';
6
+ export { MessagesClient, messagesListUrl } from './MessagesClient.js';
7
7
  export { ArtifactsClient,
8
8
  // agreement lanes are not chats — callers scope artifact writes with this.
9
9
  artifactScopeForSession, AGREEMENT_LANE_PREFIX, ARTIFACT_INLINE_TEXT_MAX_CHARS, ARTIFACT_INLINE_TEXT_OVER_LIMIT_HINT, } from './ArtifactsClient.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.37.15",
3
+ "version": "0.37.16",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {