@redplanethq/sdk 0.1.10 → 0.1.12

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/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var commander = require('commander');
4
+ var zod = require('zod');
5
+ var crypto = require('crypto');
4
6
 
5
7
  var __defProp = Object.defineProperty;
6
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -85,6 +87,7 @@ var EPISODIC_NODE_PROPERTIES = `{
85
87
  metadata: e.metadata,
86
88
  createdAt: e.createdAt,
87
89
  userId: e.userId,
90
+ workspaceId: e.workspaceId,
88
91
  sessionId: e.sessionId,
89
92
  queueId: e.queueId,
90
93
  labelIds: e.labelIds,
@@ -103,18 +106,22 @@ var STATEMENT_NODE_PROPERTIES = `{
103
106
  fact: s.fact,
104
107
  createdAt: s.createdAt,
105
108
  userId: s.userId,
109
+ workspaceId: s.workspaceId,
106
110
  validAt: s.validAt,
107
111
  invalidAt: s.invalidAt,
108
112
  invalidatedBy: s.invalidatedBy,
109
113
  attributes: s.attributes,
114
+ aspect: s.aspect,
110
115
  recallCount: s.recallCount,
111
116
  provenanceCount: s.provenanceCount
112
117
  }`;
113
118
  var ENTITY_NODE_PROPERTIES = `{
114
119
  uuid: ent.uuid,
115
120
  name: ent.name,
121
+ type: ent.type,
116
122
  createdAt: ent.createdAt,
117
123
  userId: ent.userId,
124
+ workspaceId: ent.workspaceId,
118
125
  attributes: ent.attributes
119
126
  }`;
120
127
  var COMPACTED_SESSION_NODE_PROPERTIES = `{
@@ -128,10 +135,37 @@ var COMPACTED_SESSION_NODE_PROPERTIES = `{
128
135
  updatedAt: cs.updatedAt,
129
136
  confidence: cs.confidence,
130
137
  userId: cs.userId,
138
+ workspaceId: cs.workspaceId,
131
139
  source: cs.source,
132
140
  compressionRatio: cs.compressionRatio,
133
141
  metadata: cs.metadata
134
142
  }`;
143
+ var EntityTypes = [
144
+ "Person",
145
+ "Organization",
146
+ "Place",
147
+ "Event",
148
+ "Project",
149
+ "Task",
150
+ "Technology",
151
+ "Product",
152
+ "Standard",
153
+ "Concept",
154
+ "Predicate"
155
+ ];
156
+ var StatementAspects = [
157
+ "Identity",
158
+ "Knowledge",
159
+ "Belief",
160
+ "Preference",
161
+ "Habit",
162
+ "Goal",
163
+ "Directive",
164
+ "Decision",
165
+ "Event",
166
+ "Problem",
167
+ "Relationship"
168
+ ];
135
169
  exports.EpisodeTypeEnum = void 0;
136
170
  (function(EpisodeTypeEnum2) {
137
171
  EpisodeTypeEnum2["CONVERSATION"] = "CONVERSATION";
@@ -168,11 +202,6 @@ var OAuth2Params = class {
168
202
  __name(this, "OAuth2Params");
169
203
  }
170
204
  };
171
- var APIKeyParams = class {
172
- static {
173
- __name(this, "APIKeyParams");
174
- }
175
- };
176
205
 
177
206
  // ../types/dist/integration.js
178
207
  exports.IntegrationEventType = void 0;
@@ -399,24 +428,421 @@ var IntegrationCLI = class {
399
428
  return this.program;
400
429
  }
401
430
  };
431
+ var IngestInputSchema = zod.z.object({
432
+ episodeBody: zod.z.string(),
433
+ referenceTime: zod.z.string(),
434
+ metadata: zod.z.record(zod.z.union([
435
+ zod.z.string(),
436
+ zod.z.number(),
437
+ zod.z.boolean()
438
+ ])).optional(),
439
+ source: zod.z.string(),
440
+ labelIds: zod.z.array(zod.z.string()).optional(),
441
+ sessionId: zod.z.string().optional(),
442
+ type: zod.z.enum([
443
+ "CONVERSATION",
444
+ "DOCUMENT"
445
+ ]).default("CONVERSATION"),
446
+ title: zod.z.string().optional()
447
+ });
448
+ var IngestResponseSchema = zod.z.object({
449
+ success: zod.z.boolean(),
450
+ id: zod.z.string()
451
+ });
452
+ var SearchInputSchema = zod.z.object({
453
+ query: zod.z.string(),
454
+ startTime: zod.z.string().optional(),
455
+ endTime: zod.z.string().optional(),
456
+ labelIds: zod.z.array(zod.z.string()).optional(),
457
+ limit: zod.z.number().optional(),
458
+ structured: zod.z.boolean().optional(),
459
+ sortBy: zod.z.enum([
460
+ "relevance",
461
+ "recency"
462
+ ]).optional()
463
+ });
464
+ var SearchResponseSchema = zod.z.record(zod.z.unknown());
465
+ var MeResponseSchema = zod.z.object({
466
+ id: zod.z.string(),
467
+ name: zod.z.string().nullable().optional(),
468
+ persona: zod.z.string().nullable().optional(),
469
+ workspaceId: zod.z.string().nullable().optional(),
470
+ phoneNumber: zod.z.string().nullable().optional(),
471
+ email: zod.z.string().nullable().optional(),
472
+ timezone: zod.z.string().nullable().optional(),
473
+ metadata: zod.z.record(zod.z.unknown()).nullable().optional()
474
+ });
475
+ var IntegrationAccountSchema = zod.z.object({
476
+ id: zod.z.string(),
477
+ name: zod.z.string().optional(),
478
+ slug: zod.z.string().optional()
479
+ }).passthrough();
480
+ var GetIntegrationsConnectedResponseSchema = zod.z.object({
481
+ accounts: zod.z.array(IntegrationAccountSchema)
482
+ });
483
+ var GetIntegrationActionsInputSchema = zod.z.object({
484
+ accountId: zod.z.string(),
485
+ query: zod.z.string().optional()
486
+ });
487
+ var GetIntegrationActionsResponseSchema = zod.z.object({
488
+ actions: zod.z.array(zod.z.unknown())
489
+ });
490
+ var ExecuteIntegrationActionInputSchema = zod.z.object({
491
+ accountId: zod.z.string(),
492
+ action: zod.z.string(),
493
+ parameters: zod.z.record(zod.z.unknown()).optional()
494
+ });
495
+ var ExecuteIntegrationActionResponseSchema = zod.z.object({
496
+ result: zod.z.unknown()
497
+ });
498
+ var GetDocumentsInputSchema = zod.z.object({
499
+ page: zod.z.number().optional(),
500
+ limit: zod.z.number().optional(),
501
+ source: zod.z.string().optional(),
502
+ status: zod.z.string().optional(),
503
+ type: zod.z.string().optional(),
504
+ sessionId: zod.z.string().optional(),
505
+ label: zod.z.string().optional(),
506
+ cursor: zod.z.string().optional()
507
+ });
508
+ var DocumentSchema = zod.z.object({
509
+ id: zod.z.string(),
510
+ title: zod.z.string().nullable().optional(),
511
+ createdAt: zod.z.string().optional(),
512
+ sessionId: zod.z.string().nullable().optional(),
513
+ source: zod.z.string().nullable().optional()
514
+ }).passthrough();
515
+ var GetDocumentsResponseSchema = zod.z.object({
516
+ documents: zod.z.array(DocumentSchema),
517
+ page: zod.z.number(),
518
+ limit: zod.z.number(),
519
+ hasMore: zod.z.boolean(),
520
+ nextCursor: zod.z.string().nullable(),
521
+ availableSources: zod.z.array(zod.z.object({
522
+ name: zod.z.string(),
523
+ slug: zod.z.string()
524
+ })),
525
+ totalCount: zod.z.number()
526
+ });
527
+ var GetDocumentInputSchema = zod.z.object({
528
+ documentId: zod.z.string()
529
+ });
530
+ var GetDocumentResponseSchema = zod.z.object({
531
+ document: DocumentSchema.nullable()
532
+ });
533
+ var GatewayAgentInfoSchema = zod.z.object({
534
+ id: zod.z.string(),
535
+ name: zod.z.string(),
536
+ description: zod.z.string(),
537
+ tools: zod.z.array(zod.z.string()),
538
+ platform: zod.z.string().nullable(),
539
+ hostname: zod.z.string().nullable(),
540
+ status: zod.z.enum([
541
+ "CONNECTED",
542
+ "DISCONNECTED"
543
+ ])
544
+ });
545
+ var GetGatewaysResponseSchema = zod.z.object({
546
+ gateways: zod.z.array(GatewayAgentInfoSchema)
547
+ });
548
+ var ExecuteGatewayInputSchema = zod.z.object({
549
+ gatewayId: zod.z.string(),
550
+ intent: zod.z.string()
551
+ });
552
+ var ExecuteGatewayToolInputSchema = zod.z.object({
553
+ gatewayId: zod.z.string(),
554
+ toolName: zod.z.string(),
555
+ params: zod.z.record(zod.z.unknown())
556
+ });
557
+ var ExecuteGatewayResponseSchema = zod.z.object({
558
+ result: zod.z.unknown()
559
+ });
560
+ var AuthorizationCodeResponseSchema = zod.z.object({
561
+ authorizationCode: zod.z.string(),
562
+ url: zod.z.string()
563
+ });
564
+ var TokenExchangeInputSchema = zod.z.object({
565
+ authorizationCode: zod.z.string()
566
+ });
567
+ var TokenExchangeResponseSchema = zod.z.object({
568
+ token: zod.z.object({
569
+ token: zod.z.string(),
570
+ obfuscatedToken: zod.z.string()
571
+ }).nullable()
572
+ });
573
+ var CoreClientError = class extends Error {
574
+ static {
575
+ __name(this, "CoreClientError");
576
+ }
577
+ statusCode;
578
+ constructor(message, statusCode) {
579
+ super(message);
580
+ this.name = "CoreClientError";
581
+ this.statusCode = statusCode;
582
+ }
583
+ };
584
+ var CoreClient = class {
585
+ static {
586
+ __name(this, "CoreClient");
587
+ }
588
+ baseUrl;
589
+ token;
590
+ constructor(options) {
591
+ this.baseUrl = options.baseUrl.replace(/\/+$/, "");
592
+ this.token = options.token;
593
+ }
594
+ async request(method, path, options) {
595
+ let url = `${this.baseUrl}${path}`;
596
+ if (options?.searchParams) {
597
+ const params = new URLSearchParams(options.searchParams);
598
+ const query = params.toString();
599
+ if (query) url += `?${query}`;
600
+ }
601
+ const response = await fetch(url, {
602
+ method,
603
+ headers: {
604
+ "Content-Type": "application/json",
605
+ Authorization: `Bearer ${this.token}`
606
+ },
607
+ ...options?.body ? {
608
+ body: JSON.stringify(options.body)
609
+ } : {}
610
+ });
611
+ if (!response.ok) {
612
+ let errorMessage;
613
+ try {
614
+ const errorBody = await response.json();
615
+ errorMessage = errorBody.error || JSON.stringify(errorBody);
616
+ } catch {
617
+ errorMessage = await response.text();
618
+ }
619
+ throw new CoreClientError(errorMessage, response.status);
620
+ }
621
+ return response.json();
622
+ }
623
+ /**
624
+ * Send a request without an Authorization header.
625
+ * Used for public endpoints like authorization-code and token exchange.
626
+ */
627
+ async requestPublic(method, path, options) {
628
+ const url = `${this.baseUrl}${path}`;
629
+ const response = await fetch(url, {
630
+ method,
631
+ headers: {
632
+ "Content-Type": "application/json"
633
+ },
634
+ ...options?.body ? {
635
+ body: JSON.stringify(options.body)
636
+ } : {}
637
+ });
638
+ if (!response.ok) {
639
+ let errorMessage;
640
+ try {
641
+ const errorBody = await response.json();
642
+ errorMessage = errorBody.error || JSON.stringify(errorBody);
643
+ } catch {
644
+ errorMessage = await response.text();
645
+ }
646
+ throw new CoreClientError(errorMessage, response.status);
647
+ }
648
+ return response.json();
649
+ }
650
+ /**
651
+ * Get the authenticated user's profile info.
652
+ * GET /api/v1/me
653
+ */
654
+ async me() {
655
+ return this.request("GET", "/api/v1/me");
656
+ }
657
+ /**
658
+ * Store a conversation or document in memory.
659
+ * POST /api/v1/add
660
+ */
661
+ async ingest(body) {
662
+ return this.request("POST", "/api/v1/add", {
663
+ body
664
+ });
665
+ }
666
+ /**
667
+ * Search memory with a query and optional filters.
668
+ * POST /api/v1/search
669
+ */
670
+ async search(body) {
671
+ return this.request("POST", "/api/v1/search", {
672
+ body
673
+ });
674
+ }
675
+ /**
676
+ * List all connected integration accounts for the workspace.
677
+ * GET /api/v1/integration_account
678
+ */
679
+ async getIntegrationsConnected() {
680
+ return this.request("GET", "/api/v1/integration_account");
681
+ }
682
+ /**
683
+ * Get relevant actions for a specific integration account.
684
+ * GET /api/v1/integration_account/:accountId/action?query=...
685
+ */
686
+ async getIntegrationActions(params) {
687
+ const searchParams = {};
688
+ if (params.query) searchParams.query = params.query;
689
+ return this.request("GET", `/api/v1/integration_account/${params.accountId}/action`, {
690
+ searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
691
+ });
692
+ }
693
+ /**
694
+ * Execute an action on an integration account.
695
+ * POST /api/v1/integration_account/:accountId/action
696
+ */
697
+ async executeIntegrationAction(params) {
698
+ const { accountId, ...body } = params;
699
+ return this.request("POST", `/api/v1/integration_account/${accountId}/action`, {
700
+ body
701
+ });
702
+ }
703
+ /**
704
+ * Generate a new session UUID for conversation tracking.
705
+ * Local operation — no API call.
706
+ */
707
+ async getSessionId() {
708
+ return crypto.randomUUID();
709
+ }
710
+ /**
711
+ * List documents with optional filtering and pagination.
712
+ * GET /api/v1/documents
713
+ */
714
+ async getDocuments(params) {
715
+ const searchParams = {};
716
+ if (params) {
717
+ if (params.page != null) searchParams.page = String(params.page);
718
+ if (params.limit != null) searchParams.limit = String(params.limit);
719
+ if (params.source) searchParams.source = params.source;
720
+ if (params.status) searchParams.status = params.status;
721
+ if (params.type) searchParams.type = params.type;
722
+ if (params.sessionId) searchParams.sessionId = params.sessionId;
723
+ if (params.label) searchParams.label = params.label;
724
+ if (params.cursor) searchParams.cursor = params.cursor;
725
+ }
726
+ return this.request("GET", "/api/v1/documents", {
727
+ searchParams: Object.keys(searchParams).length > 0 ? searchParams : void 0
728
+ });
729
+ }
730
+ /**
731
+ * Get a single document by ID.
732
+ * GET /api/v1/documents/:documentId
733
+ */
734
+ async getDocument(params) {
735
+ return this.request("GET", `/api/v1/documents/${params.documentId}`);
736
+ }
737
+ /**
738
+ * List all connected gateways for the workspace.
739
+ * GET /api/v1/gateways
740
+ */
741
+ async getGateways() {
742
+ return this.request("GET", "/api/v1/gateways");
743
+ }
744
+ /**
745
+ * Run a gateway sub-agent with an intent and return the final text result.
746
+ * POST /api/v1/gateways/:gatewayId/execute
747
+ */
748
+ async executeGateway(params) {
749
+ return this.request("POST", `/api/v1/gateways/${params.gatewayId}/execute`, {
750
+ body: {
751
+ intent: params.intent
752
+ }
753
+ });
754
+ }
755
+ /**
756
+ * Proxy a single tool call to a gateway via server websocket.
757
+ * POST /api/v1/gateways/:gatewayId/execute (mode: "tool")
758
+ */
759
+ async executeGatewayTool(params) {
760
+ return this.request("POST", `/api/v1/gateways/${params.gatewayId}/execute`, {
761
+ body: {
762
+ mode: "tool",
763
+ toolName: params.toolName,
764
+ params: params.params
765
+ }
766
+ });
767
+ }
768
+ // -------------------------------------------------------------------------
769
+ // Auth – Device-style login flow (public endpoints, no token required)
770
+ // -------------------------------------------------------------------------
771
+ /**
772
+ * Request a fresh authorization code.
773
+ * POST /api/v1/authorization-code (unauthenticated)
774
+ *
775
+ * The returned `url` is the page the user must visit to authorize the CLI.
776
+ */
777
+ async getAuthorizationCode() {
778
+ return this.requestPublic("POST", "/api/v1/authorization-code");
779
+ }
780
+ /**
781
+ * Exchange an authorization code for a personal access token.
782
+ * POST /api/v1/token (unauthenticated)
783
+ *
784
+ * Returns `{ token: null }` while the user has not yet completed
785
+ * the browser authorization step. Poll until `token` is non-null.
786
+ */
787
+ async exchangeToken(params) {
788
+ return this.requestPublic("POST", "/api/v1/token", {
789
+ body: params
790
+ });
791
+ }
792
+ /**
793
+ * Verify that the current token is valid by calling /api/v1/me.
794
+ * Returns the user profile on success, or throws CoreClientError on failure.
795
+ * Useful as a health-check before launching other operations.
796
+ */
797
+ async checkAuth() {
798
+ return this.me();
799
+ }
800
+ };
402
801
 
403
- exports.APIKeyParams = APIKeyParams;
404
802
  exports.ActionStatus = ActionStatus;
803
+ exports.AuthorizationCodeResponseSchema = AuthorizationCodeResponseSchema;
405
804
  exports.COMPACTED_SESSION_NODE_PROPERTIES = COMPACTED_SESSION_NODE_PROPERTIES;
406
805
  exports.ClaudeModels = ClaudeModels;
806
+ exports.CoreClient = CoreClient;
807
+ exports.CoreClientError = CoreClientError;
808
+ exports.DocumentSchema = DocumentSchema;
407
809
  exports.ENTITY_NODE_PROPERTIES = ENTITY_NODE_PROPERTIES;
408
810
  exports.EPISODIC_NODE_PROPERTIES = EPISODIC_NODE_PROPERTIES;
409
811
  exports.EXPLICIT_PATTERN_TYPES = EXPLICIT_PATTERN_TYPES;
812
+ exports.EntityTypes = EntityTypes;
410
813
  exports.EpisodeType = EpisodeType;
814
+ exports.ExecuteGatewayInputSchema = ExecuteGatewayInputSchema;
815
+ exports.ExecuteGatewayResponseSchema = ExecuteGatewayResponseSchema;
816
+ exports.ExecuteGatewayToolInputSchema = ExecuteGatewayToolInputSchema;
817
+ exports.ExecuteIntegrationActionInputSchema = ExecuteIntegrationActionInputSchema;
818
+ exports.ExecuteIntegrationActionResponseSchema = ExecuteIntegrationActionResponseSchema;
819
+ exports.GatewayAgentInfoSchema = GatewayAgentInfoSchema;
411
820
  exports.GeminiModels = GeminiModels;
821
+ exports.GetDocumentInputSchema = GetDocumentInputSchema;
822
+ exports.GetDocumentResponseSchema = GetDocumentResponseSchema;
823
+ exports.GetDocumentsInputSchema = GetDocumentsInputSchema;
824
+ exports.GetDocumentsResponseSchema = GetDocumentsResponseSchema;
825
+ exports.GetGatewaysResponseSchema = GetGatewaysResponseSchema;
826
+ exports.GetIntegrationActionsInputSchema = GetIntegrationActionsInputSchema;
827
+ exports.GetIntegrationActionsResponseSchema = GetIntegrationActionsResponseSchema;
828
+ exports.GetIntegrationsConnectedResponseSchema = GetIntegrationsConnectedResponseSchema;
412
829
  exports.IMPLICIT_PATTERN_TYPES = IMPLICIT_PATTERN_TYPES;
830
+ exports.IngestInputSchema = IngestInputSchema;
831
+ exports.IngestResponseSchema = IngestResponseSchema;
832
+ exports.IntegrationAccountSchema = IntegrationAccountSchema;
413
833
  exports.IntegrationCLI = IntegrationCLI;
414
834
  exports.LLMModelType = LLMModelType;
835
+ exports.MeResponseSchema = MeResponseSchema;
415
836
  exports.OAuth2Params = OAuth2Params;
416
837
  exports.OpenAIModels = OpenAIModels;
417
838
  exports.PATTERN_TYPES = PATTERN_TYPES;
418
839
  exports.QUALITY_THRESHOLDS = QUALITY_THRESHOLDS;
419
840
  exports.STATEMENT_NODE_PROPERTIES = STATEMENT_NODE_PROPERTIES;
841
+ exports.SearchInputSchema = SearchInputSchema;
842
+ exports.SearchResponseSchema = SearchResponseSchema;
420
843
  exports.Spec = Spec;
844
+ exports.StatementAspects = StatementAspects;
845
+ exports.TokenExchangeInputSchema = TokenExchangeInputSchema;
846
+ exports.TokenExchangeResponseSchema = TokenExchangeResponseSchema;
421
847
  //# sourceMappingURL=index.js.map
422
848
  //# sourceMappingURL=index.js.map