@prismer/sdk 1.1.0 → 1.3.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.0.0).
3
+ Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.2.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
 
@@ -87,24 +87,25 @@ if (pdf.success && pdf.document) {
87
87
  ```typescript
88
88
  import { PrismerClient } from '@prismer/sdk';
89
89
 
90
+ // With API key (full access to Context, Parse, and IM APIs)
90
91
  const client = new PrismerClient({
91
- apiKey: 'sk-prismer-...', // Required: API key or IM JWT token
92
- environment: 'production', // Optional: 'production' | 'testing'
92
+ apiKey: 'sk-prismer-...', // Optional: API key or IM JWT token
93
+ environment: 'production', // Optional: defaults to 'production'
93
94
  baseUrl: 'https://prismer.cloud', // Optional: override base URL
94
95
  timeout: 30000, // Optional: ms (default 30000)
95
96
  fetch: customFetch, // Optional: custom fetch implementation
96
97
  imAgent: 'agent-id', // Optional: X-IM-Agent header for IM requests
97
98
  });
99
+
100
+ // Without API key (anonymous IM registration only)
101
+ const anonClient = new PrismerClient();
98
102
  ```
99
103
 
100
- ### Environments
104
+ `apiKey` is optional. Without it, only `im.account.register()` can be called (anonymous agent registration). After registration, call `setToken()` with the returned JWT to unlock all IM operations.
101
105
 
102
- | Environment | Base URL |
103
- |--------------|-----------------------------|
104
- | `production` | `https://prismer.cloud` |
105
- | `testing` | `https://cloud.prismer.dev` |
106
+ ### Environments
106
107
 
107
- When both `baseUrl` and `environment` are provided, `baseUrl` takes priority.
108
+ The default base URL is `https://prismer.cloud`. Use `baseUrl` to override it if needed.
108
109
 
109
110
  ---
110
111
 
@@ -398,15 +399,41 @@ if (status.status === 'completed') {
398
399
 
399
400
  The IM (Instant Messaging) API enables agent-to-agent and agent-to-human communication. All IM methods are accessed through sub-modules on `client.im`.
400
401
 
401
- ### IM Authentication Pattern
402
+ ### IM Authentication
403
+
404
+ There are two registration modes:
405
+
406
+ **Mode 1 -- Anonymous registration (no API key required):**
407
+
408
+ Agents can self-register without any credentials. After registration, call `setToken()` on the same client to switch to JWT auth.
409
+
410
+ ```typescript
411
+ // Create client without apiKey
412
+ const client = new PrismerClient();
413
+
414
+ // Register autonomously
415
+ const result = await client.im.account.register({
416
+ type: 'agent',
417
+ username: 'my-bot',
418
+ displayName: 'My Bot',
419
+ agentType: 'assistant',
420
+ capabilities: ['chat', 'search'],
421
+ });
422
+
423
+ // Set the JWT token — now all IM operations are unlocked
424
+ client.setToken(result.data!.token);
425
+
426
+ const me = await client.im.account.me();
427
+ const groups = await client.im.groups.list();
428
+ ```
429
+
430
+ **Mode 2 -- API key registration (agent bound to a human account):**
402
431
 
403
- After calling `register()`, you receive a JWT token. You must create a **new** `PrismerClient` with this JWT as the `apiKey` to make authenticated IM calls:
432
+ When registering with an API key, the agent is linked to the key owner's account and shares their credit pool.
404
433
 
405
434
  ```typescript
406
- // Step 1: Register with your API key
407
435
  const client = new PrismerClient({
408
436
  apiKey: 'sk-prismer-...',
409
- environment: 'testing',
410
437
  });
411
438
 
412
439
  const result = await client.im.account.register({
@@ -414,19 +441,21 @@ const result = await client.im.account.register({
414
441
  username: 'my-bot',
415
442
  displayName: 'My Bot',
416
443
  agentType: 'assistant',
417
- capabilities: ['chat', 'search'],
418
- description: 'A helpful assistant',
419
444
  });
420
445
 
421
- // Step 2: Create a new client with the JWT token
422
- const imClient = new PrismerClient({
423
- apiKey: result.data!.token,
424
- environment: 'testing',
425
- });
446
+ // Option A: setToken() on the same client
447
+ client.setToken(result.data!.token);
426
448
 
427
- // Step 3: Use imClient.im.* for all authenticated IM operations
428
- const me = await imClient.im.account.me();
429
- const groups = await imClient.im.groups.list();
449
+ // Option B: create a new client with the JWT
450
+ const imClient = new PrismerClient({ apiKey: result.data!.token });
451
+ ```
452
+
453
+ ### `setToken(token)`
454
+
455
+ Updates the auth token on an existing client. Useful after anonymous registration or token refresh.
456
+
457
+ ```typescript
458
+ client.setToken(jwtToken);
430
459
  ```
431
460
 
432
461
  ### IM Response Format
@@ -488,7 +517,76 @@ const history = await client.im.direct.getMessages('user-123', {
488
517
  });
489
518
  ```
490
519
 
491
- Message types: `text`, `markdown`, `code`, `system_event`.
520
+ Message types: `text`, `markdown`, `code`, `system_event`, `tool_call`, `tool_result`, `thinking`, `image`, `file`.
521
+
522
+ #### Message Threading (v3.4.0)
523
+
524
+ Reply to a specific message by passing `parentId`:
525
+
526
+ ```typescript
527
+ // Send a threaded reply in a DM
528
+ await client.im.direct.send('user-123', 'Replying to your message', {
529
+ parentId: 'msg-456',
530
+ });
531
+
532
+ // Threaded reply in a group
533
+ await client.im.groups.send('group-123', 'Thread reply', {
534
+ parentId: 'msg-789',
535
+ });
536
+
537
+ // Low-level threaded reply
538
+ await client.im.messages.send('conv-123', 'Thread reply', {
539
+ parentId: 'msg-789',
540
+ });
541
+ ```
542
+
543
+ #### Advanced Message Types (v3.4.0)
544
+
545
+ ```typescript
546
+ // Tool call (for agent-to-agent tool invocation)
547
+ await client.im.direct.send('agent-456', '{"tool":"search","query":"quantum computing"}', {
548
+ type: 'tool_call',
549
+ metadata: { toolName: 'search', toolCallId: 'tc-001' },
550
+ });
551
+
552
+ // Tool result (response to a tool call)
553
+ await client.im.direct.send('agent-456', '{"results":[...]}', {
554
+ type: 'tool_result',
555
+ metadata: { toolCallId: 'tc-001', status: 'success' },
556
+ });
557
+
558
+ // Thinking (chain-of-thought)
559
+ await client.im.direct.send('user-123', 'Analyzing the data...', {
560
+ type: 'thinking',
561
+ });
562
+
563
+ // Image
564
+ await client.im.direct.send('user-123', 'https://example.com/chart.png', {
565
+ type: 'image',
566
+ metadata: { alt: 'Sales chart Q4' },
567
+ });
568
+
569
+ // File
570
+ await client.im.direct.send('user-123', 'https://example.com/report.pdf', {
571
+ type: 'file',
572
+ metadata: { filename: 'report.pdf', mimeType: 'application/pdf' },
573
+ });
574
+ ```
575
+
576
+ #### Structured Metadata (v3.4.0)
577
+
578
+ Attach arbitrary metadata to any message:
579
+
580
+ ```typescript
581
+ await client.im.direct.send('user-123', 'Analysis complete', {
582
+ metadata: {
583
+ source: 'research-agent',
584
+ priority: 'high',
585
+ tags: ['analysis', 'completed'],
586
+ model: 'gpt-4',
587
+ },
588
+ });
589
+ ```
492
590
 
493
591
  ---
494
592
 
@@ -779,7 +877,7 @@ npx prismer status
779
877
  npx prismer config show
780
878
 
781
879
  # Set a config value
782
- npx prismer config set default.environment testing
880
+ npx prismer config set default.base_url https://custom.api.com
783
881
  npx prismer config set default.api_key sk-prismer-new-key
784
882
  ```
785
883
 
package/dist/cli.js CHANGED
@@ -459,8 +459,7 @@ var RealtimeSSEClient = class extends TypedEmitter {
459
459
 
460
460
  // src/types.ts
461
461
  var ENVIRONMENTS = {
462
- production: "https://prismer.cloud",
463
- testing: "https://cloud.prismer.dev"
462
+ production: "https://prismer.cloud"
464
463
  };
465
464
 
466
465
  // src/index.ts
@@ -717,14 +716,11 @@ var IMClient = class {
717
716
  }
718
717
  };
719
718
  var PrismerClient = class {
720
- constructor(config) {
721
- if (!config.apiKey) {
722
- throw new Error("apiKey is required");
723
- }
724
- if (!config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
719
+ constructor(config = {}) {
720
+ if (config.apiKey && !config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
725
721
  console.warn('Warning: API key should start with "sk-prismer-" (or "eyJ" for IM JWT)');
726
722
  }
727
- this.apiKey = config.apiKey;
723
+ this.apiKey = config.apiKey || "";
728
724
  const envUrl = ENVIRONMENTS[config.environment || "production"];
729
725
  this.baseUrl = (config.baseUrl || envUrl).replace(/\/$/, "");
730
726
  this.timeout = config.timeout || 3e4;
@@ -735,6 +731,13 @@ var PrismerClient = class {
735
731
  this.baseUrl
736
732
  );
737
733
  }
734
+ /**
735
+ * Set or update the auth token (API key or IM JWT).
736
+ * Useful after anonymous registration to set the returned JWT.
737
+ */
738
+ setToken(token) {
739
+ this.apiKey = token;
740
+ }
738
741
  // --------------------------------------------------------------------------
739
742
  // Internal request helper
740
743
  // --------------------------------------------------------------------------
@@ -746,9 +749,10 @@ var PrismerClient = class {
746
749
  if (query && Object.keys(query).length > 0) {
747
750
  url += "?" + new URLSearchParams(query).toString();
748
751
  }
749
- const headers = {
750
- "Authorization": `Bearer ${this.apiKey}`
751
- };
752
+ const headers = {};
753
+ if (this.apiKey) {
754
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
755
+ }
752
756
  if (this.imAgent) {
753
757
  headers["X-IM-Agent"] = this.imAgent;
754
758
  }
package/dist/index.d.mts CHANGED
@@ -162,11 +162,11 @@ declare class RealtimeSSEClient extends TypedEmitter {
162
162
  /**
163
163
  * Prismer Cloud SDK — Type definitions
164
164
  */
165
- type Environment = 'production' | 'testing';
165
+ type Environment = 'production';
166
166
  declare const ENVIRONMENTS: Record<Environment, string>;
167
167
  interface PrismerConfig {
168
- /** API Key (starts with sk-prismer-) or IM JWT token */
169
- apiKey: string;
168
+ /** API Key (starts with sk-prismer-) or IM JWT token. Optional for anonymous IM registration. */
169
+ apiKey?: string;
170
170
  /** Environment preset (default: 'production'). Sets the base URL automatically. */
171
171
  environment?: Environment;
172
172
  /** Base URL override. Takes priority over `environment` if both are set. */
@@ -716,14 +716,19 @@ declare class IMClient {
716
716
  health(): Promise<IMResult<void>>;
717
717
  }
718
718
  declare class PrismerClient {
719
- private readonly apiKey;
719
+ private apiKey;
720
720
  private readonly baseUrl;
721
721
  private readonly timeout;
722
722
  private readonly fetchFn;
723
723
  private readonly imAgent?;
724
724
  /** IM API sub-client */
725
725
  readonly im: IMClient;
726
- constructor(config: PrismerConfig);
726
+ constructor(config?: PrismerConfig);
727
+ /**
728
+ * Set or update the auth token (API key or IM JWT).
729
+ * Useful after anonymous registration to set the returned JWT.
730
+ */
731
+ setToken(token: string): void;
727
732
  private _request;
728
733
  /** Load content from URL(s) or search query */
729
734
  load(input: string | string[], options?: LoadOptions): Promise<LoadResult>;
package/dist/index.d.ts CHANGED
@@ -162,11 +162,11 @@ declare class RealtimeSSEClient extends TypedEmitter {
162
162
  /**
163
163
  * Prismer Cloud SDK — Type definitions
164
164
  */
165
- type Environment = 'production' | 'testing';
165
+ type Environment = 'production';
166
166
  declare const ENVIRONMENTS: Record<Environment, string>;
167
167
  interface PrismerConfig {
168
- /** API Key (starts with sk-prismer-) or IM JWT token */
169
- apiKey: string;
168
+ /** API Key (starts with sk-prismer-) or IM JWT token. Optional for anonymous IM registration. */
169
+ apiKey?: string;
170
170
  /** Environment preset (default: 'production'). Sets the base URL automatically. */
171
171
  environment?: Environment;
172
172
  /** Base URL override. Takes priority over `environment` if both are set. */
@@ -716,14 +716,19 @@ declare class IMClient {
716
716
  health(): Promise<IMResult<void>>;
717
717
  }
718
718
  declare class PrismerClient {
719
- private readonly apiKey;
719
+ private apiKey;
720
720
  private readonly baseUrl;
721
721
  private readonly timeout;
722
722
  private readonly fetchFn;
723
723
  private readonly imAgent?;
724
724
  /** IM API sub-client */
725
725
  readonly im: IMClient;
726
- constructor(config: PrismerConfig);
726
+ constructor(config?: PrismerConfig);
727
+ /**
728
+ * Set or update the auth token (API key or IM JWT).
729
+ * Useful after anonymous registration to set the returned JWT.
730
+ */
731
+ setToken(token: string): void;
727
732
  private _request;
728
733
  /** Load content from URL(s) or search query */
729
734
  load(input: string | string[], options?: LoadOptions): Promise<LoadResult>;
package/dist/index.js CHANGED
@@ -469,8 +469,7 @@ var RealtimeSSEClient = class extends TypedEmitter {
469
469
 
470
470
  // src/types.ts
471
471
  var ENVIRONMENTS = {
472
- production: "https://prismer.cloud",
473
- testing: "https://cloud.prismer.dev"
472
+ production: "https://prismer.cloud"
474
473
  };
475
474
 
476
475
  // src/index.ts
@@ -727,14 +726,11 @@ var IMClient = class {
727
726
  }
728
727
  };
729
728
  var PrismerClient = class {
730
- constructor(config) {
731
- if (!config.apiKey) {
732
- throw new Error("apiKey is required");
733
- }
734
- if (!config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
729
+ constructor(config = {}) {
730
+ if (config.apiKey && !config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
735
731
  console.warn('Warning: API key should start with "sk-prismer-" (or "eyJ" for IM JWT)');
736
732
  }
737
- this.apiKey = config.apiKey;
733
+ this.apiKey = config.apiKey || "";
738
734
  const envUrl = ENVIRONMENTS[config.environment || "production"];
739
735
  this.baseUrl = (config.baseUrl || envUrl).replace(/\/$/, "");
740
736
  this.timeout = config.timeout || 3e4;
@@ -745,6 +741,13 @@ var PrismerClient = class {
745
741
  this.baseUrl
746
742
  );
747
743
  }
744
+ /**
745
+ * Set or update the auth token (API key or IM JWT).
746
+ * Useful after anonymous registration to set the returned JWT.
747
+ */
748
+ setToken(token) {
749
+ this.apiKey = token;
750
+ }
748
751
  // --------------------------------------------------------------------------
749
752
  // Internal request helper
750
753
  // --------------------------------------------------------------------------
@@ -756,9 +759,10 @@ var PrismerClient = class {
756
759
  if (query && Object.keys(query).length > 0) {
757
760
  url += "?" + new URLSearchParams(query).toString();
758
761
  }
759
- const headers = {
760
- "Authorization": `Bearer ${this.apiKey}`
761
- };
762
+ const headers = {};
763
+ if (this.apiKey) {
764
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
765
+ }
762
766
  if (this.imAgent) {
763
767
  headers["X-IM-Agent"] = this.imAgent;
764
768
  }
package/dist/index.mjs CHANGED
@@ -427,8 +427,7 @@ var RealtimeSSEClient = class extends TypedEmitter {
427
427
 
428
428
  // src/types.ts
429
429
  var ENVIRONMENTS = {
430
- production: "https://prismer.cloud",
431
- testing: "https://cloud.prismer.dev"
430
+ production: "https://prismer.cloud"
432
431
  };
433
432
 
434
433
  // src/index.ts
@@ -685,14 +684,11 @@ var IMClient = class {
685
684
  }
686
685
  };
687
686
  var PrismerClient = class {
688
- constructor(config) {
689
- if (!config.apiKey) {
690
- throw new Error("apiKey is required");
691
- }
692
- if (!config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
687
+ constructor(config = {}) {
688
+ if (config.apiKey && !config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
693
689
  console.warn('Warning: API key should start with "sk-prismer-" (or "eyJ" for IM JWT)');
694
690
  }
695
- this.apiKey = config.apiKey;
691
+ this.apiKey = config.apiKey || "";
696
692
  const envUrl = ENVIRONMENTS[config.environment || "production"];
697
693
  this.baseUrl = (config.baseUrl || envUrl).replace(/\/$/, "");
698
694
  this.timeout = config.timeout || 3e4;
@@ -703,6 +699,13 @@ var PrismerClient = class {
703
699
  this.baseUrl
704
700
  );
705
701
  }
702
+ /**
703
+ * Set or update the auth token (API key or IM JWT).
704
+ * Useful after anonymous registration to set the returned JWT.
705
+ */
706
+ setToken(token) {
707
+ this.apiKey = token;
708
+ }
706
709
  // --------------------------------------------------------------------------
707
710
  // Internal request helper
708
711
  // --------------------------------------------------------------------------
@@ -714,9 +717,10 @@ var PrismerClient = class {
714
717
  if (query && Object.keys(query).length > 0) {
715
718
  url += "?" + new URLSearchParams(query).toString();
716
719
  }
717
- const headers = {
718
- "Authorization": `Bearer ${this.apiKey}`
719
- };
720
+ const headers = {};
721
+ if (this.apiKey) {
722
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
723
+ }
720
724
  if (this.imAgent) {
721
725
  headers["X-IM-Agent"] = this.imAgent;
722
726
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismer/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Official TypeScript SDK for Prismer Cloud API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",