tekimax-ts 0.1.2 → 0.1.3

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.js CHANGED
@@ -1499,7 +1499,51 @@ var userMessageItemParamSchema = import_zod103.z.object({
1499
1499
  });
1500
1500
 
1501
1501
  // src/client.ts
1502
+ var TekimaxResponse = class {
1503
+ constructor(_raw) {
1504
+ this._raw = _raw;
1505
+ }
1506
+ /**
1507
+ * Access the raw response object returned by the API.
1508
+ */
1509
+ get raw() {
1510
+ return this._raw;
1511
+ }
1512
+ /**
1513
+ * Automatically extracts the text content from the response.
1514
+ * It looks for the first "output_text" item in the response content.
1515
+ */
1516
+ get text() {
1517
+ if (!this._raw.output) return void 0;
1518
+ const textItem = this._raw.output.find(
1519
+ (item) => item.type === "output_text"
1520
+ );
1521
+ return textItem?.text;
1522
+ }
1523
+ /**
1524
+ * The ID of the response.
1525
+ */
1526
+ get id() {
1527
+ return this._raw.id ?? void 0;
1528
+ }
1529
+ /**
1530
+ * The model used to generate the response.
1531
+ */
1532
+ get model() {
1533
+ return this._raw.model ?? void 0;
1534
+ }
1535
+ };
1502
1536
  var TekimaxClient = class {
1537
+ /**
1538
+ * Creates a new TekimaxClient.
1539
+ *
1540
+ * @param options - Configuration options for the client.
1541
+ * @param options.baseUrl - The base URL of the API (default: "https://api.tekimax.com").
1542
+ * @param options.apiKey - Your Tekimax API key.
1543
+ *
1544
+ * @example
1545
+ * const client = new TekimaxClient({ apiKey: "tm_..." });
1546
+ */
1503
1547
  constructor(options = {}) {
1504
1548
  this.baseUrl = options.baseUrl || "https://api.tekimax.com";
1505
1549
  this.headers = {
@@ -1516,13 +1560,40 @@ var TekimaxClient = class {
1516
1560
  if (!response.ok) {
1517
1561
  throw new Error(`Tekimax API Error: ${response.status} ${response.statusText}`);
1518
1562
  }
1519
- return response.json();
1563
+ const data = await response.json();
1564
+ return new TekimaxResponse(data);
1520
1565
  }
1521
- async createSession(body) {
1566
+ /**
1567
+ * Creates a new session and sends the initial message.
1568
+ *
1569
+ * @param message - The initial message text to start the session.
1570
+ * @param options - Additional configuration options (model, temperature, etc.).
1571
+ *
1572
+ * @example
1573
+ * const response = await client.createSession("Hello, world!", { model: "gpt-4" });
1574
+ * console.log(response.text);
1575
+ */
1576
+ async createSession(message, options) {
1577
+ const body = {
1578
+ ...options,
1579
+ input: message
1580
+ };
1522
1581
  return this.request("/responses", body);
1523
1582
  }
1524
- async sendMessage(body) {
1525
- return this.request("/responses", body);
1583
+ /**
1584
+ * Sends a message to an existing session or starts a new one if no previous_response_id is provided.
1585
+ *
1586
+ * @param message - The message text to send.
1587
+ * @param options - Additional configuration options.
1588
+ *
1589
+ * @example
1590
+ * const response = await client.sendMessage("What is the weather?", {
1591
+ * previous_response_id: "resp_123"
1592
+ * });
1593
+ * console.log(response.text);
1594
+ */
1595
+ async sendMessage(message, options) {
1596
+ return this.createSession(message, options);
1526
1597
  }
1527
1598
  };
1528
1599
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -1286,7 +1286,51 @@ var userMessageItemParamSchema = z103.object({
1286
1286
  });
1287
1287
 
1288
1288
  // src/client.ts
1289
+ var TekimaxResponse = class {
1290
+ constructor(_raw) {
1291
+ this._raw = _raw;
1292
+ }
1293
+ /**
1294
+ * Access the raw response object returned by the API.
1295
+ */
1296
+ get raw() {
1297
+ return this._raw;
1298
+ }
1299
+ /**
1300
+ * Automatically extracts the text content from the response.
1301
+ * It looks for the first "output_text" item in the response content.
1302
+ */
1303
+ get text() {
1304
+ if (!this._raw.output) return void 0;
1305
+ const textItem = this._raw.output.find(
1306
+ (item) => item.type === "output_text"
1307
+ );
1308
+ return textItem?.text;
1309
+ }
1310
+ /**
1311
+ * The ID of the response.
1312
+ */
1313
+ get id() {
1314
+ return this._raw.id ?? void 0;
1315
+ }
1316
+ /**
1317
+ * The model used to generate the response.
1318
+ */
1319
+ get model() {
1320
+ return this._raw.model ?? void 0;
1321
+ }
1322
+ };
1289
1323
  var TekimaxClient = class {
1324
+ /**
1325
+ * Creates a new TekimaxClient.
1326
+ *
1327
+ * @param options - Configuration options for the client.
1328
+ * @param options.baseUrl - The base URL of the API (default: "https://api.tekimax.com").
1329
+ * @param options.apiKey - Your Tekimax API key.
1330
+ *
1331
+ * @example
1332
+ * const client = new TekimaxClient({ apiKey: "tm_..." });
1333
+ */
1290
1334
  constructor(options = {}) {
1291
1335
  this.baseUrl = options.baseUrl || "https://api.tekimax.com";
1292
1336
  this.headers = {
@@ -1303,13 +1347,40 @@ var TekimaxClient = class {
1303
1347
  if (!response.ok) {
1304
1348
  throw new Error(`Tekimax API Error: ${response.status} ${response.statusText}`);
1305
1349
  }
1306
- return response.json();
1350
+ const data = await response.json();
1351
+ return new TekimaxResponse(data);
1307
1352
  }
1308
- async createSession(body) {
1353
+ /**
1354
+ * Creates a new session and sends the initial message.
1355
+ *
1356
+ * @param message - The initial message text to start the session.
1357
+ * @param options - Additional configuration options (model, temperature, etc.).
1358
+ *
1359
+ * @example
1360
+ * const response = await client.createSession("Hello, world!", { model: "gpt-4" });
1361
+ * console.log(response.text);
1362
+ */
1363
+ async createSession(message, options) {
1364
+ const body = {
1365
+ ...options,
1366
+ input: message
1367
+ };
1309
1368
  return this.request("/responses", body);
1310
1369
  }
1311
- async sendMessage(body) {
1312
- return this.request("/responses", body);
1370
+ /**
1371
+ * Sends a message to an existing session or starts a new one if no previous_response_id is provided.
1372
+ *
1373
+ * @param message - The message text to send.
1374
+ * @param options - Additional configuration options.
1375
+ *
1376
+ * @example
1377
+ * const response = await client.sendMessage("What is the weather?", {
1378
+ * previous_response_id: "resp_123"
1379
+ * });
1380
+ * console.log(response.text);
1381
+ */
1382
+ async sendMessage(message, options) {
1383
+ return this.createSession(message, options);
1313
1384
  }
1314
1385
  };
1315
1386
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tekimax-ts",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Tekimax TypeScript SDK generated with Kubb",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/client.ts CHANGED
@@ -1,9 +1,72 @@
1
- import { CreateResponseBody, ResponseResource } from "./gen/types";
1
+ import { CreateResponseBody, ResponseResource, OutputTextContentParam } from "./gen/types";
2
2
 
3
+ /**
4
+ * A wrapper around the raw API response that provides helper methods
5
+ * for common tasks like extracting text content.
6
+ */
7
+ export class TekimaxResponse {
8
+ constructor(private readonly _raw: ResponseResource) { }
9
+
10
+ /**
11
+ * Access the raw response object returned by the API.
12
+ */
13
+ get raw(): ResponseResource {
14
+ return this._raw;
15
+ }
16
+
17
+ /**
18
+ * Automatically extracts the text content from the response.
19
+ * It looks for the first "output_text" item in the response content.
20
+ */
21
+ get text(): string | undefined {
22
+ if (!this._raw.output) return undefined;
23
+
24
+ // Find the first output item that is of type 'output_text'
25
+ const textItem = this._raw.output.find(
26
+ (item): item is Extract<typeof item, { type: "output_text" }> =>
27
+ item.type === "output_text"
28
+ );
29
+
30
+ return textItem?.text;
31
+ }
32
+
33
+ /**
34
+ * The ID of the response.
35
+ */
36
+ get id(): string | undefined {
37
+ return this._raw.id ?? undefined;
38
+ }
39
+
40
+ /**
41
+ * The model used to generate the response.
42
+ */
43
+ get model(): string | undefined {
44
+ return this._raw.model ?? undefined;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Options for sending a message or creating a session.
50
+ */
51
+ export type MessageOptions = Omit<CreateResponseBody, "input" | "stream">;
52
+
53
+ /**
54
+ * The main client for interacting with the Tekimax API.
55
+ */
3
56
  export class TekimaxClient {
4
57
  private baseUrl: string;
5
58
  private headers: HeadersInit;
6
59
 
60
+ /**
61
+ * Creates a new TekimaxClient.
62
+ *
63
+ * @param options - Configuration options for the client.
64
+ * @param options.baseUrl - The base URL of the API (default: "https://api.tekimax.com").
65
+ * @param options.apiKey - Your Tekimax API key.
66
+ *
67
+ * @example
68
+ * const client = new TekimaxClient({ apiKey: "tm_..." });
69
+ */
7
70
  constructor(options: { baseUrl?: string; apiKey?: string } = {}) {
8
71
  this.baseUrl = options.baseUrl || "https://api.tekimax.com";
9
72
  this.headers = {
@@ -12,7 +75,7 @@ export class TekimaxClient {
12
75
  };
13
76
  }
14
77
 
15
- private async request<T>(path: string, body: any): Promise<T> {
78
+ private async request(path: string, body: any): Promise<TekimaxResponse> {
16
79
  const response = await fetch(`${this.baseUrl}${path}`, {
17
80
  method: "POST",
18
81
  headers: this.headers,
@@ -23,14 +86,41 @@ export class TekimaxClient {
23
86
  throw new Error(`Tekimax API Error: ${response.status} ${response.statusText}`);
24
87
  }
25
88
 
26
- return response.json() as Promise<T>;
89
+ const data = await response.json() as ResponseResource;
90
+ return new TekimaxResponse(data);
27
91
  }
28
92
 
29
- async createSession(body: CreateResponseBody): Promise<ResponseResource> {
30
- return this.request<ResponseResource>("/responses", body);
93
+ /**
94
+ * Creates a new session and sends the initial message.
95
+ *
96
+ * @param message - The initial message text to start the session.
97
+ * @param options - Additional configuration options (model, temperature, etc.).
98
+ *
99
+ * @example
100
+ * const response = await client.createSession("Hello, world!", { model: "gpt-4" });
101
+ * console.log(response.text);
102
+ */
103
+ async createSession(message: string, options?: MessageOptions): Promise<TekimaxResponse> {
104
+ const body: CreateResponseBody = {
105
+ ...options,
106
+ input: message,
107
+ };
108
+ return this.request("/responses", body);
31
109
  }
32
110
 
33
- async sendMessage(body: CreateResponseBody): Promise<ResponseResource> {
34
- return this.request<ResponseResource>("/responses", body);
111
+ /**
112
+ * Sends a message to an existing session or starts a new one if no previous_response_id is provided.
113
+ *
114
+ * @param message - The message text to send.
115
+ * @param options - Additional configuration options.
116
+ *
117
+ * @example
118
+ * const response = await client.sendMessage("What is the weather?", {
119
+ * previous_response_id: "resp_123"
120
+ * });
121
+ * console.log(response.text);
122
+ */
123
+ async sendMessage(message: string, options?: MessageOptions): Promise<TekimaxResponse> {
124
+ return this.createSession(message, options);
35
125
  }
36
126
  }
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./gen/types";
2
2
  export * from "./gen/zod";
3
- export { TekimaxClient } from "./client";
3
+ export { TekimaxClient, TekimaxResponse } from "./client";