Skip to content

Commit c8accb9

Browse files
Update api spec (#346)
* YOYO NEW API SPEC! * Generated new lib * 2.0.46 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d0c0035 commit c8accb9

10 files changed

+480
-14
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ml } from '../../src/index.js';
2+
3+
async function example() {
4+
const response = await ml.list_conversations_for_user({
5+
limit: 7,
6+
page_token: 'string',
7+
sort_by: 'created_at_ascending',
8+
});
9+
if ('error_code' in response) throw response;
10+
11+
return response;
12+
}
13+
14+
describe('Testing ml.list_conversations_for_user', () => {
15+
it('should be truthy or throw', async () => {
16+
expect(await example()).toBeTruthy();
17+
});
18+
});

__tests__/gen/ml-list_text_to_cad_models_for_user.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ async function example() {
55
limit: 7,
66
page_token: 'string',
77
sort_by: 'created_at_ascending',
8+
conversation_id: '00000000-0000-0000-0000-000000000000',
89
no_models: true,
910
});
1011
if ('error_code' in response) throw response;

kittycad.ts.patch.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"op": "add",
116116
"path": "/paths/~1user~1text-to-cad/get/x-typescript",
117117
"value": {
118-
"example": "import { ml } from '@kittycad/lib'\n\nasync function example() {\n const response = await ml.list_text_to_cad_models_for_user({\n limit: 7,\n page_token: 'string',\n sort_by: 'created_at_ascending',\n no_models: true,\n })\n if ('error_code' in response) throw response\n console.log(JSON.stringify(response, null, 2))\n}\n",
118+
"example": "import { ml } from '@kittycad/lib'\n\nasync function example() {\n const response = await ml.list_text_to_cad_models_for_user({\n limit: 7,\n page_token: 'string',\n sort_by: 'created_at_ascending',\n conversation_id: '00000000-0000-0000-0000-000000000000',\n no_models: true,\n })\n if ('error_code' in response) throw response\n console.log(JSON.stringify(response, null, 2))\n}\n",
119119
"libDocsLink": ""
120120
}
121121
},
@@ -935,6 +935,14 @@
935935
"libDocsLink": ""
936936
}
937937
},
938+
{
939+
"op": "add",
940+
"path": "/paths/~1ml~1conversations/get/x-typescript",
941+
"value": {
942+
"example": "import { ml } from '@kittycad/lib'\n\nasync function example() {\n const response = await ml.list_conversations_for_user({\n limit: 7,\n page_token: 'string',\n sort_by: 'created_at_ascending',\n })\n if ('error_code' in response) throw response\n console.log(JSON.stringify(response, null, 2))\n}\n",
943+
"libDocsLink": ""
944+
}
945+
},
938946
{
939947
"op": "add",
940948
"path": "/paths/~1ml-prompts~1{id}/get/x-typescript",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kittycad/lib",
3-
"version": "2.0.45",
3+
"version": "2.0.46",
44
"description": "Javascript library for KittyCAD API",
55
"type": "module",
66
"keywords": [

spec.json

Lines changed: 217 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,6 +4230,116 @@
42304230
}
42314231
}
42324232
},
4233+
"/ml/conversations": {
4234+
"get": {
4235+
"tags": [
4236+
"ml"
4237+
],
4238+
"summary": "List conversations",
4239+
"description": "This endpoint requires authentication by any Zoo user. It returns the conversations for the authenticated user.\n\nThe conversations are returned in order of creation, with the most recently created conversations first.",
4240+
"operationId": "list_conversations_for_user",
4241+
"parameters": [
4242+
{
4243+
"in": "query",
4244+
"name": "limit",
4245+
"description": "Maximum number of items returned by a single call",
4246+
"schema": {
4247+
"nullable": true,
4248+
"type": "integer",
4249+
"format": "uint32",
4250+
"minimum": 1
4251+
}
4252+
},
4253+
{
4254+
"in": "query",
4255+
"name": "page_token",
4256+
"description": "Token returned by previous call to retrieve the subsequent page",
4257+
"schema": {
4258+
"nullable": true,
4259+
"type": "string"
4260+
}
4261+
},
4262+
{
4263+
"in": "query",
4264+
"name": "sort_by",
4265+
"schema": {
4266+
"$ref": "#/components/schemas/CreatedAtSortMode"
4267+
}
4268+
}
4269+
],
4270+
"responses": {
4271+
"200": {
4272+
"description": "successful operation",
4273+
"headers": {
4274+
"Access-Control-Allow-Credentials": {
4275+
"description": "Access-Control-Allow-Credentials header.",
4276+
"style": "simple",
4277+
"schema": {
4278+
"nullable": true,
4279+
"type": "string"
4280+
}
4281+
},
4282+
"Access-Control-Allow-Headers": {
4283+
"description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.",
4284+
"style": "simple",
4285+
"schema": {
4286+
"nullable": true,
4287+
"type": "string"
4288+
}
4289+
},
4290+
"Access-Control-Allow-Methods": {
4291+
"description": "Access-Control-Allow-Methods header.",
4292+
"style": "simple",
4293+
"schema": {
4294+
"nullable": true,
4295+
"type": "string"
4296+
}
4297+
},
4298+
"Access-Control-Allow-Origin": {
4299+
"description": "Access-Control-Allow-Origin header.",
4300+
"style": "simple",
4301+
"schema": {
4302+
"nullable": true,
4303+
"type": "string"
4304+
}
4305+
},
4306+
"Set-Cookie": {
4307+
"description": "Set-Cookie header.",
4308+
"style": "simple",
4309+
"schema": {
4310+
"nullable": true,
4311+
"type": "string"
4312+
}
4313+
},
4314+
"X-Api-Call-Id": {
4315+
"description": "ID for this request. We return it so that users can report this to us and help us debug their problems.",
4316+
"style": "simple",
4317+
"required": true,
4318+
"schema": {
4319+
"type": "string"
4320+
}
4321+
}
4322+
},
4323+
"content": {
4324+
"application/json": {
4325+
"schema": {
4326+
"$ref": "#/components/schemas/ConversationResultsPage"
4327+
}
4328+
}
4329+
}
4330+
},
4331+
"4XX": {
4332+
"$ref": "#/components/responses/Error"
4333+
},
4334+
"5XX": {
4335+
"$ref": "#/components/responses/Error"
4336+
}
4337+
},
4338+
"x-dropshot-pagination": {
4339+
"required": []
4340+
}
4341+
}
4342+
},
42334343
"/ml/convert/proprietary-to-kcl": {
42344344
"post": {
42354345
"tags": [
@@ -15847,6 +15957,14 @@
1584715957
"$ref": "#/components/schemas/CreatedAtSortMode"
1584815958
}
1584915959
},
15960+
{
15961+
"in": "query",
15962+
"name": "conversation_id",
15963+
"description": "If specified, only return the prompts for the conversation id given.",
15964+
"schema": {
15965+
"$ref": "#/components/schemas/Uuid"
15966+
}
15967+
},
1585015968
{
1585115969
"in": "query",
1585215970
"name": "no_models",
@@ -15913,7 +16031,7 @@
1591316031
"content": {
1591416032
"application/json": {
1591516033
"schema": {
15916-
"$ref": "#/components/schemas/TextToCadResultsPage"
16034+
"$ref": "#/components/schemas/TextToCadResponseResultsPage"
1591716035
}
1591816036
}
1591916037
}
@@ -16006,7 +16124,7 @@
1600616124
"content": {
1600716125
"application/json": {
1600816126
"schema": {
16009-
"$ref": "#/components/schemas/TextToCad"
16127+
"$ref": "#/components/schemas/TextToCadResponse"
1601016128
}
1601116129
}
1601216130
}
@@ -20365,6 +20483,72 @@
2036520483
}
2036620484
}
2036720485
},
20486+
"Conversation": {
20487+
"description": "A conversation composed of many ML prompts.",
20488+
"type": "object",
20489+
"properties": {
20490+
"created_at": {
20491+
"title": "DateTime",
20492+
"description": "The date and time the conversation was created.",
20493+
"type": "string",
20494+
"format": "date-time"
20495+
},
20496+
"first_prompt": {
20497+
"description": "The prompt that started this conversation.",
20498+
"type": "string"
20499+
},
20500+
"id": {
20501+
"description": "The unique identifier for the conversation.",
20502+
"allOf": [
20503+
{
20504+
"$ref": "#/components/schemas/Uuid"
20505+
}
20506+
]
20507+
},
20508+
"updated_at": {
20509+
"title": "DateTime",
20510+
"description": "The date and time the conversation was last updated.",
20511+
"type": "string",
20512+
"format": "date-time"
20513+
},
20514+
"user_id": {
20515+
"description": "The user ID of the user who created the conversation.",
20516+
"allOf": [
20517+
{
20518+
"$ref": "#/components/schemas/Uuid"
20519+
}
20520+
]
20521+
}
20522+
},
20523+
"required": [
20524+
"created_at",
20525+
"first_prompt",
20526+
"id",
20527+
"updated_at",
20528+
"user_id"
20529+
]
20530+
},
20531+
"ConversationResultsPage": {
20532+
"description": "A single page of results",
20533+
"type": "object",
20534+
"properties": {
20535+
"items": {
20536+
"description": "list of items on this page of results",
20537+
"type": "array",
20538+
"items": {
20539+
"$ref": "#/components/schemas/Conversation"
20540+
}
20541+
},
20542+
"next_page": {
20543+
"nullable": true,
20544+
"description": "token used to fetch the next page of results (if any)",
20545+
"type": "string"
20546+
}
20547+
},
20548+
"required": [
20549+
"items"
20550+
]
20551+
},
2036820552
"ConversionParams": {
2036920553
"description": "Describes the file to convert (src) and what it should be converted into (output).",
2037020554
"type": "object",
@@ -35008,15 +35192,44 @@
3500835192
}
3500935193
}
3501035194
},
35011-
"TextToCadResultsPage": {
35195+
"TextToCadResponse": {
35196+
"description": "Type that encompasses all Text-to-CAD response types, including iteration and multi-file iteration.",
35197+
"anyOf": [
35198+
{
35199+
"description": "A response from a text to CAD prompt.",
35200+
"allOf": [
35201+
{
35202+
"$ref": "#/components/schemas/TextToCad"
35203+
}
35204+
]
35205+
},
35206+
{
35207+
"description": "A response from a text to CAD iteration.",
35208+
"allOf": [
35209+
{
35210+
"$ref": "#/components/schemas/TextToCadIteration"
35211+
}
35212+
]
35213+
},
35214+
{
35215+
"description": "A response from a text to CAD multi-file iteration.",
35216+
"allOf": [
35217+
{
35218+
"$ref": "#/components/schemas/TextToCadMultiFileIteration"
35219+
}
35220+
]
35221+
}
35222+
]
35223+
},
35224+
"TextToCadResponseResultsPage": {
3501235225
"description": "A single page of results",
3501335226
"type": "object",
3501435227
"properties": {
3501535228
"items": {
3501635229
"description": "list of items on this page of results",
3501735230
"type": "array",
3501835231
"items": {
35019-
"$ref": "#/components/schemas/TextToCad"
35232+
"$ref": "#/components/schemas/TextToCadResponse"
3502035233
}
3502135234
},
3502235235
"next_page": {

src/api/ml/get_text_to_cad_model_for_user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { TextToCad_type, Error_type } from '../../models.js';
1+
import { TextToCadResponse_type, Error_type } from '../../models.js';
22
import { Client } from '../../client.js';
33

44
interface Get_text_to_cad_model_for_user_params {
55
client?: Client;
66
id: string;
77
}
88

9-
type Get_text_to_cad_model_for_user_return = TextToCad_type | Error_type;
9+
type Get_text_to_cad_model_for_user_return =
10+
| TextToCadResponse_type
11+
| Error_type;
1012

1113
export default async function get_text_to_cad_model_for_user({
1214
client,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {
2+
ConversationResultsPage_type,
3+
Error_type,
4+
CreatedAtSortMode_type,
5+
} from '../../models.js';
6+
import { Client } from '../../client.js';
7+
8+
interface List_conversations_for_user_params {
9+
client?: Client;
10+
limit: number;
11+
page_token: string;
12+
sort_by: CreatedAtSortMode_type;
13+
}
14+
15+
type List_conversations_for_user_return =
16+
| ConversationResultsPage_type
17+
| Error_type;
18+
19+
export default async function list_conversations_for_user({
20+
client,
21+
limit,
22+
page_token,
23+
sort_by,
24+
}: List_conversations_for_user_params): Promise<List_conversations_for_user_return> {
25+
const url = `/ml/conversations?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
26+
// Backwards compatible for the BASE_URL env variable
27+
// That used to exist in only this lib, ZOO_HOST exists in the all the other
28+
// sdks and the CLI.
29+
const urlBase =
30+
process?.env?.ZOO_HOST || process?.env?.BASE_URL || 'https://api.zoo.dev';
31+
const fullUrl = urlBase + url;
32+
// The other sdks use to use KITTYCAD_API_TOKEN, now they still do for
33+
// backwards compatibility, but the new standard is ZOO_API_TOKEN.
34+
// For some reason only this lib supported KITTYCAD_TOKEN, so we need to
35+
// check for that as well.
36+
const kittycadToken = client
37+
? client.token || process.env.ZOO_API_TOKEN || ''
38+
: process.env.KITTYCAD_TOKEN ||
39+
process.env.KITTYCAD_API_TOKEN ||
40+
process.env.ZOO_API_TOKEN ||
41+
'';
42+
const headers = {
43+
Authorization: `Bearer ${kittycadToken}`,
44+
'Content-Type': 'text/plain',
45+
};
46+
const fetchOptions = {
47+
method: 'GET',
48+
headers,
49+
};
50+
const response = await fetch(fullUrl, fetchOptions);
51+
const result = (await response.json()) as List_conversations_for_user_return;
52+
return result;
53+
}

0 commit comments

Comments
 (0)