Skip to content

Commit dabf6ca

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

File tree

7 files changed

+258
-1
lines changed

7 files changed

+258
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ml } from '../../src/index.js';
2+
3+
async function example() {
4+
const response = await ml.create_proprietary_to_kcl({
5+
files: [
6+
{
7+
name: 'thing.kcl',
8+
data: new Blob(['thing = 1'], { type: 'text/plain' }),
9+
},
10+
],
11+
});
12+
if ('error_code' in response) throw response;
13+
14+
return response;
15+
}
16+
17+
describe('Testing ml.create_proprietary_to_kcl', () => {
18+
it('should be truthy or throw', async () => {
19+
expect(await example()).toBeTruthy();
20+
});
21+
});

kittycad.ts.patch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,14 @@
895895
"libDocsLink": ""
896896
}
897897
},
898+
{
899+
"op": "add",
900+
"path": "/paths/~1ml~1convert~1proprietary-to-kcl/post/x-typescript",
901+
"value": {
902+
"example": "import { ml } from '@kittycad/lib'\n\nasync function example() {\n const response = await ml.create_proprietary_to_kcl({\n files: [\n {\n name: 'thing.kcl',\n data: new Blob(['thing = 1'], { type: 'text/plain' }),\n },\n ],\n })\n if ('error_code' in response) throw response\n console.log(JSON.stringify(response, null, 2))\n}\n",
903+
"libDocsLink": ""
904+
}
905+
},
898906
{
899907
"op": "add",
900908
"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.31",
3+
"version": "2.0.32",
44
"description": "Javascript library for KittyCAD API",
55
"type": "module",
66
"keywords": [

spec.json

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,6 +3912,164 @@
39123912
}
39133913
}
39143914
},
3915+
"/ml/convert/proprietary-to-kcl": {
3916+
"post": {
3917+
"tags": [
3918+
"ml"
3919+
],
3920+
"summary": "Converts a proprietary CAD format to KCL.",
3921+
"description": "This endpoint is used to convert a proprietary CAD format to KCL. The file passed MUST have feature tree data.\n\nA STEP file does not have feature tree data, so it will not work. A sldprt file does have feature tree data, so it will work.",
3922+
"operationId": "create_proprietary_to_kcl",
3923+
"requestBody": {
3924+
"content": {
3925+
"multipart/form-data": {
3926+
"schema": {
3927+
"type": "string",
3928+
"format": "binary"
3929+
}
3930+
}
3931+
},
3932+
"required": true
3933+
},
3934+
"responses": {
3935+
"201": {
3936+
"description": "successful creation",
3937+
"headers": {
3938+
"Access-Control-Allow-Credentials": {
3939+
"description": "Access-Control-Allow-Credentials header.",
3940+
"style": "simple",
3941+
"schema": {
3942+
"nullable": true,
3943+
"type": "string"
3944+
}
3945+
},
3946+
"Access-Control-Allow-Headers": {
3947+
"description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.",
3948+
"style": "simple",
3949+
"schema": {
3950+
"nullable": true,
3951+
"type": "string"
3952+
}
3953+
},
3954+
"Access-Control-Allow-Methods": {
3955+
"description": "Access-Control-Allow-Methods header.",
3956+
"style": "simple",
3957+
"schema": {
3958+
"nullable": true,
3959+
"type": "string"
3960+
}
3961+
},
3962+
"Access-Control-Allow-Origin": {
3963+
"description": "Access-Control-Allow-Origin header.",
3964+
"style": "simple",
3965+
"schema": {
3966+
"nullable": true,
3967+
"type": "string"
3968+
}
3969+
},
3970+
"Set-Cookie": {
3971+
"description": "Set-Cookie header.",
3972+
"style": "simple",
3973+
"schema": {
3974+
"nullable": true,
3975+
"type": "string"
3976+
}
3977+
},
3978+
"X-Api-Call-Id": {
3979+
"description": "ID for this request. We return it so that users can report this to us and help us debug their problems.",
3980+
"style": "simple",
3981+
"required": true,
3982+
"schema": {
3983+
"type": "string"
3984+
}
3985+
}
3986+
},
3987+
"content": {
3988+
"application/json": {
3989+
"schema": {
3990+
"$ref": "#/components/schemas/KclModel"
3991+
}
3992+
}
3993+
}
3994+
},
3995+
"4XX": {
3996+
"$ref": "#/components/responses/Error"
3997+
},
3998+
"5XX": {
3999+
"$ref": "#/components/responses/Error"
4000+
}
4001+
}
4002+
},
4003+
"options": {
4004+
"tags": [
4005+
"hidden"
4006+
],
4007+
"summary": "OPTIONS endpoint.",
4008+
"description": "This is necessary for some preflight requests, specifically POST, PUT, and DELETE.",
4009+
"operationId": "options_create_proprietary_to_kcl",
4010+
"responses": {
4011+
"204": {
4012+
"description": "resource updated",
4013+
"headers": {
4014+
"Access-Control-Allow-Credentials": {
4015+
"description": "Access-Control-Allow-Credentials header.",
4016+
"style": "simple",
4017+
"schema": {
4018+
"nullable": true,
4019+
"type": "string"
4020+
}
4021+
},
4022+
"Access-Control-Allow-Headers": {
4023+
"description": "Access-Control-Allow-Headers header. This is a comma-separated list of headers.",
4024+
"style": "simple",
4025+
"schema": {
4026+
"nullable": true,
4027+
"type": "string"
4028+
}
4029+
},
4030+
"Access-Control-Allow-Methods": {
4031+
"description": "Access-Control-Allow-Methods header.",
4032+
"style": "simple",
4033+
"schema": {
4034+
"nullable": true,
4035+
"type": "string"
4036+
}
4037+
},
4038+
"Access-Control-Allow-Origin": {
4039+
"description": "Access-Control-Allow-Origin header.",
4040+
"style": "simple",
4041+
"schema": {
4042+
"nullable": true,
4043+
"type": "string"
4044+
}
4045+
},
4046+
"Set-Cookie": {
4047+
"description": "Set-Cookie header.",
4048+
"style": "simple",
4049+
"schema": {
4050+
"nullable": true,
4051+
"type": "string"
4052+
}
4053+
},
4054+
"X-Api-Call-Id": {
4055+
"description": "ID for this request. We return it so that users can report this to us and help us debug their problems.",
4056+
"style": "simple",
4057+
"required": true,
4058+
"schema": {
4059+
"type": "string"
4060+
}
4061+
}
4062+
}
4063+
},
4064+
"4XX": {
4065+
"$ref": "#/components/responses/Error"
4066+
},
4067+
"5XX": {
4068+
"$ref": "#/components/responses/Error"
4069+
}
4070+
}
4071+
}
4072+
},
39154073
"/ml/kcl/completions": {
39164074
"post": {
39174075
"tags": [
@@ -22995,6 +23153,19 @@
2299523153
"completions"
2299623154
]
2299723155
},
23156+
"KclModel": {
23157+
"description": "The response containing the KCL code.",
23158+
"type": "object",
23159+
"properties": {
23160+
"code": {
23161+
"description": "The KCL code.",
23162+
"type": "string"
23163+
}
23164+
},
23165+
"required": [
23166+
"code"
23167+
]
23168+
},
2299823169
"LeafNode": {
2299923170
"description": "Leaf node information.",
2300023171
"type": "object",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { KclModel_type, Error_type } from '../../models.js';
2+
import { File } from '../../models.js';
3+
import { Client } from '../../client.js';
4+
5+
interface Create_proprietary_to_kcl_params {
6+
client?: Client;
7+
files: File[];
8+
}
9+
10+
type Create_proprietary_to_kcl_return = KclModel_type | Error_type;
11+
12+
export default async function create_proprietary_to_kcl({
13+
client,
14+
files,
15+
}: Create_proprietary_to_kcl_params): Promise<Create_proprietary_to_kcl_return> {
16+
const url = `/ml/convert/proprietary-to-kcl`;
17+
// Backwards compatible for the BASE_URL env variable
18+
// That used to exist in only this lib, ZOO_HOST exists in the all the other
19+
// sdks and the CLI.
20+
const urlBase =
21+
process?.env?.ZOO_HOST || process?.env?.BASE_URL || 'https://api.zoo.dev';
22+
const fullUrl = urlBase + url;
23+
// The other sdks use to use KITTYCAD_API_TOKEN, now they still do for
24+
// backwards compatibility, but the new standard is ZOO_API_TOKEN.
25+
// For some reason only this lib supported KITTYCAD_TOKEN, so we need to
26+
// check for that as well.
27+
const kittycadToken = client
28+
? client.token || process.env.ZOO_API_TOKEN || ''
29+
: process.env.KITTYCAD_TOKEN ||
30+
process.env.KITTYCAD_API_TOKEN ||
31+
process.env.ZOO_API_TOKEN ||
32+
'';
33+
const headers = {
34+
Authorization: `Bearer ${kittycadToken}`,
35+
};
36+
37+
const formData = new FormData();
38+
files.forEach((file) => {
39+
formData.append(file.name, file.data, file.name);
40+
});
41+
42+
const fetchOptions = {
43+
method: 'POST',
44+
headers,
45+
body: formData,
46+
};
47+
const response = await fetch(fullUrl, fetchOptions);
48+
const result = (await response.json()) as Create_proprietary_to_kcl_return;
49+
return result;
50+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export const meta = {
8282
};
8383

8484
import create_kcl_code_completions from './api/ml/create_kcl_code_completions.js';
85+
import create_proprietary_to_kcl from './api/ml/create_proprietary_to_kcl.js';
8586
import create_text_to_cad from './api/ml/create_text_to_cad.js';
8687
import create_text_to_cad_iteration from './api/ml/create_text_to_cad_iteration.js';
8788
import create_text_to_cad_model_feedback from './api/ml/create_text_to_cad_model_feedback.js';
@@ -92,6 +93,7 @@ import list_ml_prompts from './api/ml/list_ml_prompts.js';
9293
import list_text_to_cad_models_for_user from './api/ml/list_text_to_cad_models_for_user.js';
9394
export const ml = {
9495
create_kcl_code_completions,
96+
create_proprietary_to_kcl,
9597
create_text_to_cad,
9698
create_text_to_cad_iteration,
9799
create_text_to_cad_model_feedback,

src/models.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,10 @@ export interface KclCodeCompletionResponse_type {
23342334
completions: string[];
23352335
}
23362336

2337+
export interface KclModel_type {
2338+
code: string /* The KCL code. */;
2339+
}
2340+
23372341
export interface LeafNode_type {
23382342
/* default:0, format:int64, description:The auth timeout of the leaf node. */
23392343
auth_timeout: number;
@@ -6669,6 +6673,7 @@ export interface Models {
66696673
KclCodeCompletionParams_type: KclCodeCompletionParams_type;
66706674
KclCodeCompletionRequest_type: KclCodeCompletionRequest_type;
66716675
KclCodeCompletionResponse_type: KclCodeCompletionResponse_type;
6676+
KclModel_type: KclModel_type;
66726677
LeafNode_type: LeafNode_type;
66736678
LengthUnit_type: LengthUnit_type;
66746679
Loft_type: Loft_type;

0 commit comments

Comments
 (0)