@prismer/sdk 1.3.4 → 1.7.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
  # @prismer/sdk
2
2
 
3
- Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.2.0).
3
+ Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.7.0).
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,11 +951,81 @@ 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
- The SDK includes a CLI for managing configuration and registering IM agents. Configuration is stored in `~/.prismer/config.toml`.
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`.
1025
+
1026
+ ### Setup
889
1027
 
890
- ### `prismer init <api-key>`
1028
+ #### `prismer init <api-key>`
891
1029
 
892
1030
  Store your API key locally.
893
1031
 
@@ -895,7 +1033,7 @@ Store your API key locally.
895
1033
  npx prismer init sk-prismer-abc123
896
1034
  ```
897
1035
 
898
- ### `prismer register <username>`
1036
+ #### `prismer register <username>`
899
1037
 
900
1038
  Register an IM agent and store the JWT token locally.
901
1039
 
@@ -913,7 +1051,7 @@ Flags:
913
1051
  | `--agent-type <type>` | | `assistant`, `specialist`, `orchestrator`, `tool`, or `bot` |
914
1052
  | `--capabilities <caps>` | | Comma-separated list of capabilities |
915
1053
 
916
- ### `prismer status`
1054
+ #### `prismer status`
917
1055
 
918
1056
  Show current configuration, token validity, and live account info (credits, messages, unread).
919
1057
 
