@axiom-lattice/client-sdk 2.1.55 → 2.1.57

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
@@ -2130,6 +2130,124 @@ var AbstractClient = class {
2130
2130
  );
2131
2131
  }
2132
2132
  };
2133
+ /**
2134
+ * Collections namespace for managing vector collections
2135
+ */
2136
+ this.collections = {
2137
+ /**
2138
+ * Lists all available collections
2139
+ * @returns A promise that resolves to the list of collections
2140
+ */
2141
+ list: async () => {
2142
+ const response = await this.makeRequest("/api/collections");
2143
+ return response.data.records;
2144
+ },
2145
+ /**
2146
+ * Retrieves a single collection by name
2147
+ * @param name - Collection name
2148
+ * @returns A promise that resolves to the collection information
2149
+ */
2150
+ get: async (name) => {
2151
+ const response = await this.makeRequest(`/api/collections/${name}`);
2152
+ if (!response.data) {
2153
+ throw new ApiError("Collection not found", 404);
2154
+ }
2155
+ return response.data;
2156
+ },
2157
+ /**
2158
+ * Creates a new collection
2159
+ * @param options - Options for creating a collection
2160
+ * @returns A promise that resolves to the created collection
2161
+ */
2162
+ create: async (options) => {
2163
+ const response = await this.makeRequest("/api/collections", {
2164
+ method: "POST",
2165
+ body: options
2166
+ });
2167
+ if (!response.data) {
2168
+ throw new ApiError("Failed to create collection", 500);
2169
+ }
2170
+ return response.data;
2171
+ },
2172
+ /**
2173
+ * Updates an existing collection by name
2174
+ * @param name - Collection name
2175
+ * @param options - Options for updating a collection
2176
+ * @returns A promise that resolves to the updated collection
2177
+ */
2178
+ update: async (name, options) => {
2179
+ const response = await this.makeRequest(`/api/collections/${name}`, {
2180
+ method: "PUT",
2181
+ body: options
2182
+ });
2183
+ if (!response.data) {
2184
+ throw new ApiError("Failed to update collection", 500);
2185
+ }
2186
+ return response.data;
2187
+ },
2188
+ /**
2189
+ * Deletes a collection by name
2190
+ * @param name - Collection name
2191
+ * @returns A promise that resolves when the collection is deleted
2192
+ */
2193
+ delete: async (name) => {
2194
+ await this.makeRequest(
2195
+ `/api/collections/${name}`,
2196
+ {
2197
+ method: "DELETE"
2198
+ }
2199
+ );
2200
+ },
2201
+ /**
2202
+ * Entries sub-namespace for a specific collection.
2203
+ * Returns entry CRUD + search methods scoped to the given collection.
2204
+ * @param collectionName - The collection name
2205
+ * @returns Entry operation methods
2206
+ */
2207
+ entries: (collectionName) => ({
2208
+ list: async () => {
2209
+ const response = await this.makeRequest(`/api/collections/${collectionName}/entries`);
2210
+ return response.data.records;
2211
+ },
2212
+ create: async (data) => {
2213
+ const response = await this.makeRequest(`/api/collections/${collectionName}/entries`, {
2214
+ method: "POST",
2215
+ body: data
2216
+ });
2217
+ if (!response.data)
2218
+ throw new ApiError("Failed to create entry", 500);
2219
+ return response.data;
2220
+ },
2221
+ get: async (id) => {
2222
+ const response = await this.makeRequest(`/api/collections/${collectionName}/entries/${id}`);
2223
+ if (!response.data)
2224
+ throw new ApiError("Entry not found", 404);
2225
+ return response.data;
2226
+ },
2227
+ update: async (id, data) => {
2228
+ const response = await this.makeRequest(`/api/collections/${collectionName}/entries/${id}`, {
2229
+ method: "PUT",
2230
+ body: data
2231
+ });
2232
+ if (!response.data)
2233
+ throw new ApiError("Failed to update entry", 500);
2234
+ return response.data;
2235
+ },
2236
+ delete: async (id) => {
2237
+ await this.makeRequest(
2238
+ `/api/collections/${collectionName}/entries/${id}`,
2239
+ { method: "DELETE" }
2240
+ );
2241
+ },
2242
+ search: async (query, opts) => {
2243
+ const response = await this.makeRequest(`/api/collections/${collectionName}/search`, {
2244
+ method: "POST",
2245
+ body: { query, ...opts }
2246
+ });
2247
+ return response.data.records;
2248
+ }
2249
+ })
2250
+ };
2133
2251
  /**
2134
2252
  * Threads namespace for managing threads for the current assistant
2135
2253
  */
@@ -2407,6 +2525,18 @@ var AbstractClient = class {
2407
2525
  },
2408
2526
  test: async (id) => {
2409
2527
  return await this.makeRequest(`/api/mcp-servers/${id}/test`, { method: "POST" });
2528
+ },
2529
+ connect: async (id) => {
2530
+ const response = await this.makeRequest(`/api/mcp-servers/${id}/connect`, { method: "POST" });
2531
+ if (!response.data)
2532
+ throw new ApiError("Failed to connect MCP server", 500);
2533
+ return response.data;
2534
+ },
2535
+ disconnect: async (id) => {
2536
+ const response = await this.makeRequest(`/api/mcp-servers/${id}/disconnect`, { method: "POST" });
2537
+ if (!response.data)
2538
+ throw new ApiError("Failed to disconnect MCP server", 500);
2539
+ return response.data;
2410
2540
  }
2411
2541
  };
2412
2542
  this.tasks = {
@@ -3714,14 +3844,20 @@ function createSimpleMessageMerger() {
3714
3844
  }
3715
3845
  return newMessage;
3716
3846
  }
