@prismer/sdk 1.0.0 → 1.2.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.1.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
 
@@ -488,7 +488,76 @@ const history = await client.im.direct.getMessages('user-123', {
488
488
  });
489
489
  ```
490
490
 
491
- Message types: `text`, `markdown`, `code`, `system_event`.
491
+ Message types: `text`, `markdown`, `code`, `system_event`, `tool_call`, `tool_result`, `thinking`, `image`, `file`.
492
+
493
+ #### Message Threading (v3.4.0)
494
+
495
+ Reply to a specific message by passing `parentId`:
496
+
497
+ ```typescript
498
+ // Send a threaded reply in a DM
499
+ await client.im.direct.send('user-123', 'Replying to your message', {
500
+ parentId: 'msg-456',
501
+ });
502
+
503
+ // Threaded reply in a group
504
+ await client.im.groups.send('group-123', 'Thread reply', {
505
+ parentId: 'msg-789',
506
+ });
507
+
508
+ // Low-level threaded reply
509
+ await client.im.messages.send('conv-123', 'Thread reply', {
510
+ parentId: 'msg-789',
511
+ });
512
+ ```
513
+
514
+ #### Advanced Message Types (v3.4.0)
515
+
516
+ ```typescript
517
+ // Tool call (for agent-to-agent tool invocation)
518
+ await client.im.direct.send('agent-456', '{"tool":"search","query":"quantum computing"}', {
519
+ type: 'tool_call',
520
+ metadata: { toolName: 'search', toolCallId: 'tc-001' },
521
+ });
522
+
523
+ // Tool result (response to a tool call)
524
+ await client.im.direct.send('agent-456', '{"results":[...]}', {
525
+ type: 'tool_result',
526
+ metadata: { toolCallId: 'tc-001', status: 'success' },
527
+ });
528
+
529
+ // Thinking (chain-of-thought)
530
+ await client.im.direct.send('user-123', 'Analyzing the data...', {
531
+ type: 'thinking',
532
+ });
533
+
534
+ // Image
535
+ await client.im.direct.send('user-123', 'https://example.com/chart.png', {
536
+ type: 'image',
537
+ metadata: { alt: 'Sales chart Q4' },
538
+ });
539
+
540
+ // File
541
+ await client.im.direct.send('user-123', 'https://example.com/report.pdf', {
542
+ type: 'file',
543
+ metadata: { filename: 'report.pdf', mimeType: 'application/pdf' },
544
+ });
545
+ ```
546
+
547
+ #### Structured Metadata (v3.4.0)
548
+
549
+ Attach arbitrary metadata to any message:
550
+
551
+ ```typescript
552
+ await client.im.direct.send('user-123', 'Analysis complete', {
553
+ metadata: {
554
+ source: 'research-agent',
555
+ priority: 'high',
556
+ tags: ['analysis', 'completed'],
557
+ model: 'gpt-4',
558
+ },
559
+ });
560
+ ```
492
561
 
493
562
  ---
494
563
 
package/dist/cli.js CHANGED
@@ -490,7 +490,8 @@ var DirectClient = class {
490
490
  return this._r("POST", `/api/im/direct/${userId}/messages`, {
491
491
  content,
492
492
  type: options?.type ?? "text",
493
- metadata: options?.metadata
493
+ metadata: options?.metadata,
494
+ parentId: options?.parentId
494
495
  });
495
496
  }
496
497
  /** Get direct message history with a user */
@@ -522,7 +523,8 @@ var GroupsClient = class {
522
523
  return this._r("POST", `/api/im/groups/${groupId}/messages`, {
523
524
  content,
524
525
  type: options?.type ?? "text",
525
- metadata: options?.metadata
526
+ metadata: options?.metadata,
527
+ parentId: options?.parentId
526
528
  });
527
529
  }
528
530
  /** Get group message history */
@@ -574,7 +576,8 @@ var MessagesClient = class {
574
576
  return this._r("POST", `/api/im/messages/${conversationId}`, {
575
577
  content,
576
578
  type: options?.type ?? "text",
577
- metadata: options?.metadata
579
+ metadata: options?.metadata,
580
+ parentId: options?.parentId
578
581
  });
579
582
  }
580
583
  /** Get message history for a conversation */
@@ -714,14 +717,11 @@ var IMClient = class {
714
717
  }
715
718
  };
716
719
  var PrismerClient = class {
717
- constructor(config) {
718
- if (!config.apiKey) {
719
- throw new Error("apiKey is required");
720
- }
721
- if (!config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
720
+ constructor(config = {}) {
721
+ if (config.apiKey && !config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
722
722
  console.warn('Warning: API key should start with "sk-prismer-" (or "eyJ" for IM JWT)');
723
723
  }
724
- this.apiKey = config.apiKey;
724
+ this.apiKey = config.apiKey || "";
725
725
  const envUrl = ENVIRONMENTS[config.environment || "production"];
726
726
  this.baseUrl = (config.baseUrl || envUrl).replace(/\/$/, "");
727
727
  this.timeout = config.timeout || 3e4;
@@ -732,6 +732,13 @@ var PrismerClient = class {
732
732
  this.baseUrl
733
733
  );
734
734
  }
735
+ /**
736
+ * Set or update the auth token (API key or IM JWT).
737
+ * Useful after anonymous registration to set the returned JWT.
738
+ */
739
+ setToken(token) {
740
+ this.apiKey = token;
741
+ }
735
742
  // --------------------------------------------------------------------------
736
743
  // Internal request helper
737
744
  // --------------------------------------------------------------------------
@@ -743,9 +750,10 @@ var PrismerClient = class {
743
750
  if (query && Object.keys(query).length > 0) {
744
751
  url += "?" + new URLSearchParams(query).toString();
745
752
  }
746
- const headers = {
747
- "Authorization": `Bearer ${this.apiKey}`
748
- };
753
+ const headers = {};
754
+ if (this.apiKey) {
755
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
756
+ }
749
757
  if (this.imAgent) {
750
758
  headers["X-IM-Agent"] = this.imAgent;
751
759
  }
package/dist/index.d.mts CHANGED
@@ -165,8 +165,8 @@ declare class RealtimeSSEClient extends TypedEmitter {
165
165
  type Environment = 'production' | 'testing';
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. */
@@ -179,7 +179,7 @@ interface PrismerConfig {
179
179
  imAgent?: string;
180
180
  }
181
181
  interface LoadOptions {
182
- inputType?: 'url' | 'urls' | 'query';
182
+ inputType?: 'auto' | 'url' | 'urls' | 'query';
183
183
  processUncached?: boolean;
184
184
  search?: {
185
185
  topK?: number;
@@ -392,6 +392,8 @@ interface IMMeData {
392
392
  agentCard?: IMAgentCard;
393
393
  stats: {
394
394
  conversationCount: number;
395
+ directCount?: number;
396
+ groupCount?: number;
395
397
  contactCount: number;
396
398
  messagesSent: number;
397
399
  unreadCount: number;
@@ -412,11 +414,15 @@ interface IMTokenData {
412
414
  }
413
415
  interface IMMessage {
414
416
  id: string;
417
+ conversationId?: string;
415
418
  content: string;
416
419
  type: string;
417
420
  senderId: string;
421
+ parentId?: string | null;
422
+ status?: string;
418
423
  createdAt: string;
419
- metadata?: Record<string, any>;
424
+ updatedAt?: string;
425
+ metadata?: Record<string, any> | string;
420
426
  }
421
427
  interface IMRouting {
422
428
  mode: string;
@@ -433,6 +439,7 @@ interface IMMessageData {
433
439
  interface IMGroupMember {
434
440
  userId: string;
435
441
  username: string;
442
+ displayName?: string;
436
443
  role: string;
437
444
  }
438
445
  interface IMGroupData {
@@ -504,7 +511,8 @@ interface IMAutocompleteResult {
504
511
  interface IMCreateGroupOptions {
505
512
  title: string;
506
513
  description?: string;
507
- members: string[];
514
+ members?: string[];
515
+ metadata?: Record<string, any>;
508
516
  }
509
517
  interface IMCreateBindingOptions {
510
518
  platform: 'telegram' | 'discord' | 'slack' | 'wechat' | 'x' | 'line';
@@ -513,8 +521,9 @@ interface IMCreateBindingOptions {
513
521
  channelId?: string;
514
522
  }
515
523
  interface IMSendOptions {
516
- type?: 'text' | 'markdown' | 'code' | 'system_event';
524
+ type?: 'text' | 'markdown' | 'code' | 'image' | 'file' | 'tool_call' | 'tool_result' | 'system_event' | 'thinking';
517
525
  metadata?: Record<string, any>;
526
+ parentId?: string;
518
527
  }
519
528
  interface IMPaginationOptions {
520
529
  limit?: number;
@@ -707,14 +716,19 @@ declare class IMClient {
707
716
  health(): Promise<IMResult<void>>;
708
717
  }
709
718
  declare class PrismerClient {
710
- private readonly apiKey;
719
+ private apiKey;
711
720
  private readonly baseUrl;
712
721
  private readonly timeout;
713
722
  private readonly fetchFn;
714
723
  private readonly imAgent?;
715
724
  /** IM API sub-client */
716
725
  readonly im: IMClient;
717
- 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;
718
732
  private _request;
719
733
  /** Load content from URL(s) or search query */
720
734
  load(input: string | string[], options?: LoadOptions): Promise<LoadResult>;
package/dist/index.d.ts CHANGED
@@ -165,8 +165,8 @@ declare class RealtimeSSEClient extends TypedEmitter {
165
165
  type Environment = 'production' | 'testing';
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. */
@@ -179,7 +179,7 @@ interface PrismerConfig {
179
179
  imAgent?: string;
180
180
  }
181
181
  interface LoadOptions {
182
- inputType?: 'url' | 'urls' | 'query';
182
+ inputType?: 'auto' | 'url' | 'urls' | 'query';
183
183
  processUncached?: boolean;
184
184
  search?: {
185
185
  topK?: number;
@@ -392,6 +392,8 @@ interface IMMeData {
392
392
  agentCard?: IMAgentCard;
393
393
  stats: {
394
394
  conversationCount: number;
395
+ directCount?: number;
396
+ groupCount?: number;
395
397
  contactCount: number;
396
398
  messagesSent: number;
397
399
  unreadCount: number;
@@ -412,11 +414,15 @@ interface IMTokenData {
412
414
  }
413
415
  interface IMMessage {
414
416
  id: string;
417
+ conversationId?: string;
415
418
  content: string;
416
419
  type: string;
417
420
  senderId: string;
421
+ parentId?: string | null;
422
+ status?: string;
418
423
  createdAt: string;
419
- metadata?: Record<string, any>;
424
+ updatedAt?: string;
425
+ metadata?: Record<string, any> | string;
420
426
  }
421
427
  interface IMRouting {
422
428
  mode: string;
@@ -433,6 +439,7 @@ interface IMMessageData {
433
439
  interface IMGroupMember {
434
440
  userId: string;
435
441
  username: string;
442
+ displayName?: string;
436
443
  role: string;
437
444
  }
438
445
  interface IMGroupData {
@@ -504,7 +511,8 @@ interface IMAutocompleteResult {
504
511
  interface IMCreateGroupOptions {
505
512
  title: string;
506
513
  description?: string;
507
- members: string[];
514
+ members?: string[];
515
+ metadata?: Record<string, any>;
508
516
  }
509
517
  interface IMCreateBindingOptions {
510
518
  platform: 'telegram' | 'discord' | 'slack' | 'wechat' | 'x' | 'line';
@@ -513,8 +521,9 @@ interface IMCreateBindingOptions {
513
521
  channelId?: string;
514
522
  }
515
523
  interface IMSendOptions {
516
- type?: 'text' | 'markdown' | 'code' | 'system_event';
524
+ type?: 'text' | 'markdown' | 'code' | 'image' | 'file' | 'tool_call' | 'tool_result' | 'system_event' | 'thinking';
517
525
  metadata?: Record<string, any>;
526
+ parentId?: string;
518
527
  }
519
528
  interface IMPaginationOptions {
520
529
  limit?: number;
@@ -707,14 +716,19 @@ declare class IMClient {
707
716
  health(): Promise<IMResult<void>>;
708
717
  }
709
718
  declare class PrismerClient {
710
- private readonly apiKey;
719
+ private apiKey;
711
720
  private readonly baseUrl;
712
721
  private readonly timeout;
713
722
  private readonly fetchFn;
714
723
  private readonly imAgent?;
715
724
  /** IM API sub-client */
716
725
  readonly im: IMClient;
717
- 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;
718
732
  private _request;
719
733
  /** Load content from URL(s) or search query */
720
734
  load(input: string | string[], options?: LoadOptions): Promise<LoadResult>;
package/dist/index.js CHANGED
@@ -500,7 +500,8 @@ var DirectClient = class {
500
500
  return this._r("POST", `/api/im/direct/${userId}/messages`, {
501
501
  content,
502
502
  type: options?.type ?? "text",
503
- metadata: options?.metadata
503
+ metadata: options?.metadata,
504
+ parentId: options?.parentId
504
505
  });
505
506
  }
506
507
  /** Get direct message history with a user */
@@ -532,7 +533,8 @@ var GroupsClient = class {
532
533
  return this._r("POST", `/api/im/groups/${groupId}/messages`, {
533
534
  content,
534
535
  type: options?.type ?? "text",
535
- metadata: options?.metadata
536
+ metadata: options?.metadata,
537
+ parentId: options?.parentId
536
538
  });
537
539
  }
538
540
  /** Get group message history */
@@ -584,7 +586,8 @@ var MessagesClient = class {
584
586
  return this._r("POST", `/api/im/messages/${conversationId}`, {
585
587
  content,
586
588
  type: options?.type ?? "text",
587
- metadata: options?.metadata
589
+ metadata: options?.metadata,
590
+ parentId: options?.parentId
588
591
  });
589
592
  }
590
593
  /** Get message history for a conversation */
@@ -724,14 +727,11 @@ var IMClient = class {
724
727
  }
725
728
  };
726
729
  var PrismerClient = class {
727
- constructor(config) {
728
- if (!config.apiKey) {
729
- throw new Error("apiKey is required");
730
- }
731
- if (!config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
730
+ constructor(config = {}) {
731
+ if (config.apiKey && !config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
732
732
  console.warn('Warning: API key should start with "sk-prismer-" (or "eyJ" for IM JWT)');
733
733
  }
734
- this.apiKey = config.apiKey;
734
+ this.apiKey = config.apiKey || "";
735
735
  const envUrl = ENVIRONMENTS[config.environment || "production"];
736
736
  this.baseUrl = (config.baseUrl || envUrl).replace(/\/$/, "");
737
737
  this.timeout = config.timeout || 3e4;
@@ -742,6 +742,13 @@ var PrismerClient = class {
742
742
  this.baseUrl
743
743
  );
744
744
  }
745
+ /**
746
+ * Set or update the auth token (API key or IM JWT).
747
+ * Useful after anonymous registration to set the returned JWT.
748
+ */
749
+ setToken(token) {
750
+ this.apiKey = token;
751
+ }
745
752
  // --------------------------------------------------------------------------
746
753
  // Internal request helper
747
754
  // --------------------------------------------------------------------------
@@ -753,9 +760,10 @@ var PrismerClient = class {
753
760
  if (query && Object.keys(query).length > 0) {
754
761
  url += "?" + new URLSearchParams(query).toString();
755
762
  }
756
- const headers = {
757
- "Authorization": `Bearer ${this.apiKey}`
758
- };
763
+ const headers = {};
764
+ if (this.apiKey) {
765
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
766
+ }
759
767
  if (this.imAgent) {
760
768
  headers["X-IM-Agent"] = this.imAgent;
761
769
  }
package/dist/index.mjs CHANGED
@@ -458,7 +458,8 @@ var DirectClient = class {
458
458
  return this._r("POST", `/api/im/direct/${userId}/messages`, {
459
459
  content,
460
460
  type: options?.type ?? "text",
461
- metadata: options?.metadata
461
+ metadata: options?.metadata,
462
+ parentId: options?.parentId
462
463
  });
463
464
  }
464
465
  /** Get direct message history with a user */
@@ -490,7 +491,8 @@ var GroupsClient = class {
490
491
  return this._r("POST", `/api/im/groups/${groupId}/messages`, {
491
492
  content,
492
493
  type: options?.type ?? "text",
493
- metadata: options?.metadata
494
+ metadata: options?.metadata,
495
+ parentId: options?.parentId
494
496
  });
495
497
  }
496
498
  /** Get group message history */
@@ -542,7 +544,8 @@ var MessagesClient = class {
542
544
  return this._r("POST", `/api/im/messages/${conversationId}`, {
543
545
  content,
544
546
  type: options?.type ?? "text",
545
- metadata: options?.metadata
547
+ metadata: options?.metadata,
548
+ parentId: options?.parentId
546
549
  });
547
550
  }
548
551
  /** Get message history for a conversation */
@@ -682,14 +685,11 @@ var IMClient = class {
682
685
  }
683
686
  };
684
687
  var PrismerClient = class {
685
- constructor(config) {
686
- if (!config.apiKey) {
687
- throw new Error("apiKey is required");
688
- }
689
- if (!config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
688
+ constructor(config = {}) {
689
+ if (config.apiKey && !config.apiKey.startsWith("sk-prismer-") && !config.apiKey.startsWith("eyJ")) {
690
690
  console.warn('Warning: API key should start with "sk-prismer-" (or "eyJ" for IM JWT)');
691
691
  }
692
- this.apiKey = config.apiKey;
692
+ this.apiKey = config.apiKey || "";
693
693
  const envUrl = ENVIRONMENTS[config.environment || "production"];
694
694
  this.baseUrl = (config.baseUrl || envUrl).replace(/\/$/, "");
695
695
  this.timeout = config.timeout || 3e4;
@@ -700,6 +700,13 @@ var PrismerClient = class {
700
700
  this.baseUrl
701
701
  );
702
702
  }
703
+ /**
704
+ * Set or update the auth token (API key or IM JWT).
705
+ * Useful after anonymous registration to set the returned JWT.
706
+ */
707
+ setToken(token) {
708
+ this.apiKey = token;
709
+ }
703
710
  // --------------------------------------------------------------------------
704
711
  // Internal request helper
705
712
  // --------------------------------------------------------------------------
@@ -711,9 +718,10 @@ var PrismerClient = class {
711
718
  if (query && Object.keys(query).length > 0) {
712
719
  url += "?" + new URLSearchParams(query).toString();
713
720
  }
714
- const headers = {
715
- "Authorization": `Bearer ${this.apiKey}`
716
- };
721
+ const headers = {};
722
+ if (this.apiKey) {
723
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
724
+ }
717
725
  if (this.imAgent) {
718
726
  headers["X-IM-Agent"] = this.imAgent;
719
727
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismer/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Official TypeScript SDK for Prismer Cloud API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",