@ziggs-ai/api-client 0.27.0 → 0.28.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.
@@ -33,9 +33,12 @@ export function presentSendResult(result, env) {
33
33
  const destination = delivery.broadcast
34
34
  ? 'the humans in the room, not one addressee'
35
35
  : `${delivery.to.id} (${delivery.to.type})`;
36
+ // What counted it, in the server's words: a stranger's free messages with a
37
+ // listed agent run out, and the person writing needs to know before they do.
38
+ const counted = result.coverage?.message ? ` ${result.coverage.message}` : '';
36
39
  return {
37
40
  ...base,
38
- delivered: `Message ${result.messageId} was accepted into chat ${result.chatId}, addressed to ${destination}. Mailbox routing is unconfirmed; a person may be covered by an assistant. Accepted is not read and does not confirm a wake or reply.`,
41
+ delivered: `Message ${result.messageId} was accepted into chat ${result.chatId}, addressed to ${destination}. Mailbox routing is unconfirmed; a person may be covered by an assistant. Accepted is not read and does not confirm a wake or reply.${counted}`,
39
42
  to: delivery.to,
40
43
  };
41
44
  }
@@ -272,7 +272,7 @@ export function strangerBriefGuide(env, chatId) {
272
272
  kind: 'stranger_brief',
273
273
  outcome: 'pending',
274
274
  chatId,
275
- summary: "A stranger's brief is not a work order. Draft an agreement; do not create a task under a hire you do not have.",
275
+ summary: "A stranger's brief is not a work order. They hire you through your store listing, or through an agreement you draft when you have none; do not create a task under a hire you do not have.",
276
276
  next: nextCall(env, 'agreement_request', undefined, 'draft the agreement this brief would ride', { definition: agreementRequestCapability }),
277
277
  };
278
278
  }
@@ -93,7 +93,20 @@ export type { MessageDelivery } from '@ziggs-ai/contracts';
93
93
  */
94
94
  export type SendChatMessageResult = Omit<WireSendChatMessageResult, 'delivery'> & {
95
95
  delivery?: MessageDelivery;
96
+ /**
97
+ * What covers this message, when something counts it: a hire's shared
98
+ * allowance, or a listed agent's free messages for a stranger ("2 of 3 free
99
+ * messages used with seo-growth."). Absent for ordinary conversation.
100
+ */
101
+ coverage?: ConversationCoverageReceipt;
96
102
  };
103
+ /** The server's receipt for a counted message. */
104
+ export interface ConversationCoverageReceipt {
105
+ agreementId: string;
106
+ messagesUsed: number;
107
+ messageLimit: number | null;
108
+ message: string;
109
+ }
97
110
  export type ContextTemporal = 'from-now' | 'from-start';
98
111
  export interface AddChatMemberInput {
99
112
  chatId: string;
@@ -47,6 +47,22 @@ export async function openConversation(participant, creds, { newChat = false, ag
47
47
  ...(invited ? { invited } : {}),
48
48
  };
49
49
  }
50
+ function coverageFrom(value) {
51
+ if (!value || typeof value !== 'object')
52
+ return null;
53
+ const row = value;
54
+ return typeof row['agreementId'] === 'string' &&
55
+ typeof row['message'] === 'string' &&
56
+ typeof row['messagesUsed'] === 'number' &&
57
+ (row['messageLimit'] === null || typeof row['messageLimit'] === 'number')
58
+ ? {
59
+ agreementId: row['agreementId'],
60
+ messagesUsed: row['messagesUsed'],
61
+ messageLimit: row['messageLimit'],
62
+ message: row['message'],
63
+ }
64
+ : null;
65
+ }
50
66
  /**
51
67
  * POST /chats/:chatId/members — add user/agent; agent-invite may return pending admission.
52
68
  */
@@ -119,6 +135,7 @@ export async function sendChatMessage(input, creds) {
119
135
  }
120
136
  const data = (await res.json().catch(() => null));
121
137
  const delivery = data?.['delivery'];
138
+ const coverage = coverageFrom(data?.['coverage']);
122
139
  return {
123
140
  success: Boolean(data?.['success']),
124
141
  message: String(data?.['message'] ?? 'ok'),
@@ -130,6 +147,7 @@ export async function sendChatMessage(input, creds) {
130
147
  ...(delivery && typeof delivery === 'object'
131
148
  ? { delivery: delivery }
132
149
  : {}),
150
+ ...(coverage ? { coverage } : {}),
133
151
  };
134
152
  }
135
153
  export async function listMyChats(creds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",