3717
- function updateToolCalls(message) {
3718
- if (message.role !== "ai")
3719
- return;
3720
- const builders = toolBuilders.get(message.id);
3847
+ function replaceMessage(id, updates) {
3848
+ const index = messageMap.get(id);
3849
+ if (index === void 0)
3850
+ return null;
3851
+ const updated = { ...messages[index], ...updates };
3852
+ messages[index] = updated;
3853
+ return updated;
3854
+ }
3855
+ function buildToolCalls(messageId) {
3856
+ const builders = toolBuilders.get(messageId);
3721
3857
  if (!builders || builders.size === 0)
3722
- return;
3858
+ return null;
3723
3859
  const toolCalls = [];
3724
- for (const [index, builder] of Array.from(builders.entries())) {
3860
+ for (const [, builder] of Array.from(builders.entries())) {
3725
3861
  if (builder.name && builder.id) {
3726
3862
  const args = builder.args.trim();
3727
3863
  const parsedArgs = safeJsonParse(args);
@@ -3733,9 +3869,7 @@ function createSimpleMessageMerger() {
3733
3869
  });
3734
3870
  }
3735
3871
  }
3736
- if (toolCalls.length > 0) {
3737
- message.tool_calls = toolCalls;
3738
- }
3872
+ return toolCalls.length > 0 ? toolCalls : null;
3739
3873
  }
3740
3874
  function initialMessages(msgs) {
3741
3875
  reset();
@@ -3745,15 +3879,21 @@ function createSimpleMessageMerger() {
3745
3879
  }
3746
3880
  function push(chunk) {
3747
3881
  const role = normalizeRole(chunk.type);
3748
- const message = ensureMessage(chunk.data.id, role);
3882
+ let message = ensureMessage(chunk.data.id, role);
3883
+ const isInArray = message.role !== "tool";
3749
3884
  if (chunk.data.content) {
3750
- message.content = (message.content || "") + chunk.data.content;
3885
+ const newContent = (message.content || "") + chunk.data.content;
3886
+ if (isInArray) {
3887
+ message = replaceMessage(chunk.data.id, { content: newContent }) || message;
3888
+ } else {
3889
+ message.content = newContent;
3890
+ }
3751
3891
  }
3752
3892
  if (message.role === "ai" && chunk.data.tool_calls && chunk.data.tool_calls.length > 0) {
3753
3893
  for (const toolCall of chunk.data.tool_calls) {
3754
3894
  toolId_MessageIdMap.set(toolCall.id, message.id);
3755
3895
  }
3756
- message.tool_calls = chunk.data.tool_calls;
3896
+ message = replaceMessage(chunk.data.id, { tool_calls: [...chunk.data.tool_calls] }) || message;
3757
3897
  }
3758
3898
  if (chunk.data.tool_call_chunks && message.role === "ai") {
3759
3899
  let builders = toolBuilders.get(message.id);
@@ -3774,7 +3914,10 @@ function createSimpleMessageMerger() {
3774
3914
  if (chunk_item.args)
3775
3915
  builder.args += chunk_item.args;
3776
3916
  }
3777
- updateToolCalls(message);
3917
+ const toolCalls = buildToolCalls(message.id);
3918
+ if (toolCalls) {
3919
+ message = replaceMessage(chunk.data.id, { tool_calls: toolCalls }) || message;
3920
+ }
3778
3921
  }
3779
3922
  if (message.role === "tool" && chunk.data.tool_call_id) {
3780
3923
  const original_tool_message_id = chunk.data.id;
@@ -3783,49 +3926,19 @@ function createSimpleMessageMerger() {
3783
3926
  return;
3784
3927
  const messageIndex = messageMap.get(messageId);
3785
3928
  if (messageIndex !== void 0) {
3786
- const message2 = messages[messageIndex];
3787
- message2.tool_calls = message2.tool_calls?.map((tc) => {
3929
+ const aiMessage = messages[messageIndex];
3930
+ const updatedToolCalls = aiMessage.tool_calls?.map((tc) => {
3788
3931
  if (tc.id === chunk.data.tool_call_id) {
3789
3932
  return { ...tc, response: chunk.data.content, status: "success", original_tool_message_id };
3790
3933
  }
3791
3934
  return tc;
3792
3935
  });
3793
- messages[messageIndex] = message2;
3936
+ messages[messageIndex] = { ...aiMessage, tool_calls: updatedToolCalls };
3794
3937
  }
3795
3938
  }
3796
3939
  }
3797
3940
  function getMessages() {
3798
3941
  return [...messages];
3799
- const toolResponsesMap = {};
3800
- messages.forEach((message) => {
3801
- if (message.role === "tool" && message.tool_call_id) {
3802
- toolResponsesMap[message.tool_call_id] = message;
3803
- }
3804
- });
3805
- return messages.filter((message) => {
3806
- return message.role !== "tool";
3807
- }).map((message) => {
3808
- if (message.role === "ai" && message.tool_calls) {
3809
- const mergedMessage = { ...message };
3810
- if (mergedMessage.tool_calls) {
3811
- mergedMessage.tool_calls = mergedMessage.tool_calls.map(
3812
- (toolCall) => {
3813
- const toolResponse = toolResponsesMap[toolCall.id];
3814
- if (toolResponse) {
3815
- return {
3816
- ...toolCall,
3817
- response: toolResponse.content,
3818
- status: "success"
3819
- };
3820
- }
3821
- return toolCall;
3822
- }
3823
- );
3824
- }
3825
- return mergedMessage;
3826
- }
3827
- return message;
3828
- });
3829
3942
  }
3830
3943
  function getMessagesWithoutToolCalls() {
3831
3944
  return messages.filter(