vessels-sdk 0.4.0 → 0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # vessels-sdk
2
2
 
3
- Node.js SDK for [Vessels](https://vessels-two.vercel.app) — let your agent reach you.
3
+ Node.js SDK for [Vessels](https://vessels.app) — let your agent reach you.
4
4
 
5
5
  Vessels is the communication layer between AI agents and their human operators. Your agent pushes structured messages to a vessel; the human responds via the web or mobile app; your agent receives the answer via polling or webhooks.
6
6
 
@@ -38,7 +38,7 @@ const { messageId, vesselId } = await vessels.push({
38
38
  });
39
39
  ```
40
40
 
41
- Get your API key from Settings → API Keys in the [Vessels app](https://vessels-two.vercel.app), or via the CLI:
41
+ Get your API key from Settings → API Keys in the [Vessels app](https://vessels.app), or via the CLI:
42
42
 
43
43
  ```bash
44
44
  npm install -g vessels
@@ -55,7 +55,7 @@ vessels keys create
55
55
  | Option | Type | Default | Description |
56
56
  |--------|------|---------|-------------|
57
57
  | `apiKey` | `string` | required | Your `vsl_` prefixed API key |
58
- | `baseUrl` | `string` | `https://vessels-two.vercel.app` | Override for local dev or self-hosted |
58
+ | `baseUrl` | `string` | `https://vessels.app` | Override for local dev or self-hosted |
59
59
 
60
60
  ---
61
61
 
@@ -469,7 +469,7 @@ import type {
469
469
 
470
470
  ## Links
471
471
 
472
- - Dashboard: [https://vessels-two.vercel.app](https://vessels-two.vercel.app)
473
- - Full integration reference: [https://vessels-two.vercel.app/docs](https://vessels-two.vercel.app/docs)
472
+ - Dashboard: [https://vessels.app](https://vessels.app)
473
+ - Full integration reference: [https://vessels.app/docs](https://vessels.app/docs)
474
474
  - CLI: `npm install -g vessels`
475
475
  - npm: [https://www.npmjs.com/package/vessels-sdk](https://www.npmjs.com/package/vessels-sdk)
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ var Vessels = class {
36
36
  _debug;
37
37
  constructor(config) {
38
38
  this.apiKey = config.apiKey;
39
- this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://vessels-two.vercel.app";
39
+ this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://vessels.app";
40
40
  this._debug = config.debug ?? false;
41
41
  }
42
42
  async _fetch(url, init) {
@@ -178,7 +178,8 @@ var Vessels = class {
178
178
  type: "message.user",
179
179
  timestamp: e.timestamp,
180
180
  vessel,
181
- message: { id: e.message?.id, content: e.message?.content ?? null }
181
+ message: { id: e.message?.id, content: e.message?.content ?? null },
182
+ context: []
182
183
  };
183
184
  });
184
185
  return { ok: true, events, hasMore: data.has_more ?? false };
@@ -209,6 +210,55 @@ var Vessels = class {
209
210
  return false;
210
211
  }
211
212
  }
213
+ // Verify + parse in one call. Returns a typed event or null (invalid signature or unknown type).
214
+ // body: raw request body string (before JSON.parse)
215
+ // signature: X-Vessels-Signature header value
216
+ // webhookSecret: the secret shown when you created the webhook endpoint in Settings
217
+ async parseWebhookEvent(body, signature, webhookSecret) {
218
+ const valid = await this.verifyWebhook(body, signature, webhookSecret);
219
+ if (!valid) return null;
220
+ try {
221
+ const raw = JSON.parse(body);
222
+ const v = raw.data?.vessel ?? {};
223
+ const vessel = {
224
+ id: v.id,
225
+ externalId: v.external_id ?? null,
226
+ title: v.title ?? null,
227
+ metadata: v.metadata ?? {},
228
+ labels: v.labels ?? []
229
+ };
230
+ if (raw.event === "interaction.response") {
231
+ return {
232
+ id: raw.data.response_id,
233
+ type: "interaction.response",
234
+ timestamp: raw.timestamp,
235
+ vessel,
236
+ messageId: raw.data.message_id,
237
+ interactionType: raw.data.interaction_type,
238
+ response: raw.data.response,
239
+ interactionMetadata: raw.data.metadata ?? null,
240
+ user: raw.data.user ?? null
241
+ };
242
+ }
243
+ if (raw.event === "message.user") {
244
+ return {
245
+ id: raw.data.message_id,
246
+ type: "message.user",
247
+ timestamp: raw.timestamp,
248
+ vessel,
249
+ message: { id: raw.data.message_id, content: raw.data.content ?? null },
250
+ context: (raw.data.context ?? []).map((m) => ({
251
+ source: m.source,
252
+ content: m.content ?? null,
253
+ createdAt: m.created_at
254
+ }))
255
+ };
256
+ }
257
+ return null;
258
+ } catch {
259
+ return null;
260
+ }
261
+ }
212
262
  };
213
263
 
214
264
  exports.AgentActivityTypes = AgentActivityTypes;
package/dist/index.d.cts CHANGED
@@ -74,6 +74,11 @@ interface UserMessageEvent {
74
74
  id: string;
75
75
  content: string | null;
76
76
  };
77
+ context: Array<{
78
+ source: string;
79
+ content: string | null;
80
+ createdAt: string;
81
+ }>;
77
82
  }
78
83
  type PollEvent = InteractionResponseEvent | UserMessageEvent;
79
84
  interface PollResponse {
@@ -138,6 +143,7 @@ declare class Vessels {
138
143
  }): _vessels_types.ConfirmPreviewInteraction;
139
144
  poll(options?: PollOptions): Promise<PollResponse>;
140
145
  verifyWebhook(body: string, signature: string, webhookSecret: string): Promise<boolean>;
146
+ parseWebhookEvent(body: string, signature: string, webhookSecret: string): Promise<InteractionResponseEvent | UserMessageEvent | null>;
141
147
  }
142
148
 
143
149
  export { AgentActivityTypes, type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushManyResult, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
package/dist/index.d.ts CHANGED
@@ -74,6 +74,11 @@ interface UserMessageEvent {
74
74
  id: string;
75
75
  content: string | null;
76
76
  };
77
+ context: Array<{
78
+ source: string;
79
+ content: string | null;
80
+ createdAt: string;
81
+ }>;
77
82
  }
78
83
  type PollEvent = InteractionResponseEvent | UserMessageEvent;
79
84
  interface PollResponse {
@@ -138,6 +143,7 @@ declare class Vessels {
138
143
  }): _vessels_types.ConfirmPreviewInteraction;
139
144
  poll(options?: PollOptions): Promise<PollResponse>;
140
145
  verifyWebhook(body: string, signature: string, webhookSecret: string): Promise<boolean>;
146
+ parseWebhookEvent(body: string, signature: string, webhookSecret: string): Promise<InteractionResponseEvent | UserMessageEvent | null>;
141
147
  }
142
148
 
143
149
  export { AgentActivityTypes, type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushManyResult, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var Vessels = class {
34
34
  _debug;
35
35
  constructor(config) {
36
36
  this.apiKey = config.apiKey;
37
- this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://vessels-two.vercel.app";
37
+ this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://vessels.app";
38
38
  this._debug = config.debug ?? false;
39
39
  }
40
40
  async _fetch(url, init) {
@@ -176,7 +176,8 @@ var Vessels = class {
176
176
  type: "message.user",
177
177
  timestamp: e.timestamp,
178
178
  vessel,
179
- message: { id: e.message?.id, content: e.message?.content ?? null }
179
+ message: { id: e.message?.id, content: e.message?.content ?? null },
180
+ context: []
180
181
  };
181
182
  });
182
183
  return { ok: true, events, hasMore: data.has_more ?? false };
@@ -207,6 +208,55 @@ var Vessels = class {
207
208
  return false;
208
209
  }
209
210
  }
211
+ // Verify + parse in one call. Returns a typed event or null (invalid signature or unknown type).
212
+ // body: raw request body string (before JSON.parse)
213
+ // signature: X-Vessels-Signature header value
214
+ // webhookSecret: the secret shown when you created the webhook endpoint in Settings
215
+ async parseWebhookEvent(body, signature, webhookSecret) {
216
+ const valid = await this.verifyWebhook(body, signature, webhookSecret);
217
+ if (!valid) return null;
218
+ try {
219
+ const raw = JSON.parse(body);
220
+ const v = raw.data?.vessel ?? {};
221
+ const vessel = {
222
+ id: v.id,
223
+ externalId: v.external_id ?? null,
224
+ title: v.title ?? null,
225
+ metadata: v.metadata ?? {},
226
+ labels: v.labels ?? []
227
+ };
228
+ if (raw.event === "interaction.response") {
229
+ return {
230
+ id: raw.data.response_id,
231
+ type: "interaction.response",
232
+ timestamp: raw.timestamp,
233
+ vessel,
234
+ messageId: raw.data.message_id,
235
+ interactionType: raw.data.interaction_type,
236
+ response: raw.data.response,
237
+ interactionMetadata: raw.data.metadata ?? null,
238
+ user: raw.data.user ?? null
239
+ };
240
+ }
241
+ if (raw.event === "message.user") {
242
+ return {
243
+ id: raw.data.message_id,
244
+ type: "message.user",
245
+ timestamp: raw.timestamp,
246
+ vessel,
247
+ message: { id: raw.data.message_id, content: raw.data.content ?? null },
248
+ context: (raw.data.context ?? []).map((m) => ({
249
+ source: m.source,
250
+ content: m.content ?? null,
251
+ createdAt: m.created_at
252
+ }))
253
+ };
254
+ }
255
+ return null;
256
+ } catch {
257
+ return null;
258
+ }
259
+ }
210
260
  };
211
261
 
212
262
  export { AgentActivityTypes, Vessels, VesselsAuthError, VesselsRateLimitError, VesselsValidationError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vessels-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Let your agent reach you. Official Vessels SDK.",
5
5
  "type": "module",
6
6
  "exports": {