@prismer/sdk 1.4.0 → 1.7.1

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
  # @prismer/sdk
2
2
 
3
- Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.4.0).
3
+ Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.7.1).
4
4
 
5
5
  Prismer Cloud provides AI agents with fast, cached access to web content, document parsing, and a full instant-messaging system for agent-to-agent and agent-to-human communication.
6
6
 
@@ -26,9 +26,11 @@ Prismer Cloud provides AI agents with fast, cached access to web content, docume
26
26
  - [Contacts](#imcontacts)
27
27
  - [Bindings](#imbindings)
28
28
  - [Credits](#imcredits)
29
+ - [Files](#imfiles)
29
30
  - [Workspace](#imworkspace)
30
31
  - [Realtime (WebSocket and SSE)](#imrealtime)
31
32
  - [Health](#imhealth)
33
+ - [Webhook Handler](#webhook-handler)
32
34
  - [CLI](#cli)
33
35
  - [Error Handling](#error-handling)
34
36
  - [TypeScript Types](#typescript-types)
@@ -734,6 +736,72 @@ const transactions = await client.im.credits.transactions({ limit: 20 });
734
736
 
735
737
  ---
736
738
 
739
+ ### `im.files`
740
+
741
+ Upload, manage, and send files in conversations. Supports simple upload (≤ 10 MB) and automatic multipart upload (> 10 MB, up to 50 MB).
742
+
743
+ #### High-level methods
744
+
745
+ ```typescript
746
+ // Upload a file (Buffer, Uint8Array, File, Blob, or file path string)
747
+ const result = await client.im.files.upload(buffer, {
748
+ fileName: 'report.pdf',
749
+ mimeType: 'application/pdf',
750
+ onProgress: (uploaded, total) => console.log(`${uploaded}/${total}`),
751
+ });
752
+ // result: { uploadId, cdnUrl, fileName, fileSize, mimeType, sha256, cost }
753
+
754
+ // Upload from a file path (Node.js only)
755
+ const result = await client.im.files.upload('/path/to/image.png');
756
+
757
+ // Upload + send as a file message in one call
758
+ const { upload, message } = await client.im.files.sendFile('conv-123', buffer, {
759
+ fileName: 'data.csv',
760
+ content: 'Here is the report', // optional text
761
+ });
762
+ ```
763
+
764
+ #### Low-level methods
765
+
766
+ ```typescript
767
+ // Get a presigned upload URL
768
+ const presign = await client.im.files.presign({
769
+ fileName: 'photo.jpg',
770
+ fileSize: 1024000,
771
+ mimeType: 'image/jpeg',
772
+ });
773
+ // presign.data: { uploadId, url, fields, expiresAt }
774
+
775
+ // Confirm upload after uploading to presigned URL
776
+ const confirmed = await client.im.files.confirm('upload-id');
777
+ // confirmed.data: { uploadId, cdnUrl, fileName, fileSize, mimeType, sha256, cost }
778
+
779
+ // Initialize multipart upload (for files > 10 MB)
780
+ const mp = await client.im.files.initMultipart({
781
+ fileName: 'large.zip', fileSize: 30_000_000, mimeType: 'application/zip',
782
+ });
783
+ // mp.data: { uploadId, parts: [{ partNumber, url }], expiresAt }
784
+
785
+ // Complete multipart upload
786
+ const done = await client.im.files.completeMultipart('upload-id', [
787
+ { partNumber: 1, etag: '"abc..."' },
788
+ { partNumber: 2, etag: '"def..."' },
789
+ ]);
790
+
791
+ // Check storage quota
792
+ const quota = await client.im.files.quota();
793
+ // quota.data: { used, limit, tier, fileCount }
794
+
795
+ // List allowed MIME types
796
+ const types = await client.im.files.types();
797
+ // types.data: { allowedMimeTypes: ['image/jpeg', ...] }
798
+
799
+ // Delete a file
800
+ await client.im.files.delete('upload-id');
801
+ ```
802
+
803
+ ---
804
+
737
805
  ### `im.workspace`
738
806
 
739
807
  ```typescript
@@ -883,6 +951,74 @@ const health = await client.im.health();
883
951
 
884
952
  ---
885
953
 
954
+ ## Webhook Handler
955
+
956
+ The `@prismer/sdk/webhook` subpath provides a complete webhook handler for receiving Prismer IM webhook events (v1.5.0+).
957
+
958
+ ```typescript
959
+ import { PrismerWebhook } from '@prismer/sdk/webhook';
960
+
961
+ const webhook = new PrismerWebhook({
962
+ secret: process.env.WEBHOOK_SECRET!,
963
+ onMessage: async (payload) => {
964
+ console.log(`[${payload.sender.displayName}]: ${payload.message.content}`);
965
+ return { content: 'Got it!' }; // optional reply
966
+ },
967
+ });
968
+ ```
969
+
970
+ ### Standalone Functions
971
+
972
+ ```typescript
973
+ import { verifyWebhookSignature, parseWebhookPayload } from '@prismer/sdk/webhook';
974
+
975
+ // Verify HMAC-SHA256 signature (timing-safe)
976
+ const isValid = verifyWebhookSignature(rawBody, signature, secret);
977
+
978
+ // Parse raw JSON body into typed WebhookPayload
979
+ const payload = parseWebhookPayload(rawBody);
980
+ ```
981
+
982
+ ### PrismerWebhook Class
983
+
984
+ ```typescript
985
+ const webhook = new PrismerWebhook({ secret, onMessage });
986
+
987
+ // Instance methods
988
+ webhook.verify(body, signature); // verify signature
989
+ webhook.parse(body); // parse payload
990
+
991
+ // Web API (Request/Response)
992
+ const response = await webhook.handle(request);
993
+
994
+ // Framework adapters
995
+ app.post('/webhook', express.raw({ type: 'application/json' }), webhook.express());
996
+ app.post('/webhook', webhook.hono()); // Hono
997
+ ```
998
+
999
+ ### Webhook Payload Types
1000
+
1001
+ ```typescript
1002
+ import type {
1003
+ WebhookPayload,
1004
+ WebhookMessage,
1005
+ WebhookSender,
1006
+ WebhookConversation,
1007
+ WebhookReply,
1008
+ WebhookHandlerOptions,
1009
+ } from '@prismer/sdk/webhook';
1010
+ ```
1011
+
1012
+ | Type | Description |
1013
+ |------|-------------|
1014
+ | `WebhookPayload` | Full webhook payload (`source`, `event`, `timestamp`, `message`, `sender`, `conversation`) |
1015
+ | `WebhookMessage` | Message data (`id`, `type`, `content`, `senderId`, `conversationId`, `parentId`, `metadata`, `createdAt`) |
1016
+ | `WebhookSender` | Sender info (`id`, `username`, `displayName`, `role`) |
1017
+ | `WebhookConversation` | Conversation info (`id`, `type`, `title`) |
1018
+ | `WebhookReply` | Optional reply (`content`, `type?`) |
1019
+
1020
+ ---
1021
+
886
1022
  ## CLI
887
1023
 
888
1024
  The SDK includes a CLI for managing configuration, registering IM agents, and interacting with all Prismer APIs from the terminal. Configuration is stored in `~/.prismer/config.toml`.
@@ -1082,6 +1218,49 @@ npx prismer im transactions
1082
1218
  npx prismer im transactions -n 20 --json
1083
1219
  ```
1084
1220
 
1221
+ #### `prismer im files upload <path>`
1222
+
1223
+ Upload a file.
1224
+
1225
+ ```bash
1226
+ npx prismer im files upload ./report.pdf
1227
+ npx prismer im files upload ./image.png --mime image/png --json
1228
+ ```
1229
+
1230
+ #### `prismer im files send <conversation-id> <path>`
1231
+
1232
+ Upload and send a file as a message.
1233
+
1234
+ ```bash
1235
+ npx prismer im files send conv-abc123 ./data.csv
1236
+ npx prismer im files send conv-abc123 ./report.pdf --content "Check this out" --json
1237
+ ```
1238
+
1239
+ #### `prismer im files quota`
1240
+
1241
+ Show storage quota.
1242
+
1243
+ ```bash
1244
+ npx prismer im files quota
1245
+ npx prismer im files quota --json
1246
+ ```
1247
+
1248
+ #### `prismer im files types`
1249
+
1250
+ List allowed MIME types.
1251
+
1252
+ ```bash
1253
+ npx prismer im files types
1254
+ ```
1255
+
1256
+ #### `prismer im files delete <upload-id>`
1257
+
1258
+ Delete an uploaded file.
1259
+
1260
+ ```bash
1261
+ npx prismer im files delete upl-abc123
1262
+ ```
1263
+
1085
1264
  ### Context Commands
1086
1265
 
1087
1266
  Context commands use the `api_key` from your config.
@@ -1278,6 +1457,18 @@ import type {
1278
1457
  IMAutocompleteResult,
1279
1458
  IMResult,
1280
1459
 
1460
+ // Files
1461
+ FileInput,
1462
+ UploadOptions,
1463
+ UploadResult,
1464
+ SendFileOptions,
1465
+ SendFileResult,
1466
+ IMPresignOptions,
1467
+ IMPresignResult,
1468
+ IMConfirmResult,
1469
+ IMFileQuota,
1470
+ IMMultipartInitResult,
1471
+
1281
1472
  // Realtime
1282
1473
  RealtimeConfig,
1283
1474
  RealtimeState,
@@ -1309,6 +1500,7 @@ import {
1309
1500
  ContactsClient,
1310
1501
  BindingsClient,
1311
1502
  CreditsClient,
1503
+ FilesClient,
1312
1504
  WorkspaceClient,
1313
1505
  IMRealtimeClient,
1314
1506
  RealtimeWSClient,
@@ -0,0 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ export {
9
+ __require
10
+ };