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