Skip to content

Commit

Permalink
feature: add /topic/clone to the ts-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker authored and skeptrunedev committed Oct 8, 2024
1 parent 71c20d6 commit 8b6fe7e
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
84 changes: 84 additions & 0 deletions clients/ts-sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5451,6 +5451,67 @@
]
}
},
"/api/topic/clone": {
"post": {
"tags": [
"Topic"
],
"summary": "Clone Topic",
"description": "Create a new chat topic from a `topic_id`. The new topic will be attched to the owner_id and act as a coordinator for conversation message history of gen-AI chat sessions. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.",
"operationId": "clone_topic",
"parameters": [
{
"name": "TR-Dataset",
"in": "header",
"description": "The dataset id or tracking_id to use for the request. We assume you intend to use an id if the value is a valid uuid.",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"description": "JSON request payload to create chat topic",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CloneTopicReqPayload"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "The JSON response payload containing the created topic",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Topic"
}
}
}
},
"400": {
"description": "Topic name empty or a service error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponseBody"
}
}
}
}
},
"security": [
{
"ApiKey": [
"admin"
]
}
]
}
},
"/api/topic/owner/{owner_id}": {
"get": {
"tags": [
Expand Down Expand Up @@ -7093,6 +7154,29 @@
}
}
},
"CloneTopicReqPayload": {
"type": "object",
"required": [
"topic_id",
"owner_id"
],
"properties": {
"name": {
"type": "string",
"description": "The name of the topic. If this is not provided, the topic name is the same as the previous topic",
"nullable": true
},
"owner_id": {
"type": "string",
"description": "The owner_id of the topic. This is typically a browser fingerprint or your user's id. It is used to group topics together for a user."
},
"topic_id": {
"type": "string",
"format": "uuid",
"description": "The topic_id to clone from"
}
}
},
"ClusterAnalytics": {
"oneOf": [
{
Expand Down
30 changes: 30 additions & 0 deletions clients/ts-sdk/src/functions/topic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DeleteTopicData2,
GetAllTopicsForOwnerIdData,
UpdateTopicReqPayload,
CloneTopicReqPayload
} from "../../fetch-client";
import { TrieveSDK } from "../../sdk";

Expand Down Expand Up @@ -40,6 +41,35 @@ export async function createTopic(
);
}

/**
* Clone a chat topic and all its messages to a new topic. Topics are attached to a owner_id’s and act as a coordinator for conversation message history of gen-AI chat sessions. Auth’ed user or api key must have an admin or owner role for the specified dataset’s organization.
*
* Example:
* ```js
*const data = await trieve.cloneTopic({
first_user_message: "hello",
name: "Test",
owner_id: "3c90c3cc-1d76-27198-8888-8dd25736052a",
});
* ```
*/
export async function cloneTopic(
/** @hidden */
this: TrieveSDK,
data: CloneTopicReqPayload,
signal?: AbortSignal
) {
return await this.trieve.fetch(
"/api/topic/clone",
"post",
{
data,
datasetId: this.datasetId,
},
signal
);
}

/**
* Update an existing chat topic. Currently, only the name of the topic can be updated. Auth’ed user or api key must have an admin or owner role for the specified dataset’s organization.
*
Expand Down
43 changes: 43 additions & 0 deletions clients/ts-sdk/src/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,21 @@ export type ChunkWithPosition = {
position: number;
};

export type CloneTopicReqPayload = {
/**
* The name of the topic. If this is not provided, the topic name is the same as the previous topic
*/
name?: (string) | null;
/**
* The owner_id of the topic. This is typically a browser fingerprint or your user's id. It is used to group topics together for a user.
*/
owner_id: string;
/**
* The topic_id to clone from
*/
topic_id: string;
};

export type ClusterAnalytics = {
filter?: ((ClusterAnalyticsFilter) | null);
type: 'cluster_topics';
Expand Down Expand Up @@ -3761,6 +3776,19 @@ export type UpdateTopicData = {

export type UpdateTopicResponse = (void);

export type CloneTopicData = {
/**
* JSON request payload to create chat topic
*/
requestBody: CloneTopicReqPayload;
/**
* The dataset id or tracking_id to use for the request. We assume you intend to use an id if the value is a valid uuid.
*/
trDataset: string;
};

export type CloneTopicResponse = (Topic);

export type GetAllTopicsForOwnerIdData = {
/**
* The owner_id to get topics of; A common approach is to use a browser fingerprint or your user's id
Expand Down Expand Up @@ -5149,6 +5177,21 @@ export type $OpenApiTs = {
};
};
};
'/api/topic/clone': {
post: {
req: CloneTopicData;
res: {
/**
* The JSON response payload containing the created topic
*/
200: Topic;
/**
* Topic name empty or a service error
*/
400: ErrorResponseBody;
};
};
};
'/api/topic/owner/{owner_id}': {
get: {
req: GetAllTopicsForOwnerIdData;
Expand Down

0 comments on commit 8b6fe7e

Please sign in to comment.