@websimai/client-api-types 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websimai/client-api-types",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Type declarations for `window.websim` object",
5
5
  "author": "GameRoMan",
6
6
  "license": "MIT",
@@ -8,9 +8,6 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./src/index.d.ts"
11
- },
12
- "./client": {
13
- "types": "./src/client.d.ts"
14
11
  }
15
12
  },
16
13
  "scripts": {
@@ -0,0 +1,74 @@
1
+ import type { WebsimUser, WebsimUserOrAnonymous } from "./types";
2
+
3
+ import type { ChatCompletionOptions, ChatCompletionResult } from "./types";
4
+
5
+ import type { ImageGenOptions, ImageGenResult } from "./types";
6
+
7
+ import type { TextToSpeechOptions, TextToSpeechResult } from "./types";
8
+
9
+ export interface WebsimClientAPI {
10
+ getUser(): Promise<WebsimUserOrAnonymous>;
11
+ /** Alias for getUser */
12
+ getCurrentUser(): Promise<WebsimUserOrAnonymous>;
13
+ /** @deprecated Use getBootstrap instead */
14
+ getDistinctId(): Promise<string>;
15
+ getBootstrap(): Promise<{
16
+ readonly distinct_id: string;
17
+ readonly session_id: string;
18
+ }>;
19
+ getCreatedBy(): Promise<WebsimUser>;
20
+ /** Alias for getCreatedBy */
21
+ getCreator(): Promise<WebsimUser>;
22
+ getCurrentProject(): Promise<{
23
+ readonly id: string;
24
+ readonly title: string;
25
+ readonly description: string;
26
+ }>;
27
+ getColorScheme(): Promise<"light" | "dark">;
28
+
29
+ postComment(args: {
30
+ content: string;
31
+ credits?: number;
32
+ images?: string[];
33
+ }): Promise<{ readonly error?: "User has not interacted with the page" }>;
34
+
35
+ addEventListener(
36
+ eventType: "comment:created",
37
+ callback: (data: any) => void
38
+ ): () => void;
39
+
40
+ upload: (file: File) => Promise<string>;
41
+
42
+ readonly chat: {
43
+ readonly completions: {
44
+ create: (args: ChatCompletionOptions) => Promise<ChatCompletionResult>;
45
+ };
46
+ };
47
+
48
+ imageGen: (args: ImageGenOptions) => Promise<ImageGenResult>;
49
+
50
+ textToSpeech: (args: TextToSpeechOptions) => Promise<TextToSpeechResult>;
51
+
52
+ experimental: {
53
+ v0: {
54
+ login: () => Promise<void>;
55
+
56
+ /**
57
+ * Saves the given htmlContent to a new websim site.
58
+ * @param htmlContent html content to save
59
+ * @returns object with id of the saved site
60
+ */
61
+ save(htmlContent: string): Promise<{ id: string }>;
62
+
63
+ /**
64
+ * Returns the HTML for the given siteId.
65
+ * Defaults to the current websimsite.
66
+ * @param siteId
67
+ * @returns HTML for the given siteId.
68
+ */
69
+ getHTML(siteId?: string): Promise<string>;
70
+ };
71
+ };
72
+
73
+ internal_only_experimental: {};
74
+ }
@@ -0,0 +1,9 @@
1
+ import type { WebsimClientAPI } from "./client-api";
2
+
3
+ declare global {
4
+ interface Window {
5
+ readonly websim: WebsimClientAPI;
6
+ }
7
+
8
+ declare const websim: WebsimClientAPI;
9
+ }
package/src/index.d.ts CHANGED
@@ -1,9 +1,4 @@
1
- import type { WebsimClientAPI } from "./client";
1
+ export type { WebsimClientAPI } from "./client-api";
2
+ export type * from "./types";
2
3
 
3
- declare global {
4
- interface Window {
5
- readonly websim: WebsimClientAPI;
6
- }
7
-
8
- declare const websim: WebsimClientAPI;
9
- }
4
+ export type * from "./globals";
@@ -0,0 +1,106 @@
1
+ export type ChatCompletionsMessageRole =
2
+ | "system"
3
+ | "user"
4
+ | "assistant"
5
+ | "tool";
6
+
7
+ export type ChatCompletionsMessageContent =
8
+ | {
9
+ /**
10
+ * The type of content part.
11
+ */
12
+ type: "text";
13
+ /**
14
+ * The text content.
15
+ */
16
+ text: string;
17
+ }
18
+ | {
19
+ /**
20
+ * The type of content part.
21
+ */
22
+ type: "image_url";
23
+ /**
24
+ * An object containing the base64 encoded image data URL.
25
+ */
26
+ image_url: {
27
+ /**
28
+ * A base64 encoded image data URL.
29
+ */
30
+ url: string;
31
+ };
32
+ };
33
+
34
+ /**
35
+ * Represents a single message in the conversation history.
36
+ */
37
+ export type ChatCompletionsMessage = {
38
+ /**
39
+ * The role of the message sender.
40
+ */
41
+ role: ChatCompletionsMessageRole;
42
+ /**
43
+ * The message content.
44
+ * Can be plain text or an array for multimodal inputs.
45
+ */
46
+ content: string | ChatCompletionsMessageContent[];
47
+ };
48
+
49
+ export type ChatCompletionOptions = {
50
+ /**
51
+ * A list of messages comprising the conversation so far.
52
+ * Each message includes a `role` (system, user, assistant, tool) and `content`.
53
+ */
54
+ messages: ChatCompletionsMessage[];
55
+ /**
56
+ * ID of the model to use.
57
+ * If not specified, websim uses its default model.
58
+ */
59
+ model?: string;
60
+ /**
61
+ * If `true`, the model will attempt to generate a JSON object.
62
+ * The response content will be a string that you will need to parse.
63
+ * Defaults to `false`.
64
+ */
65
+ json?: boolean;
66
+ /**
67
+ * If `true`, the response will be streamed back incrementally.
68
+ * Defaults to `false`.
69
+ */
70
+ stream?: boolean;
71
+ /**
72
+ * What sampling temperature to use, between 0 and 2.
73
+ * Higher values (e.g., 0.8) make the output more random; lower values (e.g., 0.2) make it more focused.
74
+ * Defaults to 1.
75
+ */
76
+ temperature?: number;
77
+ /**
78
+ * An alternative to sampling with temperature, where the model considers tokens with top_p probability mass.
79
+ * E.g., 0.1 means only tokens comprising the top 10% probability mass are considered.
80
+ * Defaults to 1.
81
+ */
82
+ top_p?: number;
83
+ /**
84
+ * The maximum number of tokens to generate in the chat completion.
85
+ */
86
+ max_tokens?: number;
87
+ };
88
+
89
+ export type ChatCompletionResult = {
90
+ /**
91
+ * The generated text content from the assistant.
92
+ */
93
+ readonly content: string;
94
+ /**
95
+ * The role of the message sender, which will always be "assistant" for the model's response.
96
+ */
97
+ readonly role: "assistant";
98
+ };
99
+
100
+ export namespace ChatCompletions {
101
+ export type MessageRole = ChatCompletionsMessageRole;
102
+ export type ContentPart = ChatCompletionsMessageContent;
103
+ export type Message = ChatCompletionsMessage;
104
+ export type Options = ChatCompletionOptions;
105
+ export type Result = ChatCompletionResult;
106
+ }
@@ -0,0 +1,67 @@
1
+ export type ImageGenAspectRatio =
2
+ | "1:1"
3
+ | "16:9"
4
+ | "21:9"
5
+ | "3:2"
6
+ | "2:3"
7
+ | "4:5"
8
+ | "5:4"
9
+ | "3:4"
10
+ | "4:3"
11
+ | "9:16"
12
+ | "9:21";
13
+
14
+ export type ImageGenOptions = {
15
+ /**
16
+ * The primary text prompt describing the image to generate.
17
+ * This is a required parameter.
18
+ */
19
+ prompt: string;
20
+ /**
21
+ * Optional aspect ratio for the generated image.
22
+ * Defaults to "1:1".
23
+ * If `width` and `height` are provided, this parameter will be ignored.
24
+ */
25
+ aspect_ratio?: ImageGenAspectRatio;
26
+ /**
27
+ * Optional width of the generated image in pixels.
28
+ * If provided along with `height`, it overrides `aspect_ratio`.
29
+ */
30
+ width?: number;
31
+ /**
32
+ * Optional height of the generated image in pixels.
33
+ * If provided along with `width`, it overrides `aspect_ratio`.
34
+ */
35
+ height?: number;
36
+ /**
37
+ * Optional boolean.
38
+ * If `true`, the generated image will have a transparent background.
39
+ * Defaults to `false`.
40
+ */
41
+ transparent?: boolean;
42
+ /**
43
+ * Optional array of image inputs.
44
+ * Each object in the array should have a `url` property, which is a base64 encoded image data URL.
45
+ * Supports 1-4 input images for image-to-image generation.
46
+ */
47
+ image_inputs?: { url: string }[];
48
+ /**
49
+ * Optional seed for the image generation process.
50
+ * Using the same prompt and seed will produce variations of the same output, useful for consistent results or exploring variations.
51
+ */
52
+ seed?: number;
53
+ };
54
+
55
+ export type ImageGenResult = {
56
+ /**
57
+ * The URL of the generated image.
58
+ * This URL can be used to display the image.
59
+ */
60
+ readonly url: `https://${string}/${string}`;
61
+ };
62
+
63
+ export namespace ImageGen {
64
+ export type AspectRatio = ImageGenAspectRatio;
65
+ export type Options = ImageGenOptions;
66
+ export type Result = ImageGenResult;
67
+ }
@@ -0,0 +1,4 @@
1
+ export type * from "./chat";
2
+ export type * from "./image-gen";
3
+ export type * from "./user";
4
+ export type * from "./text-to-speech";
@@ -0,0 +1,32 @@
1
+ export type TextToSpeechOptions = {
2
+ /**
3
+ * The text string to synthesize to speech.
4
+ */
5
+ text: string;
6
+ /**
7
+ * Voice identifier (e.g., "en-male") or ElevenLabs voice ID for a specific voice.
8
+ */
9
+ voice?: string;
10
+ /**
11
+ * Desired audio format.
12
+ * Defaults to "mp3".
13
+ */
14
+ format?: "mp3" | "wav";
15
+ /**
16
+ * Playback speed multiplier.
17
+ * Typical range 0.5 - 2.0.
18
+ */
19
+ speed?: number;
20
+ /**
21
+ * Pitch adjustment in semitones.
22
+ * Typical range -12 to 12.
23
+ */
24
+ pitch?: number;
25
+ };
26
+
27
+ export type TextToSpeechResult = {
28
+ /**
29
+ * A public URL pointing to the generated audio file.
30
+ */
31
+ readonly url: `https://${string}/${string}`;
32
+ };
@@ -0,0 +1,13 @@
1
+ export type AnonymousWebsimUser = {
2
+ readonly id: "1";
3
+ readonly username: "anonymous";
4
+ readonly avatar_url: null;
5
+ };
6
+
7
+ export type WebsimUser = {
8
+ readonly id: string;
9
+ readonly username: string;
10
+ readonly avatar_url: `https://${string}/${string}` | null;
11
+ };
12
+
13
+ export type WebsimUserOrAnonymous = WebsimUser | AnonymousWebsimUser;
package/src/client.d.ts DELETED
@@ -1,106 +0,0 @@
1
- export type ChatCompletionsMessageContent =
2
- | { type: "text"; text: string }
3
- | { type: "image_url"; image_url: { url: string } };
4
-
5
- export type ChatCompletionsMessage = {
6
- role: "assistant" | "user" | "system";
7
- content: string | ChatCompletionsMessageContent[];
8
- };
9
-
10
- export type AnonymousWebsimUser = {
11
- id: "1";
12
- username: "anonymous";
13
- avatar_url: null;
14
- };
15
-
16
- export type WebsimUser = {
17
- id: string;
18
- username: string;
19
- avatar_url: `https://${string}/${string}` | null;
20
- };
21
-
22
- export type WebsimUserOrAnonymous = WebsimUser | AnonymousWebsimUser;
23
-
24
- export interface WebsimClientAPI {
25
- getUser(): Promise<WebsimUserOrAnonymous>;
26
- /** Alias for getUser */
27
- getCurrentUser(): Promise<WebsimUserOrAnonymous>;
28
- /** @deprecated Use getBootstrap instead */
29
- getDistinctId(): Promise<string>;
30
- getBootstrap(): Promise<{
31
- distinct_id: string;
32
- session_id: string;
33
- }>;
34
- getCreatedBy(): Promise<WebsimUser>;
35
- getCreator(): Promise<WebsimUser>;
36
- getCurrentProject(): Promise<{
37
- id: string;
38
- title: string;
39
- description: string;
40
- }>;
41
- getColorScheme(): Promise<"light" | "dark">;
42
-
43
- postComment({
44
- content,
45
- credits,
46
- }: {
47
- content: string;
48
- credits: number;
49
- }): Promise<{} | { error: "User has not interacted with the page" }>;
50
-
51
- addEventListener(
52
- eventType: "comment:created",
53
- callback: (data: any) => void
54
- ): () => void;
55
-
56
- upload: (file: File) => Promise<string>;
57
-
58
- chat: {
59
- completions: {
60
- create: ({
61
- messages,
62
- json,
63
- }: {
64
- messages: ChatCompletionsMessage[];
65
- json?: boolean;
66
- }) => Promise<{ role: "assistant"; content: string }>;
67
- };
68
- };
69
-
70
- imageGen: (args: {
71
- prompt: string;
72
- aspect_ratio?: string;
73
- width?: number;
74
- height?: number;
75
- seed?: number;
76
- transparent?: boolean;
77
- }) => Promise<{ url: string }>;
78
-
79
- textToSpeech: (args: {
80
- text: string;
81
- voice?: string;
82
- voice_sample?: string;
83
- }) => Promise<{ url: string }>;
84
-
85
- experimental: {
86
- v0: {
87
- login: () => Promise<void>;
88
-
89
- /**
90
- * Saves the given htmlContent to a new websim site.
91
- * @param htmlContent html content to save
92
- * @returns object with id of the saved site
93
- */
94
- save(htmlContent: string): Promise<{ id: string }>;
95
-
96
- /**
97
- * Returns the HTML for the given siteId. Defaults to the current websimsite.
98
- * @param siteId
99
- * @returns HTML for the given siteId.
100
- */
101
- getHTML(siteId?: string): Promise<string>;
102
- };
103
- };
104
-
105
- internal_only_experimental: {};
106
- }