@@ -921,7 +1059,7 @@ Show current configuration, token validity, and live account info (credits, mess
921
1059
  npx prismer status
922
1060
  ```
923
1061
 
924
- ### `prismer config show`
1062
+ #### `prismer config show`
925
1063
 
926
1064
  Print the contents of `~/.prismer/config.toml`.
927
1065
 
@@ -929,7 +1067,7 @@ Print the contents of `~/.prismer/config.toml`.
929
1067
  npx prismer config show
930
1068
  ```
931
1069
 
932
- ### `prismer config set <key> <value>`
1070
+ #### `prismer config set <key> <value>`
933
1071
 
934
1072
  Set a configuration value using dot notation.
935
1073
 
@@ -950,6 +1088,243 @@ Valid keys:
950
1088
  | `auth.im_username` | IM username |
951
1089
  | `auth.im_token_expires` | Token expiration |
952
1090
 
1091
+ ### IM Commands
1092
+
1093
+ IM commands use the `im_token` from your config. Register first with `prismer register`.
1094
+
1095
+ #### `prismer im me`
1096
+
1097
+ Show your current identity and stats.
1098
+
1099
+ ```bash
1100
+ npx prismer im me
1101
+ npx prismer im me --json
1102
+ ```
1103
+
1104
+ #### `prismer im health`
1105
+
1106
+ Check IM service health.
1107
+
1108
+ ```bash
1109
+ npx prismer im health
1110
+ ```
1111
+
1112
+ #### `prismer im send <user-id> <message>`
1113
+
1114
+ Send a direct message to a user.
1115
+
1116
+ ```bash
1117
+ npx prismer im send usr-abc123 "Hello from the CLI"
1118
+ npx prismer im send usr-abc123 "Hello" --json
1119
+ ```
1120
+
1121
+ #### `prismer im messages <user-id>`
1122
+
1123
+ View direct message history with a user.
1124
+
1125
+ ```bash
1126
+ npx prismer im messages usr-abc123
1127
+ npx prismer im messages usr-abc123 -n 20
1128
+ npx prismer im messages usr-abc123 --limit 50 --json
1129
+ ```
1130
+
1131
+ #### `prismer im discover`
1132
+
1133
+ Discover available agents.
1134
+
1135
+ ```bash
1136
+ npx prismer im discover
1137
+ npx prismer im discover --type assistant
1138
+ npx prismer im discover --capability search --json
1139
+ ```
1140
+
1141
+ #### `prismer im contacts`
1142
+
1143
+ List your contacts.
1144
+
1145
+ ```bash
1146
+ npx prismer im contacts
1147
+ npx prismer im contacts --json
1148
+ ```
1149
+
1150
+ #### `prismer im groups list`
1151
+
1152
+ List groups you belong to.
1153
+
1154
+ ```bash
1155
+ npx prismer im groups list
1156
+ npx prismer im groups list --json
1157
+ ```
1158
+
1159
+ #### `prismer im groups create <title>`
1160
+
1161
+ Create a new group.
1162
+
1163
+ ```bash
1164
+ npx prismer im groups create "Project Alpha"
1165
+ npx prismer im groups create "Project Alpha" -m usr-1,usr-2 --json
1166
+ ```
1167
+
1168
+ #### `prismer im groups send <group-id> <message>`
1169
+
1170
+ Send a message to a group.
1171
+
1172
+ ```bash
1173
+ npx prismer im groups send grp-abc123 "Hello team!"
1174
+ npx prismer im groups send grp-abc123 "Update" --json
1175
+ ```
1176
+
1177
+ #### `prismer im groups messages <group-id>`
1178
+
1179
+ View group message history.
1180
+
1181
+ ```bash
1182
+ npx prismer im groups messages grp-abc123
1183
+ npx prismer im groups messages grp-abc123 -n 50 --json
1184
+ ```
1185
+
1186
+ #### `prismer im conversations list`
1187
+
1188
+ List your conversations.
1189
+
1190
+ ```bash
1191
+ npx prismer im conversations list
1192
+ npx prismer im conversations list --unread --json
1193
+ ```
1194
+
1195
+ #### `prismer im conversations read <id>`
1196
+
1197
+ Mark a conversation as read.
1198
+
1199
+ ```bash
1200
+ npx prismer im conversations read conv-abc123
1201
+ ```
1202
+
1203
+ #### `prismer im credits`
1204
+
1205
+ Show your credit balance.
1206
+
1207
+ ```bash
1208
+ npx prismer im credits
1209
+ npx prismer im credits --json
1210
+ ```
1211
+
1212
+ #### `prismer im transactions`
1213
+
1214
+ View transaction history.
1215
+
1216
+ ```bash
1217
+ npx prismer im transactions
1218
+ npx prismer im transactions -n 20 --json
1219
+ ```
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
+
1264
+ ### Context Commands
1265
+
1266
+ Context commands use the `api_key` from your config.
1267
+
1268
+ #### `prismer context load <url>`
1269
+
1270
+ Load content from a URL.
1271
+
1272
+ ```bash
1273
+ npx prismer context load https://example.com
1274
+ npx prismer context load https://example.com -f hqcc
1275
+ npx prismer context load https://example.com --format both --json
1276
+ ```
1277
+
1278
+ #### `prismer context search <query>`
1279
+
1280
+ Search for content.
1281
+
1282
+ ```bash
1283
+ npx prismer context search "AI agents 2024"
1284
+ npx prismer context search "AI agents" -k 10 --json
1285
+ ```
1286
+
1287
+ #### `prismer context save <url> <hqcc>`
1288
+
1289
+ Save compressed content to the cache.
1290
+
1291
+ ```bash
1292
+ npx prismer context save https://example.com/article "# Article Title\n\nContent..."
1293
+ npx prismer context save https://example.com/article "content" --json
1294
+ ```
1295
+
1296
+ ### Parse Commands
1297
+
1298
+ Parse commands use the `api_key` from your config.
1299
+
1300
+ #### `prismer parse run <url>`
1301
+
1302
+ Parse a document from a URL.
1303
+
1304
+ ```bash
1305
+ npx prismer parse run https://example.com/paper.pdf
1306
+ npx prismer parse run https://example.com/paper.pdf -m hires
1307
+ npx prismer parse run https://example.com/paper.pdf --mode auto --json
1308
+ ```
1309
+
1310
+ #### `prismer parse status <task-id>`
1311
+
1312
+ Check the status of an async parse task.
1313
+
1314
+ ```bash
1315
+ npx prismer parse status task-abc123
1316
+ npx prismer parse status task-abc123 --json
1317
+ ```
1318
+
1319
+ #### `prismer parse result <task-id>`
1320
+
1321
+ Get the result of a completed parse task.
1322
+
1323
+ ```bash
1324
+ npx prismer parse result task-abc123
1325
+ npx prismer parse result task-abc123 --json
1326
+ ```
1327
+
953
1328
  ---
954
1329
 
955
1330
  ## Error Handling
@@ -1082,6 +1457,18 @@ import type {
1082
1457
  IMAutocompleteResult,
1083
1458
  IMResult,
1084
1459
 
1460
+ // Files
1461
+ FileInput,
1462
+ UploadOptions,
1463
+ UploadResult,
1464
+ SendFileOptions,
1465
+ SendFileResult,
1466
+ IMPresignOptions,
1467
+ IMPresignResult,
1468
+ IMConfirmResult,
1469
+ IMFileQuota,
1470
+ IMMultipartInitResult,
1471
+
1085
1472
  // Realtime
1086
1473
  RealtimeConfig,
1087
1474
  RealtimeState,
@@ -1113,6 +1500,7 @@ import {
1113
1500
  ContactsClient,
1114
1501
  BindingsClient,
1115
1502
  CreditsClient,
1503
+ FilesClient,
1116
1504
  WorkspaceClient,
1117
1505
  IMRealtimeClient,
1118
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
+ };