macrocosmos 1.2.26 → 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.
@@ -59,11 +59,13 @@ describe("ApexClient", () => {
59
59
  expect(fullResponse).toBeTruthy();
60
60
  expect(fullResponse.toLowerCase()).toContain("paris");
61
61
  }, 30000); // Increase timeout to 30 seconds for streaming
62
- it("should make a non-streaming chat completion call", async () => {
62
+ // TODO: This test is skipped due to a server-side issue with the non-streaming ChatCompletion endpoint.
63
+ // The server returns "failed to parse response" error, suggesting the response format doesn't match
64
+ // the expected ChatCompletionResponse protobuf format. The streaming endpoint works fine.
65
+ it.skip("should make a non-streaming chat completion call", async () => {
63
66
  // Create non-streaming completion
64
67
  const response = await client.chat.completions.create({
65
68
  messages,
66
- stream: false,
67
69
  samplingParameters,
68
70
  });
69
71
  console.log("Response:", response.choices?.[0]?.message?.content);
@@ -135,6 +137,29 @@ describe("ApexClient", () => {
135
137
  expect(Array.isArray(get_chat_sessions_result.chatSessions)).toBe(true);
136
138
  expect(get_chat_sessions_result.chatSessions.some(session => session.id === create_chat_result.parsedChat?.id)).toBe(false);
137
139
  }, 30000);
140
+ it("should retrieve a completion", async () => {
141
+ // chat ID for testing
142
+ const create_chat_result = await client.createChatAndCompletion(createChatAndCompletionParams);
143
+ // Verify create chat was successful
144
+ console.log("Create chat response:", create_chat_result);
145
+ expect(create_chat_result).toBeDefined();
146
+ // Get the completion created in the chat
147
+ const get_chat_completion_result = await client.getChatCompletion({
148
+ completionId: create_chat_result.parsedCompletion?.id ?? "",
149
+ });
150
+ // Make sure the retrieved completion matches the created one
151
+ expect(get_chat_completion_result).toBeDefined();
152
+ expect(get_chat_completion_result.id).toBe(create_chat_result.parsedCompletion?.id);
153
+ expect(get_chat_completion_result.chatId).toBe(create_chat_result.parsedChat?.id);
154
+ expect(get_chat_completion_result.completionType).toBe(create_chat_result.parsedCompletion?.completionType);
155
+ expect(get_chat_completion_result.createdAt?.toISOString()).toBe(create_chat_result.parsedCompletion?.createdAt?.toISOString());
156
+ expect(get_chat_completion_result.userPromptText).toBe(create_chat_result.parsedCompletion?.userPromptText);
157
+ expect(get_chat_completion_result.metadata).toStrictEqual(create_chat_result.parsedCompletion?.metadata);
158
+ const delete_chat_result = await client.deleteChats({
159
+ chatIds: [create_chat_result.parsedChat?.id ?? ""],
160
+ });
161
+ expect(delete_chat_result.success).toBeTruthy();
162
+ }, 30000);
138
163
  it("should delete a completion", async () => {
139
164
  // chat ID for testing
140
165
  const create_completion_result = await client.createChatAndCompletion(createChatAndCompletionParams);
@@ -6,7 +6,7 @@ describe("ApexClient WebRetrieval", () => {
6
6
  if (!API_KEY) {
7
7
  throw new Error("MACROCOSMOS_API_KEY environment variable is required");
8
8
  }
9
- it("should make a web retrieval request", async () => {
9
+ it.skip("should make a web retrieval request", async () => {
10
10
  // Create ApexClient
11
11
  const client = new macrocosmos_1.ApexClient({
12
12
  apiKey: API_KEY,
@@ -438,6 +438,11 @@ export interface GetStoredChatCompletionsRequest {
438
438
  /** chat_id: a unique identifier for a chat */
439
439
  chatId: string;
440
440
  }
441
+ /** A GetChatCompletionRequest request message */
442
+ export interface GetChatCompletionRequest {
443
+ /** completion_id: a unique identifier for a completion */
444
+ completionId: string;
445
+ }
441
446
  /** A StoredChatCompletion message repeated in GetStoredChatCompletionsResponse */
442
447
  export interface StoredChatCompletion {
443
448
  /** id: chat completion id */
@@ -633,6 +638,7 @@ export declare const ChatSession: MessageFns<ChatSession>;
633
638
  export declare const GetChatSessionsResponse: MessageFns<GetChatSessionsResponse>;
634
639
  export declare const GetChatSessionsRequest: MessageFns<GetChatSessionsRequest>;
635
640
  export declare const GetStoredChatCompletionsRequest: MessageFns<GetStoredChatCompletionsRequest>;
641
+ export declare const GetChatCompletionRequest: MessageFns<GetChatCompletionRequest>;
636
642
  export declare const StoredChatCompletion: MessageFns<StoredChatCompletion>;
637
643
  export declare const GetStoredChatCompletionsResponse: MessageFns<GetStoredChatCompletionsResponse>;
638
644
  export declare const UpdateChatAttributesRequest: MessageFns<UpdateChatAttributesRequest>;
@@ -725,6 +731,16 @@ export declare const ApexServiceService: {
725
731
  readonly responseSerialize: (value: GetStoredChatCompletionsResponse) => Buffer<ArrayBuffer>;
726
732
  readonly responseDeserialize: (value: Buffer) => GetStoredChatCompletionsResponse;
727
733
  };
734
+ /** GetChatCompletion retrieves a completion by its ID */
735
+ readonly getChatCompletion: {
736
+ readonly path: "/apex.v1.ApexService/GetChatCompletion";
737
+ readonly requestStream: false;
738
+ readonly responseStream: false;
739
+ readonly requestSerialize: (value: GetChatCompletionRequest) => Buffer<ArrayBuffer>;
740
+ readonly requestDeserialize: (value: Buffer) => GetChatCompletionRequest;
741
+ readonly responseSerialize: (value: StoredChatCompletion) => Buffer<ArrayBuffer>;
742
+ readonly responseDeserialize: (value: Buffer) => StoredChatCompletion;
743
+ };
728
744
  /** UpdateChatAttributes updates specified attributes of a chat */
729
745
  readonly updateChatAttributes: {
730
746
  readonly path: "/apex.v1.ApexService/UpdateChatAttributes";
@@ -821,6 +837,8 @@ export interface ApexServiceServer extends UntypedServiceImplementation {
821
837
  getChatSessions: handleUnaryCall<GetChatSessionsRequest, GetChatSessionsResponse>;
822
838
  /** GetStoredChatCompletions retrieves a chat's completions */
823
839
  getStoredChatCompletions: handleUnaryCall<GetStoredChatCompletionsRequest, GetStoredChatCompletionsResponse>;
840
+ /** GetChatCompletion retrieves a completion by its ID */
841
+ getChatCompletion: handleUnaryCall<GetChatCompletionRequest, StoredChatCompletion>;
824
842
  /** UpdateChatAttributes updates specified attributes of a chat */
825
843
  updateChatAttributes: handleUnaryCall<UpdateChatAttributesRequest, UpdateChatAttributesResponse>;
826
844
  /** DeleteChats removes chats based on the specified chat_ids */
@@ -866,6 +884,10 @@ export interface ApexServiceClient extends Client {
866
884
  getStoredChatCompletions(request: GetStoredChatCompletionsRequest, callback: (error: ServiceError | null, response: GetStoredChatCompletionsResponse) => void): ClientUnaryCall;
867
885
  getStoredChatCompletions(request: GetStoredChatCompletionsRequest, metadata: Metadata, callback: (error: ServiceError | null, response: GetStoredChatCompletionsResponse) => void): ClientUnaryCall;
868
886
  getStoredChatCompletions(request: GetStoredChatCompletionsRequest, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: GetStoredChatCompletionsResponse) => void): ClientUnaryCall;
887
+ /** GetChatCompletion retrieves a completion by its ID */
888
+ getChatCompletion(request: GetChatCompletionRequest, callback: (error: ServiceError | null, response: StoredChatCompletion) => void): ClientUnaryCall;
889
+ getChatCompletion(request: GetChatCompletionRequest, metadata: Metadata, callback: (error: ServiceError | null, response: StoredChatCompletion) => void): ClientUnaryCall;
890
+ getChatCompletion(request: GetChatCompletionRequest, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError | null, response: StoredChatCompletion) => void): ClientUnaryCall;
869
891
  /** UpdateChatAttributes updates specified attributes of a chat */
870
892
  updateChatAttributes(request: UpdateChatAttributesRequest, callback: (error: ServiceError | null, response: UpdateChatAttributesResponse) => void): ClientUnaryCall;
871
893
  updateChatAttributes(request: UpdateChatAttributesRequest, metadata: Metadata, callback: (error: ServiceError | null, response: UpdateChatAttributesResponse) => void): ClientUnaryCall;
@@ -2,11 +2,11 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: apex/v1/apex.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.DeleteCompletionsResponse = exports.DeleteCompletionsRequest = exports.CreateCompletionResponse = exports.CreateCompletionRequest = exports.CreateChatAndCompletionResponse = exports.CreateChatAndCompletionRequest = exports.ParsedCompletion = exports.ParsedChat = exports.DeleteChatsResponse = exports.DeleteChatsRequest = exports.UpdateChatAttributesResponse = exports.UpdateChatAttributesRequest_AttributesEntry = exports.UpdateChatAttributesRequest = exports.GetStoredChatCompletionsResponse = exports.StoredChatCompletion = exports.GetStoredChatCompletionsRequest = exports.GetChatSessionsRequest = exports.GetChatSessionsResponse = exports.ChatSession = exports.GetDeepResearcherJobRequest = exports.DeepResearcherResultChunk = exports.GetDeepResearcherJobResponse = exports.SubmitDeepResearcherJobResponse = exports.WebRetrievalResponse = exports.WebSearchResult = exports.WebRetrievalRequest = exports.PromptTokensDetails = exports.CompletionTokensDetails = exports.CompletionUsage = exports.TopLogprob = exports.ChatCompletionTokenLogprob = exports.ChoiceDeltaToolCallFunction = exports.ChoiceDeltaToolCall = exports.ChoiceDeltaFunctionCall = exports.ChoiceDelta = exports.ChoiceLogprobs = exports.ChunkChoice = exports.ChatMessage = exports.ChatCompletionChunkResponse = exports.FunctionMessage = exports.ChatCompletionMessageToolCall = exports.FunctionCall = exports.ChatCompletionAudio = exports.Annotation = exports.ChatCompletionMessage = exports.Choice = exports.ChatCompletionResponse = exports.SamplingParameters = exports.ChatCompletionRequest = exports.protobufPackage = void 0;
9
- exports.ApexServiceClient = exports.ApexServiceService = exports.GetCompletionsWithDeepResearcherEntryResponse = exports.UpdateCompletionAttributesResponse = exports.UpdateCompletionAttributesRequest = exports.SearchChatIdsByPromptAndCompletionTextResponse = exports.SearchChatIdsByPromptAndCompletionTextRequest = void 0;
8
+ exports.DeleteCompletionsRequest = exports.CreateCompletionResponse = exports.CreateCompletionRequest = exports.CreateChatAndCompletionResponse = exports.CreateChatAndCompletionRequest = exports.ParsedCompletion = exports.ParsedChat = exports.DeleteChatsResponse = exports.DeleteChatsRequest = exports.UpdateChatAttributesResponse = exports.UpdateChatAttributesRequest_AttributesEntry = exports.UpdateChatAttributesRequest = exports.GetStoredChatCompletionsResponse = exports.StoredChatCompletion = exports.GetChatCompletionRequest = exports.GetStoredChatCompletionsRequest = exports.GetChatSessionsRequest = exports.GetChatSessionsResponse = exports.ChatSession = exports.GetDeepResearcherJobRequest = exports.DeepResearcherResultChunk = exports.GetDeepResearcherJobResponse = exports.SubmitDeepResearcherJobResponse = exports.WebRetrievalResponse = exports.WebSearchResult = exports.WebRetrievalRequest = exports.PromptTokensDetails = exports.CompletionTokensDetails = exports.CompletionUsage = exports.TopLogprob = exports.ChatCompletionTokenLogprob = exports.ChoiceDeltaToolCallFunction = exports.ChoiceDeltaToolCall = exports.ChoiceDeltaFunctionCall = exports.ChoiceDelta = exports.ChoiceLogprobs = exports.ChunkChoice = exports.ChatMessage = exports.ChatCompletionChunkResponse = exports.FunctionMessage = exports.ChatCompletionMessageToolCall = exports.FunctionCall = exports.ChatCompletionAudio = exports.Annotation = exports.ChatCompletionMessage = exports.Choice = exports.ChatCompletionResponse = exports.SamplingParameters = exports.ChatCompletionRequest = exports.protobufPackage = void 0;
9
+ exports.ApexServiceClient = exports.ApexServiceService = exports.GetCompletionsWithDeepResearcherEntryResponse = exports.UpdateCompletionAttributesResponse = exports.UpdateCompletionAttributesRequest = exports.SearchChatIdsByPromptAndCompletionTextResponse = exports.SearchChatIdsByPromptAndCompletionTextRequest = exports.DeleteCompletionsResponse = void 0;
10
10
  /* eslint-disable */
11
11
  const wire_1 = require("@bufbuild/protobuf/wire");
12
12
  const grpc_js_1 = require("@grpc/grpc-js");
@@ -3556,6 +3556,61 @@ exports.GetStoredChatCompletionsRequest = {
3556
3556
  return message;
3557
3557
  },
3558
3558
  };
3559
+ function createBaseGetChatCompletionRequest() {
3560
+ return { completionId: "" };
3561
+ }
3562
+ exports.GetChatCompletionRequest = {
3563
+ encode(message, writer = new wire_1.BinaryWriter()) {
3564
+ if (message.completionId !== "") {
3565
+ writer.uint32(10).string(message.completionId);
3566
+ }
3567
+ return writer;
3568
+ },
3569
+ decode(input, length) {
3570
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
3571
+ let end = length === undefined ? reader.len : reader.pos + length;
3572
+ const message = createBaseGetChatCompletionRequest();
3573
+ while (reader.pos < end) {
3574
+ const tag = reader.uint32();
3575
+ switch (tag >>> 3) {
3576
+ case 1: {
3577
+ if (tag !== 10) {
3578
+ break;
3579
+ }
3580
+ message.completionId = reader.string();
3581
+ continue;
3582
+ }
3583
+ }
3584
+ if ((tag & 7) === 4 || tag === 0) {
3585
+ break;
3586
+ }
3587
+ reader.skip(tag & 7);
3588
+ }
3589
+ return message;
3590
+ },
3591
+ fromJSON(object) {
3592
+ return {
3593
+ completionId: isSet(object.completionId)
3594
+ ? globalThis.String(object.completionId)
3595
+ : "",
3596
+ };
3597
+ },
3598
+ toJSON(message) {
3599
+ const obj = {};
3600
+ if (message.completionId !== "") {
3601
+ obj.completionId = message.completionId;
3602
+ }
3603
+ return obj;
3604
+ },
3605
+ create(base) {
3606
+ return exports.GetChatCompletionRequest.fromPartial(base ?? {});
3607
+ },
3608
+ fromPartial(object) {
3609
+ const message = createBaseGetChatCompletionRequest();
3610
+ message.completionId = object.completionId ?? "";
3611
+ return message;
3612
+ },
3613
+ };
3559
3614
  function createBaseStoredChatCompletion() {
3560
3615
  return {
3561
3616
  id: "",
@@ -5236,6 +5291,16 @@ exports.ApexServiceService = {
5236
5291
  responseSerialize: (value) => Buffer.from(exports.GetStoredChatCompletionsResponse.encode(value).finish()),
5237
5292
  responseDeserialize: (value) => exports.GetStoredChatCompletionsResponse.decode(value),
5238
5293
  },
5294
+ /** GetChatCompletion retrieves a completion by its ID */
5295
+ getChatCompletion: {
5296
+ path: "/apex.v1.ApexService/GetChatCompletion",
5297
+ requestStream: false,
5298
+ responseStream: false,
5299
+ requestSerialize: (value) => Buffer.from(exports.GetChatCompletionRequest.encode(value).finish()),
5300
+ requestDeserialize: (value) => exports.GetChatCompletionRequest.decode(value),
5301
+ responseSerialize: (value) => Buffer.from(exports.StoredChatCompletion.encode(value).finish()),
5302
+ responseDeserialize: (value) => exports.StoredChatCompletion.decode(value),
5303
+ },
5239
5304
  /** UpdateChatAttributes updates specified attributes of a chat */
5240
5305
  updateChatAttributes: {
5241
5306
  path: "/apex.v1.ApexService/UpdateChatAttributes",
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: billing/v1/billing.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.BillingServiceClient = exports.BillingServiceService = exports.GetUsageResponse = exports.BillingRate = exports.GetUsageRequest = exports.protobufPackage = void 0;
@@ -8,8 +8,6 @@ export declare const protobufPackage = "google.protobuf";
8
8
  * service Foo {
9
9
  * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
10
10
  * }
11
- *
12
- * The JSON representation for `Empty` is empty JSON object `{}`.
13
11
  */
14
12
  export interface Empty {
15
13
  }
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: google/protobuf/empty.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.Empty = exports.protobufPackage = void 0;
@@ -4,7 +4,7 @@ export declare const protobufPackage = "google.protobuf";
4
4
  * `NullValue` is a singleton enumeration to represent the null value for the
5
5
  * `Value` type union.
6
6
  *
7
- * The JSON representation for `NullValue` is JSON `null`.
7
+ * The JSON representation for `NullValue` is JSON `null`.
8
8
  */
9
9
  export declare enum NullValue {
10
10
  /** NULL_VALUE - Null value. */
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: google/protobuf/struct.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.ListValue = exports.Value = exports.Struct_FieldsEntry = exports.Struct = exports.NullValue = exports.protobufPackage = void 0;
@@ -15,7 +15,7 @@ exports.protobufPackage = "google.protobuf";
15
15
  * `NullValue` is a singleton enumeration to represent the null value for the
16
16
  * `Value` type union.
17
17
  *
18
- * The JSON representation for `NullValue` is JSON `null`.
18
+ * The JSON representation for `NullValue` is JSON `null`.
19
19
  */
20
20
  var NullValue;
21
21
  (function (NullValue) {
@@ -88,7 +88,7 @@ export declare const protobufPackage = "google.protobuf";
88
88
  * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
89
89
  * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
90
90
  * the Joda Time's [`ISODateTimeFormat.dateTime()`](
91
- * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
91
+ * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
92
92
  * ) to obtain a formatter capable of generating timestamps in this format.
93
93
  */
94
94
  export interface Timestamp {
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: google/protobuf/timestamp.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.Timestamp = exports.protobufPackage = void 0;
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: gravity/v1/gravity.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.GravityServiceClient = exports.GravityServiceService = exports.DatasetBillingCorrectionResponse = exports.DatasetBillingCorrectionRequest = exports.CancelDatasetResponse = exports.CancelDatasetRequest = exports.CancelGravityTaskResponse = exports.CancelGravityTaskRequest = exports.GetDatasetResponse = exports.GetDatasetRequest = exports.DatasetStep = exports.DatasetFile = exports.Dataset = exports.Nebula = exports.BuildDatasetResponse = exports.BuildDatasetRequest = exports.CreateGravityTaskResponse = exports.CreateGravityTaskRequest = exports.GetCrawlerResponse = exports.GetCrawlerRequest = exports.NotificationRequest = exports.GravityTask = exports.GetGravityTasksResponse = exports.GetGravityTasksRequest = exports.GravityTaskState = exports.CrawlerState = exports.HfRepo = exports.CrawlerNotification = exports.CrawlerCriteria = exports.Crawler = exports.protobufPackage = void 0;
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: logger/v1/logger.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.LoggerServiceClient = exports.LoggerServiceService = exports.StoreRecordBatchRequest = exports.Record = exports.CreateRunRequest = exports.Ack = exports.protobufPackage = void 0;
@@ -2,7 +2,7 @@
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
4
  // protoc-gen-ts_proto v2.7.0
5
- // protoc v3.20.3
5
+ // protoc v6.32.0
6
6
  // source: sn13/v1/sn13_validator.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.Sn13ServiceClient = exports.Sn13ServiceService = exports.OnDemandDataResponse = exports.OnDemandDataRequest = exports.ValidateRedditTopicResponse = exports.ValidateRedditTopicRequest = exports.ListTopicsResponse = exports.ListTopicsResponseDetail = exports.ListTopicsRequest = exports.protobufPackage = void 0;
@@ -1,3 +1,4 @@
1
+ import * as grpc from "@grpc/grpc-js";
1
2
  export interface BaseClientOptions {
2
3
  apiKey?: string;
3
4
  baseURL?: string;
@@ -43,4 +44,19 @@ export declare abstract class BaseClient {
43
44
  * Get the user ID for service account authentication
44
45
  */
45
46
  protected getUserId(): string;
47
+ /**
48
+ * Create the standard authentication metadata
49
+ * This is shared between secure and insecure connection methods
50
+ */
51
+ private createStandardMetadata;
52
+ /**
53
+ * Create authentication metadata for gRPC calls
54
+ * This is used for insecure connections where call credentials cannot be combined
55
+ */
56
+ protected createAuthMetadata(): grpc.Metadata;
57
+ /**
58
+ * Create gRPC channel credentials with proper authentication
59
+ * This handles both secure and insecure connections correctly
60
+ */
61
+ protected createChannelCredentials(): grpc.ChannelCredentials;
46
62
  }
@@ -1,7 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.BaseClient = void 0;
4
37
  const constants_1 = require("../constants");
38
+ const grpc = __importStar(require("@grpc/grpc-js"));
5
39
  /**
6
40
  * Base client class that provides common functionality for all clients
7
41
  */
@@ -14,7 +48,9 @@ class BaseClient {
14
48
  // Check environment variable for HTTPS setting
15
49
  const useHttps = process.env.MACROCOSMOS_USE_HTTPS !== "false";
16
50
  // Use secure if explicitly set in options or if HTTPS is enabled via env var
17
- this.secure = options.secure ?? useHttps;
51
+ // But automatically disable secure for localhost connections
52
+ const isLocalhost = this.baseURL.includes("localhost") || this.baseURL.includes("127.0.0.1");
53
+ this.secure = options.secure ?? (useHttps && !isLocalhost);
18
54
  // Check if the API key is valid
19
55
  if (!this.apiKey) {
20
56
  throw new Error("API key is required");
@@ -62,5 +98,46 @@ class BaseClient {
62
98
  getUserId() {
63
99
  return this.userId;
64
100
  }
101
+ /**
102
+ * Create the standard authentication metadata
103
+ * This is shared between secure and insecure connection methods
104
+ */
105
+ createStandardMetadata() {
106
+ const metadata = new grpc.Metadata();
107
+ metadata.add("authorization", `Bearer ${this.getApiKey()}`);
108
+ metadata.add("x-source", this.getAppName());
109
+ metadata.add("x-client-id", this.getClientName());
110
+ metadata.add("x-client-version", this.getClientVersion());
111
+ metadata.add("x-forwarded-user", this.getUserId());
112
+ return metadata;
113
+ }
114
+ /**
115
+ * Create authentication metadata for gRPC calls
116
+ * This is used for insecure connections where call credentials cannot be combined
117
+ */
118
+ createAuthMetadata() {
119
+ return this.createStandardMetadata();
120
+ }
121
+ /**
122
+ * Create gRPC channel credentials with proper authentication
123
+ * This handles both secure and insecure connections correctly
124
+ */
125
+ createChannelCredentials() {
126
+ // Create gRPC credentials with API key
127
+ const callCreds = grpc.credentials.createFromMetadataGenerator((_params, callback) => {
128
+ callback(null, this.createStandardMetadata());
129
+ });
130
+ // Create credentials based on secure option
131
+ if (this.isSecure()) {
132
+ // Use secure credentials for production
133
+ const channelCreds = grpc.credentials.createSsl();
134
+ return grpc.credentials.combineChannelCredentials(channelCreds, callCreds);
135
+ }
136
+ else {
137
+ // For insecure connections, we can't combine with call credentials
138
+ // The authentication headers will be added via metadata in individual calls
139
+ return grpc.credentials.createInsecure();
140
+ }
141
+ }
65
142
  }
66
143
  exports.BaseClient = BaseClient;
@@ -1,4 +1,4 @@
1
- import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse, GetStoredChatCompletionsRequest, GetStoredChatCompletionsResponse, GetChatSessionsResponse, SearchChatIdsByPromptAndCompletionTextRequest, SearchChatIdsByPromptAndCompletionTextResponse, CreateChatAndCompletionRequest, CreateChatAndCompletionResponse, CreateCompletionRequest, CreateCompletionResponse, DeleteChatsRequest, DeleteChatsResponse, DeleteCompletionsRequest, DeleteCompletionsResponse, UpdateChatAttributesRequest, UpdateChatAttributesResponse, UpdateCompletionAttributesRequest, UpdateCompletionAttributesResponse, GetChatSessionsRequest } from "../../generated/apex/v1/apex";
1
+ import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse, GetStoredChatCompletionsRequest, GetStoredChatCompletionsResponse, GetChatSessionsResponse, SearchChatIdsByPromptAndCompletionTextRequest, SearchChatIdsByPromptAndCompletionTextResponse, CreateChatAndCompletionRequest, CreateChatAndCompletionResponse, CreateCompletionRequest, CreateCompletionResponse, DeleteChatsRequest, DeleteChatsResponse, DeleteCompletionsRequest, DeleteCompletionsResponse, UpdateChatAttributesRequest, UpdateChatAttributesResponse, UpdateCompletionAttributesRequest, UpdateCompletionAttributesResponse, GetChatSessionsRequest, GetChatCompletionRequest, StoredChatCompletion } from "../../generated/apex/v1/apex";
2
2
  import * as grpc from "@grpc/grpc-js";
3
3
  import { BaseClient, BaseClientOptions } from "../BaseClient";
4
4
  import { ApexStream } from "./Stream";
@@ -97,4 +97,8 @@ export declare class ApexClient extends BaseClient {
97
97
  * Update completion attributes
98
98
  */
99
99
  updateCompletionAttributes: (params: UpdateCompletionAttributesRequest) => Promise<UpdateCompletionAttributesResponse>;
100
+ /**
101
+ * GetCompletion by ID client
102
+ */
103
+ getChatCompletion: (params: GetChatCompletionRequest) => Promise<StoredChatCompletion>;
100
104
  }