From d4cf74a5764dfe78870d0f1f93d4786837696b22 Mon Sep 17 00:00:00 2001 From: Jose Sabater Date: Fri, 28 Nov 2025 16:17:15 +0100 Subject: [PATCH 1/2] add file download endpoint --- .speakeasy/speakeasy-modifications-overlay.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.speakeasy/speakeasy-modifications-overlay.yaml b/.speakeasy/speakeasy-modifications-overlay.yaml index 4ba83f7..e281220 100644 --- a/.speakeasy/speakeasy-modifications-overlay.yaml +++ b/.speakeasy/speakeasy-modifications-overlay.yaml @@ -736,3 +736,12 @@ actions: created_at: 1732439000000 reviewed_at: 1732439000000 type: method-name + - target: $["paths"]["/knowledge/{knowledge_base_id}/files/{file_id}/download_url"]["get"] + update: + x-speakeasy-name-override: getFileDownloadUrl + x-speakeasy-metadata: + after: sdk.knowledge.getFileDownloadUrl() + before: sdk.knowledge.get_file_download_url_knowledge__knowledge_base_id__files__file_id__download_url_get() + created_at: 1732872000000 + reviewed_at: 1732872000000 + type: method-name From cac15fb8e43f9a4f5a4dcd4bac69d8eee0cdeb33 Mon Sep 17 00:00:00 2001 From: Jose Sabater Date: Fri, 28 Nov 2025 16:38:04 +0100 Subject: [PATCH 2/2] regenerate --- .speakeasy/gen.lock | 41 ++- .speakeasy/gen.yaml | 6 +- .speakeasy/workflow.lock | 12 +- docs/models/filedownloadurlresponse.md | 19 ++ docs/models/listfilesresponse.md | 19 +- ...ebaseidfilesfileiddownloadurlgetrequest.md | 20 ++ ...eknowledgebaseidregisterfilepostrequest.md | 4 + .../updatespanspansspanidpatchrequest.md | 4 +- .../paginatedresponselistfilesresponse.md | 4 + docs/models/registerfileuploadrequest.md | 7 +- docs/models/registerfileuploadresponse.md | 13 +- docs/models/updatespanrequest.md | 8 +- docs/sdks/knowledge/README.md | 83 ++++++ docs/sdks/spans/README.md | 8 +- examples/package-lock.json | 2 +- jsr.json | 2 +- package-lock.json | 4 +- package.json | 6 +- src/funcs/knowledgeGetFileDownloadUrl.ts | 209 ++++++++++++++ src/lib/config.ts | 6 +- src/lib/encodings.ts | 20 +- src/mcp-server/mcp-server.ts | 2 +- src/mcp-server/server.ts | 4 +- .../tools/knowledgeGetFileDownloadUrl.ts | 39 +++ .../chatcompletionassistantmessageparam.ts | 120 +++++--- src/models/chatcompletionmessage.ts | 48 ++-- src/models/chatcompletionnonstreaming.ts | 259 ++++++++++++------ src/models/chatcompletionstreaming.ts | 259 ++++++++++++------ src/models/chatcompletionusermessageparam.ts | 138 ++++++---- src/models/filedownloadurlresponse.ts | 70 +++++ src/models/index.ts | 1 + src/models/listfilesresponse.ts | 7 + ...chatchatcompletioncustomtoolparamcustom.ts | 45 ++- ...nowledgebaseidfilesfileiddownloadurlget.ts | 85 ++++++ src/models/operations/index.ts | 1 + src/models/registerfileuploadrequest.ts | 7 + src/models/registerfileuploadresponse.ts | 4 + src/sdk/knowledge.ts | 20 ++ src/types/unrecognized.ts | 10 +- 39 files changed, 1272 insertions(+), 344 deletions(-) create mode 100644 docs/models/filedownloadurlresponse.md create mode 100644 docs/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlgetrequest.md create mode 100644 src/funcs/knowledgeGetFileDownloadUrl.ts create mode 100644 src/mcp-server/tools/knowledgeGetFileDownloadUrl.ts create mode 100644 src/models/filedownloadurlresponse.ts create mode 100644 src/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlget.ts diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 8614b19..6f5e86d 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,18 +1,18 @@ lockVersion: 2.0.0 id: 7fd487cb-2a73-459e-99e5-2c4e6547175f management: - docChecksum: 8a701aa5036da0a2919658f49f4c88f3 + docChecksum: a460a1ebe6ede9e586a70b25d2a661ba docVersion: 2.0.0 - speakeasyVersion: 1.660.0 - generationVersion: 2.760.2 - releaseVersion: 3.3.1 - configChecksum: 18bd011b72904dd62ac5fb36d42f1066 + speakeasyVersion: 1.664.0 + generationVersion: 2.766.1 + releaseVersion: 3.3.2 + configChecksum: 8c82f1e2d056460a762ab90c9324d283 features: typescript: additionalDependencies: 0.1.0 additionalProperties: 0.1.2 constsAndDefaults: 0.1.12 - core: 3.26.9 + core: 3.26.12 defaultEnabledRetries: 0.1.0 devContainers: 2.90.1 enumUnions: 0.1.0 @@ -30,7 +30,7 @@ features: retries: 2.83.0 sdkHooks: 0.3.0 serverEvents: 0.1.12 - unions: 2.86.0 + unions: 2.86.2 generatedFiles: - .devcontainer/README.md - .devcontainer/devcontainer.json @@ -148,6 +148,7 @@ generatedFiles: - docs/models/errors/unauthorizederror.md - docs/models/example.md - docs/models/examplein.md + - docs/models/filedownloadurlresponse.md - docs/models/filefile.md - docs/models/filet.md - docs/models/filter.md @@ -217,6 +218,7 @@ generatedFiles: - docs/models/operations/getcustommodelbynamemodelscustombynamenamegetrequest.md - docs/models/operations/getcustommodelmodelscustommodelidgetrequest.md - docs/models/operations/getdatasetentrydatasetsdatasetidentriesentryidgetrequest.md + - docs/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlgetrequest.md - docs/models/operations/getfunctionbynamefunctionsbynamenamegetrequest.md - docs/models/operations/getfunctionbyrevisionfunctionsfunctionidrevisionsrevisionidgetrequest.md - docs/models/operations/getfunctionfunctionsfunctionidgetrequest.md @@ -367,6 +369,7 @@ generatedFiles: - src/funcs/knowledgeDeleteFile.ts - src/funcs/knowledgeGet.ts - src/funcs/knowledgeGetByName.ts + - src/funcs/knowledgeGetFileDownloadUrl.ts - src/funcs/knowledgeGetUploadUrl.ts - src/funcs/knowledgeList.ts - src/funcs/knowledgeListFiles.ts @@ -463,6 +466,7 @@ generatedFiles: - src/mcp-server/tools/knowledgeDeleteFile.ts - src/mcp-server/tools/knowledgeGet.ts - src/mcp-server/tools/knowledgeGetByName.ts + - src/mcp-server/tools/knowledgeGetFileDownloadUrl.ts - src/mcp-server/tools/knowledgeGetUploadUrl.ts - src/mcp-server/tools/knowledgeList.ts - src/mcp-server/tools/knowledgeListFiles.ts @@ -574,6 +578,7 @@ generatedFiles: - src/models/example.ts - src/models/examplein.ts - src/models/file.ts + - src/models/filedownloadurlresponse.ts - src/models/filefile.ts - src/models/filter.ts - src/models/functioncallconfigurationinput.ts @@ -636,6 +641,7 @@ generatedFiles: - src/models/operations/getcustommodelbynamemodelscustombynamenameget.ts - src/models/operations/getcustommodelmodelscustommodelidget.ts - src/models/operations/getdatasetentrydatasetsdatasetidentriesentryidget.ts + - src/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlget.ts - src/models/operations/getfunctionbynamefunctionsbynamenameget.ts - src/models/operations/getfunctionbyrevisionfunctionsfunctionidrevisionsrevisionidget.ts - src/models/operations/getfunctionfunctionsfunctionidget.ts @@ -1026,7 +1032,7 @@ examples: path: span_id: "77b258a2-45c1-4b87-a50c-9116bc8ed1d6" requestBody: - application/json: {"name": "my span", "start_time": "2025-11-21T16:13:26.520750Z", "type": "email_tool", "end_time": "2025-11-21T16:13:26.520845Z", "input": "Hello, world!", "output": "Hello, world!", "error": "Exception: This is an error message", "meta": {"key": "value"}, "score": 10} + application/json: {"name": "my span", "start_time": "2025-11-28T13:52:33.685136Z", "type": "email_tool", "end_time": "2025-11-28T13:52:33.685231Z", "input": "Hello, world!", "output": "Hello, world!", "error": "Exception: This is an error message", "meta": {"key": "value"}, "score": 10} responses: "200": application/json: {"name": "my span", "start_time": "2024-03-20T10:00:00+00:00", "id": "84d9ffc8-336c-4953-b92f-fe05d5405951", "trace_id": "123e4567-e89b-12d3-a456-426614174000", "parent_id": "123e4567-e89b-12d3-a456-426614174000", "type": "email_tool", "end_time": "2024-03-20T10:00:10+00:00", "input": "Hello, world!", "output": "Hello, world!", "error": "Exception: This is an error message", "meta": {"key": "value"}, "score": 10} @@ -1749,7 +1755,7 @@ examples: path: knowledge_base_id: "3c6931ec-d324-46b6-bec6-bf31a5f0623f" requestBody: - application/json: {"filename": "example.pdf", "file_id": "0dff5851-c155-4a46-8450-5b96eb017ae5", "content_type": "application/pdf"} + application/json: {"filename": "example.pdf", "file_id": "0dff5851-c155-4a46-8450-5b96eb017ae5", "content_type": "application/pdf", "metadata": {"category": "legal", "client": "acme"}} responses: "201": application/json: {"id": "8c8543c2-ed47-4e71-a474-8c7f688fd79c", "key": "", "original_filename": "", "document_id": 667726} @@ -1993,5 +1999,22 @@ examples: application/json: {"type": "NotFoundError", "message": "The resource was not found", "detail": "Span 123e4567-e89b-12d3-a456-426614174000 not found"} "422": application/json: {"type": "RequestValidationError", "message": "The request is invalid", "detail": {"input": "input value", "loc": ["path", "to", "error"], "msg": "error message", "type": "type of error"}} + get_file_download_url_knowledge__knowledge_base_id__files__file_id__download_url_get: + speakeasy-default-get-file-download-url-knowledge-knowledge-base-id-files-file-id-download-url-get: + parameters: + path: + knowledge_base_id: "3d6f9cb0-cbf2-4c9a-8995-331034439b8d" + file_id: "d917ff5b-acf0-4e5c-943a-7d584204a9f3" + responses: + "200": + application/json: {"url": "https://best-availability.name/", "expires_in": 554035} + "400": + application/json: {"type": "BadRequestError", "message": "The request is invalid", "detail": "The request is invalid"} + "401": + application/json: {"type": "UnauthorizedError", "message": "The request is unauthorized", "detail": "The API key is invalid"} + "404": + application/json: {"type": "NotFoundError", "message": "The resource was not found", "detail": "Span 123e4567-e89b-12d3-a456-426614174000 not found"} + "422": + application/json: {"type": "RequestValidationError", "message": "The request is invalid", "detail": {"input": "input value", "loc": ["path", "to", "error"], "msg": "error message", "type": "type of error"}} examplesVersion: 1.0.2 generatedTests: {} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index bf20234..f5a4630 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -29,7 +29,7 @@ generation: generateNewTests: false skipResponseBodyAssertions: false typescript: - version: 3.3.1 + version: 3.3.2 acceptHeaderEnum: true additionalDependencies: dependencies: {} @@ -54,7 +54,9 @@ typescript: exportZodModelNamespace: false flattenGlobalSecurity: true flatteningOrder: parameters-first + formStringArrayEncodeMode: encoded-string forwardCompatibleEnumsByDefault: false + forwardCompatibleUnionsByDefault: "false" generateExamples: true imports: option: openapi @@ -64,6 +66,7 @@ typescript: operations: models/operations shared: models webhooks: models/webhooks + inferUnionDiscriminators: true inputModelSuffix: input jsonpath: rfc9535 laxMode: strict @@ -71,6 +74,7 @@ typescript: methodArguments: require-security-and-request modelPropertyCasing: camel moduleFormat: dual + multipartArrayFormat: legacy outputModelSuffix: output packageName: opperai responseFormat: flat diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 2aa662e..97978d2 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,9 +1,9 @@ -speakeasyVersion: 1.660.0 +speakeasyVersion: 1.664.0 sources: FastAPI: sourceNamespace: fast-api - sourceRevisionDigest: sha256:bd3231659ba8b906113e299659f433b250ed9df2bdc5b997514a683f29ec32d4 - sourceBlobDigest: sha256:dd8abd2f9e02dd0aa2ceaae1792f85e2c2e0cdec533cb2b46976734b60aa2d5f + sourceRevisionDigest: sha256:96c05ebf50787da9b70ff351605b19d5d0ee37a6d96719e9bf18e0fea8163d7e + sourceBlobDigest: sha256:8ba1960e535cf0cc797a118bca7a9325a2dae0615250814ec9fa6f9c3faf3631 tags: - latest - 2.0.0 @@ -11,10 +11,10 @@ targets: opper: source: FastAPI sourceNamespace: fast-api - sourceRevisionDigest: sha256:bd3231659ba8b906113e299659f433b250ed9df2bdc5b997514a683f29ec32d4 - sourceBlobDigest: sha256:dd8abd2f9e02dd0aa2ceaae1792f85e2c2e0cdec533cb2b46976734b60aa2d5f + sourceRevisionDigest: sha256:96c05ebf50787da9b70ff351605b19d5d0ee37a6d96719e9bf18e0fea8163d7e + sourceBlobDigest: sha256:8ba1960e535cf0cc797a118bca7a9325a2dae0615250814ec9fa6f9c3faf3631 codeSamplesNamespace: fast-api-typescript-code-samples - codeSamplesRevisionDigest: sha256:908f1a1d5358dad84a584d2b52429cfa753bcf7052704e51c0140f7bdec02dbe + codeSamplesRevisionDigest: sha256:bb5610491dbaf2387cbcb8c6cfcae50804b90cbaa81890e0c98573c64c44542b workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/docs/models/filedownloadurlresponse.md b/docs/models/filedownloadurlresponse.md new file mode 100644 index 0000000..aacdbb9 --- /dev/null +++ b/docs/models/filedownloadurlresponse.md @@ -0,0 +1,19 @@ +# FileDownloadUrlResponse + +## Example Usage + +```typescript +import { FileDownloadUrlResponse } from "opperai/models"; + +let value: FileDownloadUrlResponse = { + url: "https://overcooked-thyme.name", + expiresIn: 13071, +}; +``` + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------- | --------------------------------------- | --------------------------------------- | --------------------------------------- | +| `url` | *string* | :heavy_check_mark: | Presigned URL to download the file | +| `expiresIn` | *number* | :heavy_check_mark: | Number of seconds until the URL expires | \ No newline at end of file diff --git a/docs/models/listfilesresponse.md b/docs/models/listfilesresponse.md index 7415b76..762b9f8 100644 --- a/docs/models/listfilesresponse.md +++ b/docs/models/listfilesresponse.md @@ -11,15 +11,20 @@ let value: ListFilesResponse = { size: 351349, status: "", documentId: 118298, + metadata: { + "category": "legal", + "client": "acme", + }, }; ``` ## Fields -| Field | Type | Required | Description | -| --------------------------------- | --------------------------------- | --------------------------------- | --------------------------------- | -| `id` | *string* | :heavy_check_mark: | The id of the file | -| `originalFilename` | *string* | :heavy_check_mark: | The original filename | -| `size` | *number* | :heavy_check_mark: | The size of the file in bytes | -| `status` | *string* | :heavy_check_mark: | The indexing status of the file | -| `documentId` | *number* | :heavy_check_mark: | The id of the associated document | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | ----------------------------------------- | +| `id` | *string* | :heavy_check_mark: | The id of the file | | +| `originalFilename` | *string* | :heavy_check_mark: | The original filename | | +| `size` | *number* | :heavy_check_mark: | The size of the file in bytes | | +| `status` | *string* | :heavy_check_mark: | The indexing status of the file | | +| `documentId` | *number* | :heavy_check_mark: | The id of the associated document | | +| `metadata` | Record | :heavy_minus_sign: | The metadata attached to the file | {
"category": "legal",
"client": "acme"
} | \ No newline at end of file diff --git a/docs/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlgetrequest.md b/docs/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlgetrequest.md new file mode 100644 index 0000000..01f1a87 --- /dev/null +++ b/docs/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlgetrequest.md @@ -0,0 +1,20 @@ +# GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest + +## Example Usage + +```typescript +import { GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest } from "opperai/models/operations"; + +let value: + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest = { + knowledgeBaseId: "a52ff0c1-a1ef-4bb7-939a-bd9357631e39", + fileId: "728e40e6-0612-4027-8f0c-cf4e079a288b", + }; +``` + +## Fields + +| Field | Type | Required | Description | +| ---------------------------- | ---------------------------- | ---------------------------- | ---------------------------- | +| `knowledgeBaseId` | *string* | :heavy_check_mark: | The id of the knowledge base | +| `fileId` | *string* | :heavy_check_mark: | The id of the file | \ No newline at end of file diff --git a/docs/models/operations/registerfileuploadknowledgeknowledgebaseidregisterfilepostrequest.md b/docs/models/operations/registerfileuploadknowledgeknowledgebaseidregisterfilepostrequest.md index 3785e7e..343d0d8 100644 --- a/docs/models/operations/registerfileuploadknowledgeknowledgebaseidregisterfilepostrequest.md +++ b/docs/models/operations/registerfileuploadknowledgeknowledgebaseidregisterfilepostrequest.md @@ -11,6 +11,10 @@ let value: RegisterFileUploadKnowledgeKnowledgeBaseIdRegisterFilePostRequest = { filename: "example.pdf", fileId: "1ea8fd4c-c52c-4100-8653-01ab93359ed1", contentType: "application/pdf", + metadata: { + "category": "legal", + "client": "acme", + }, }, }; ``` diff --git a/docs/models/operations/updatespanspansspanidpatchrequest.md b/docs/models/operations/updatespanspansspanidpatchrequest.md index deb7372..c18738c 100644 --- a/docs/models/operations/updatespanspansspanidpatchrequest.md +++ b/docs/models/operations/updatespanspansspanidpatchrequest.md @@ -9,9 +9,9 @@ let value: UpdateSpanSpansSpanIdPatchRequest = { spanId: "c4686ca8-5f9f-483e-8cc2-e12731bcf9e5", updateSpanRequest: { name: "my span", - startTime: new Date("2025-11-21T16:13:26.520750Z"), + startTime: new Date("2025-11-28T13:52:33.685136Z"), type: "email_tool", - endTime: new Date("2025-11-21T16:13:26.520845Z"), + endTime: new Date("2025-11-28T13:52:33.685231Z"), input: "Hello, world!", output: "Hello, world!", error: "Exception: This is an error message", diff --git a/docs/models/paginatedresponselistfilesresponse.md b/docs/models/paginatedresponselistfilesresponse.md index c1b57a6..bb112ee 100644 --- a/docs/models/paginatedresponselistfilesresponse.md +++ b/docs/models/paginatedresponselistfilesresponse.md @@ -16,6 +16,10 @@ let value: PaginatedResponseListFilesResponse = { size: 283826, status: "", documentId: 185150, + metadata: { + "category": "legal", + "client": "acme", + }, }, ], }; diff --git a/docs/models/registerfileuploadrequest.md b/docs/models/registerfileuploadrequest.md index d82a66a..52da8bf 100644 --- a/docs/models/registerfileuploadrequest.md +++ b/docs/models/registerfileuploadrequest.md @@ -9,6 +9,10 @@ let value: RegisterFileUploadRequest = { filename: "example.pdf", fileId: "a6985676-1a18-4da3-8dc0-13029ff25547", contentType: "application/pdf", + metadata: { + "category": "legal", + "client": "acme", + }, }; ``` @@ -19,4 +23,5 @@ let value: RegisterFileUploadRequest = { | `filename` | *string* | :heavy_check_mark: | The filename of the file to register | example.pdf | | `fileId` | *string* | :heavy_check_mark: | The id of the file to register | | | `contentType` | *string* | :heavy_check_mark: | The content type of the file to register | application/pdf | -| `configuration` | [models.TextProcessingConfiguration](../models/textprocessingconfiguration.md) | :heavy_minus_sign: | The configuration for the file to register | | \ No newline at end of file +| `configuration` | [models.TextProcessingConfiguration](../models/textprocessingconfiguration.md) | :heavy_minus_sign: | The configuration for the file to register | | +| `metadata` | Record | :heavy_minus_sign: | Optional metadata to attach to the file | {
"category": "legal",
"client": "acme"
} | \ No newline at end of file diff --git a/docs/models/registerfileuploadresponse.md b/docs/models/registerfileuploadresponse.md index ddf4e8b..fc51b7a 100644 --- a/docs/models/registerfileuploadresponse.md +++ b/docs/models/registerfileuploadresponse.md @@ -15,9 +15,10 @@ let value: RegisterFileUploadResponse = { ## Fields -| Field | Type | Required | Description | -| ------------------ | ------------------ | ------------------ | ------------------ | -| `id` | *string* | :heavy_check_mark: | N/A | -| `key` | *string* | :heavy_check_mark: | N/A | -| `originalFilename` | *string* | :heavy_check_mark: | N/A | -| `documentId` | *number* | :heavy_check_mark: | N/A | \ No newline at end of file +| Field | Type | Required | Description | +| --------------------- | --------------------- | --------------------- | --------------------- | +| `id` | *string* | :heavy_check_mark: | N/A | +| `key` | *string* | :heavy_check_mark: | N/A | +| `originalFilename` | *string* | :heavy_check_mark: | N/A | +| `documentId` | *number* | :heavy_check_mark: | N/A | +| `metadata` | Record | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/updatespanrequest.md b/docs/models/updatespanrequest.md index c65f6ce..13b5706 100644 --- a/docs/models/updatespanrequest.md +++ b/docs/models/updatespanrequest.md @@ -7,9 +7,9 @@ import { UpdateSpanRequest } from "opperai/models"; let value: UpdateSpanRequest = { name: "my span", - startTime: new Date("2025-11-21T16:13:26.520750Z"), + startTime: new Date("2025-11-28T13:52:33.685136Z"), type: "email_tool", - endTime: new Date("2025-11-21T16:13:26.520845Z"), + endTime: new Date("2025-11-28T13:52:33.685231Z"), input: "Hello, world!", output: "Hello, world!", error: "Exception: This is an error message", @@ -25,9 +25,9 @@ let value: UpdateSpanRequest = { | Field | Type | Required | Description | Example | | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | | `name` | *string* | :heavy_minus_sign: | The name of the span, something descriptive about the span that will be used to identify it when querying | my span | -| `startTime` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) | :heavy_minus_sign: | The start time of the span in UTC | 2025-11-21T16:13:26.520750Z | +| `startTime` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) | :heavy_minus_sign: | The start time of the span in UTC | 2025-11-28T13:52:33.685136Z | | `type` | *string* | :heavy_minus_sign: | The type of the span | email_tool | -| `endTime` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) | :heavy_minus_sign: | The end time of the span in UTC | 2025-11-21T16:13:26.520845Z | +| `endTime` | [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) | :heavy_minus_sign: | The end time of the span in UTC | 2025-11-28T13:52:33.685231Z | | `input` | *string* | :heavy_minus_sign: | The input of the span | Hello, world! | | `output` | *string* | :heavy_minus_sign: | The output of the span | Hello, world! | | `error` | *string* | :heavy_minus_sign: | In case of an error, the error message | Exception: This is an error message | diff --git a/docs/sdks/knowledge/README.md b/docs/sdks/knowledge/README.md index 7d70494..5c4e855 100644 --- a/docs/sdks/knowledge/README.md +++ b/docs/sdks/knowledge/README.md @@ -13,6 +13,7 @@ * [getUploadUrl](#getuploadurl) - Get Upload Url * [registerFileUpload](#registerfileupload) - Register File Upload * [deleteFile](#deletefile) - Delete File From Knowledge Base +* [getFileDownloadUrl](#getfiledownloadurl) - Get File Download Url * [listFiles](#listfiles) - List Files * [query](#query) - Query Knowledge Base * [deleteDocuments](#deletedocuments) - Delete Documents @@ -491,6 +492,10 @@ async function run() { filename: "example.pdf", fileId: "0dff5851-c155-4a46-8450-5b96eb017ae5", contentType: "application/pdf", + metadata: { + "category": "legal", + "client": "acme", + }, }); console.log(result); @@ -518,6 +523,10 @@ async function run() { filename: "example.pdf", fileId: "0dff5851-c155-4a46-8450-5b96eb017ae5", contentType: "application/pdf", + metadata: { + "category": "legal", + "client": "acme", + }, }); if (res.ok) { const { value: result } = res; @@ -628,6 +637,80 @@ run(); | errors.RequestValidationError | 422 | application/json | | errors.APIError | 4XX, 5XX | \*/\* | +## getFileDownloadUrl + +Get a presigned URL to download a file from a knowledge base + +### Example Usage + + +```typescript +import { Opper } from "opperai"; + +const opper = new Opper({ + httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", +}); + +async function run() { + const result = await opper.knowledge.getFileDownloadUrl("3d6f9cb0-cbf2-4c9a-8995-331034439b8d", "d917ff5b-acf0-4e5c-943a-7d584204a9f3"); + + console.log(result); +} + +run(); +``` + +### Standalone function + +The standalone function version of this method: + +```typescript +import { OpperCore } from "opperai/core.js"; +import { knowledgeGetFileDownloadUrl } from "opperai/funcs/knowledgeGetFileDownloadUrl.js"; + +// Use `OpperCore` for best tree-shaking performance. +// You can create one instance of it to use across an application. +const opper = new OpperCore({ + httpBearer: process.env["OPPER_HTTP_BEARER"] ?? "", +}); + +async function run() { + const res = await knowledgeGetFileDownloadUrl(opper, "3d6f9cb0-cbf2-4c9a-8995-331034439b8d", "d917ff5b-acf0-4e5c-943a-7d584204a9f3"); + if (res.ok) { + const { value: result } = res; + console.log(result); + } else { + console.log("knowledgeGetFileDownloadUrl failed:", res.error); + } +} + +run(); +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `knowledgeBaseId` | *string* | :heavy_check_mark: | The id of the knowledge base | +| `fileId` | *string* | :heavy_check_mark: | The id of the file | +| `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. | +| `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. | +| `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. | + +### Response + +**Promise\<[models.FileDownloadUrlResponse](../../models/filedownloadurlresponse.md)\>** + +### Errors + +| Error Type | Status Code | Content Type | +| ----------------------------- | ----------------------------- | ----------------------------- | +| errors.BadRequestError | 400 | application/json | +| errors.UnauthorizedError | 401 | application/json | +| errors.NotFoundError | 404 | application/json | +| errors.RequestValidationError | 422 | application/json | +| errors.APIError | 4XX, 5XX | \*/\* | + ## listFiles List all files in a knowledge base diff --git a/docs/sdks/spans/README.md b/docs/sdks/spans/README.md index ebe4830..bddddbb 100644 --- a/docs/sdks/spans/README.md +++ b/docs/sdks/spans/README.md @@ -204,9 +204,9 @@ const opper = new Opper({ async function run() { const result = await opper.spans.update("77b258a2-45c1-4b87-a50c-9116bc8ed1d6", { name: "my span", - startTime: new Date("2025-11-21T16:13:26.520750Z"), + startTime: new Date("2025-11-28T13:52:33.685136Z"), type: "email_tool", - endTime: new Date("2025-11-21T16:13:26.520845Z"), + endTime: new Date("2025-11-28T13:52:33.685231Z"), input: "Hello, world!", output: "Hello, world!", error: "Exception: This is an error message", @@ -239,9 +239,9 @@ const opper = new OpperCore({ async function run() { const res = await spansUpdate(opper, "77b258a2-45c1-4b87-a50c-9116bc8ed1d6", { name: "my span", - startTime: new Date("2025-11-21T16:13:26.520750Z"), + startTime: new Date("2025-11-28T13:52:33.685136Z"), type: "email_tool", - endTime: new Date("2025-11-21T16:13:26.520845Z"), + endTime: new Date("2025-11-28T13:52:33.685231Z"), input: "Hello, world!", output: "Hello, world!", error: "Exception: This is an error message", diff --git a/examples/package-lock.json b/examples/package-lock.json index 47ac1c7..6d60226 100644 --- a/examples/package-lock.json +++ b/examples/package-lock.json @@ -18,7 +18,7 @@ }, "..": { "name": "opperai", - "version": "3.3.1", + "version": "3.3.2", "dependencies": { "@modelcontextprotocol/sdk": ">=1.5.0 <1.10.0", "zod": "^3.25.0 || ^4.0.0" diff --git a/jsr.json b/jsr.json index 37e7ed7..dd2e2eb 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "opperai", - "version": "3.3.1", + "version": "3.3.2", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index d31922d..695925b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opperai", - "version": "3.3.1", + "version": "3.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opperai", - "version": "3.3.1", + "version": "3.3.2", "dependencies": { "@modelcontextprotocol/sdk": ">=1.5.0 <1.10.0", "zod": "^3.25.0 || ^4.0.0" diff --git a/package.json b/package.json index f0b6e30..2b146bd 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "opperai", - "version": "3.3.1", + "version": "3.3.2", "author": "Speakeasy", "repository": { - "type": "git", - "url": "https://github.com/opper-ai/opper-node" + "url": "https://github.com/opper-ai/opper-node", + "type": "git" }, "type": "module", "bin": { diff --git a/src/funcs/knowledgeGetFileDownloadUrl.ts b/src/funcs/knowledgeGetFileDownloadUrl.ts new file mode 100644 index 0000000..ee124c2 --- /dev/null +++ b/src/funcs/knowledgeGetFileDownloadUrl.ts @@ -0,0 +1,209 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { OpperCore } from "../core.js"; +import { encodeSimple } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { OpperError } from "../models/errors/oppererror.js"; +import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as models from "../models/index.js"; +import * as operations from "../models/operations/index.js"; +import { APICall, APIPromise } from "../types/async.js"; +import { Result } from "../types/fp.js"; + +/** + * Get File Download Url + * + * @remarks + * Get a presigned URL to download a file from a knowledge base + */ +export function knowledgeGetFileDownloadUrl( + client: OpperCore, + knowledgeBaseId: string, + fileId: string, + options?: RequestOptions, +): APIPromise< + Result< + models.FileDownloadUrlResponse, + | errors.BadRequestError + | errors.UnauthorizedError + | errors.NotFoundError + | errors.RequestValidationError + | OpperError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + > +> { + return new APIPromise($do( + client, + knowledgeBaseId, + fileId, + options, + )); +} + +async function $do( + client: OpperCore, + knowledgeBaseId: string, + fileId: string, + options?: RequestOptions, +): Promise< + [ + Result< + models.FileDownloadUrlResponse, + | errors.BadRequestError + | errors.UnauthorizedError + | errors.NotFoundError + | errors.RequestValidationError + | OpperError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >, + APICall, + ] +> { + const input: + operations.GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest = + { + knowledgeBaseId: knowledgeBaseId, + fileId: fileId, + }; + + const parsed = safeParse( + input, + (value) => + operations + .GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$outboundSchema + .parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return [parsed, { status: "invalid" }]; + } + const payload = parsed.value; + const body = null; + + const pathParams = { + file_id: encodeSimple("file_id", payload.file_id, { + explode: false, + charEncoding: "percent", + }), + knowledge_base_id: encodeSimple( + "knowledge_base_id", + payload.knowledge_base_id, + { explode: false, charEncoding: "percent" }, + ), + }; + + const path = pathToFunc( + "/knowledge/{knowledge_base_id}/files/{file_id}/download_url", + )(pathParams); + + const headers = new Headers(compactMap({ + Accept: "application/json", + })); + + const secConfig = await extractSecurity(client._options.httpBearer); + const securityInput = secConfig == null ? {} : { httpBearer: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + options: client._options, + baseURL: options?.serverURL ?? client._baseURL ?? "", + operationID: + "get_file_download_url_knowledge__knowledge_base_id__files__file_id__download_url_get", + oAuth2Scopes: null, + + resolvedSecurity: requestSecurity, + + securitySource: client._options.httpBearer, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path: path, + headers: headers, + body: body, + userAgent: client._options.userAgent, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return [requestRes, { status: "invalid" }]; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: ["400", "401", "404", "422", "4XX", "5XX"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return [doResult, { status: "request-error", request: req }]; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + models.FileDownloadUrlResponse, + | errors.BadRequestError + | errors.UnauthorizedError + | errors.NotFoundError + | errors.RequestValidationError + | OpperError + | ResponseValidationError + | ConnectionError + | RequestAbortedError + | RequestTimeoutError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError + >( + M.json(200, models.FileDownloadUrlResponse$inboundSchema), + M.jsonErr(400, errors.BadRequestError$inboundSchema), + M.jsonErr(401, errors.UnauthorizedError$inboundSchema), + M.jsonErr(404, errors.NotFoundError$inboundSchema), + M.jsonErr(422, errors.RequestValidationError$inboundSchema), + M.fail("4XX"), + M.fail("5XX"), + )(response, req, { extraFields: responseFields }); + if (!result.ok) { + return [result, { status: "complete", request: req, response }]; + } + + return [result, { status: "complete", request: req, response }]; +} diff --git a/src/lib/config.ts b/src/lib/config.ts index 3b93d67..cc3a497 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -61,7 +61,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "2.0.0", - sdkVersion: "3.3.1", - genVersion: "2.760.2", - userAgent: "speakeasy-sdk/typescript 3.3.1 2.760.2 2.0.0 opperai", + sdkVersion: "3.3.2", + genVersion: "2.766.1", + userAgent: "speakeasy-sdk/typescript 3.3.2 2.766.1 2.0.0 opperai", } as const; diff --git a/src/lib/encodings.ts b/src/lib/encodings.ts index 25c9dcb..31cd373 100644 --- a/src/lib/encodings.ts +++ b/src/lib/encodings.ts @@ -102,8 +102,9 @@ export function encodeLabel( }); encValue = mapped?.join("").slice(1); } else { - const k = - options?.explode && isPlainObject(value) ? `${encodeString(pk)}=` : ""; + const k = options?.explode && isPlainObject(value) + ? `${encodeString(pk)}=` + : ""; encValue = `${k}${encodeValue(pv)}`; } @@ -426,6 +427,7 @@ export function queryJoin(...args: (string | undefined)[]): string { type QueryEncoderOptions = { explode?: boolean; charEncoding?: "percent" | "none"; + allowEmptyValue?: string[]; }; type QueryEncoder = ( @@ -440,7 +442,7 @@ type BulkQueryEncoder = ( ) => string; export function queryEncoder(f: QueryEncoder): BulkQueryEncoder { - const bulkEncode = function ( + const bulkEncode = function( values: Record, options?: QueryEncoderOptions, ): string { @@ -450,7 +452,19 @@ export function queryEncoder(f: QueryEncoder): BulkQueryEncoder { charEncoding: options?.charEncoding ?? "percent", }; + const allowEmptySet = new Set(options?.allowEmptyValue ?? []); + const encoded = Object.entries(values).map(([key, value]) => { + if (allowEmptySet.has(key)) { + if ( + value === undefined + || value === null + || value === "" + || (Array.isArray(value) && value.length === 0) + ) { + return `${encodeURIComponent(key)}=`; + } + } return f(key, value, opts); }); return queryJoin(...encoded); diff --git a/src/mcp-server/mcp-server.ts b/src/mcp-server/mcp-server.ts index f70c36c..9e16bd2 100644 --- a/src/mcp-server/mcp-server.ts +++ b/src/mcp-server/mcp-server.ts @@ -19,7 +19,7 @@ const routes = buildRouteMap({ export const app = buildApplication(routes, { name: "mcp", versionInfo: { - currentVersion: "3.3.1", + currentVersion: "3.3.2", }, }); diff --git a/src/mcp-server/server.ts b/src/mcp-server/server.ts index c043cdb..7094523 100644 --- a/src/mcp-server/server.ts +++ b/src/mcp-server/server.ts @@ -41,6 +41,7 @@ import { tool$knowledgeDeleteDocuments } from "./tools/knowledgeDeleteDocuments. import { tool$knowledgeDeleteFile } from "./tools/knowledgeDeleteFile.js"; import { tool$knowledgeGet } from "./tools/knowledgeGet.js"; import { tool$knowledgeGetByName } from "./tools/knowledgeGetByName.js"; +import { tool$knowledgeGetFileDownloadUrl } from "./tools/knowledgeGetFileDownloadUrl.js"; import { tool$knowledgeGetUploadUrl } from "./tools/knowledgeGetUploadUrl.js"; import { tool$knowledgeList } from "./tools/knowledgeList.js"; import { tool$knowledgeListFiles } from "./tools/knowledgeListFiles.js"; @@ -86,7 +87,7 @@ export function createMCPServer(deps: { }) { const server = new McpServer({ name: "Opper", - version: "3.3.1", + version: "3.3.2", }); const client = new OpperCore({ @@ -126,6 +127,7 @@ export function createMCPServer(deps: { tool(tool$knowledgeGetUploadUrl); tool(tool$knowledgeRegisterFileUpload); tool(tool$knowledgeDeleteFile); + tool(tool$knowledgeGetFileDownloadUrl); tool(tool$knowledgeListFiles); tool(tool$knowledgeQuery); tool(tool$knowledgeDeleteDocuments); diff --git a/src/mcp-server/tools/knowledgeGetFileDownloadUrl.ts b/src/mcp-server/tools/knowledgeGetFileDownloadUrl.ts new file mode 100644 index 0000000..bf28357 --- /dev/null +++ b/src/mcp-server/tools/knowledgeGetFileDownloadUrl.ts @@ -0,0 +1,39 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod/v3"; +import { knowledgeGetFileDownloadUrl } from "../../funcs/knowledgeGetFileDownloadUrl.js"; +import { formatResult, ToolDefinition } from "../tools.js"; + +const args = { + knowledgeBaseId: z.string(), + fileId: z.string(), +}; + +export const tool$knowledgeGetFileDownloadUrl: ToolDefinition = { + name: "knowledge-get-file-download-url", + description: `Get File Download Url + +Get a presigned URL to download a file from a knowledge base`, + args, + tool: async (client, args, ctx) => { + const [result, apiCall] = await knowledgeGetFileDownloadUrl( + client, + args.knowledgeBaseId, + args.fileId, + { fetchOptions: { signal: ctx.signal } }, + ).$inspect(); + + if (!result.ok) { + return { + content: [{ type: "text", text: result.error.message }], + isError: true, + }; + } + + const value = result.value; + + return formatResult(value, apiCall); + }, +}; diff --git a/src/models/chatcompletionassistantmessageparam.ts b/src/models/chatcompletionassistantmessageparam.ts index a6504e1..945723b 100644 --- a/src/models/chatcompletionassistantmessageparam.ts +++ b/src/models/chatcompletionassistantmessageparam.ts @@ -45,18 +45,19 @@ import { } from "./functioncallinput.js"; export type ChatCompletionAssistantMessageParamContent1 = - | ChatCompletionContentPartTextParam - | ChatCompletionContentPartRefusalParam; + | (ChatCompletionContentPartTextParam & { type: "text" }) + | (ChatCompletionContentPartRefusalParam & { type: "refusal" }); export type ChatCompletionAssistantMessageParamContent2 = | string | Array< - ChatCompletionContentPartTextParam | ChatCompletionContentPartRefusalParam + | (ChatCompletionContentPartTextParam & { type: "text" }) + | (ChatCompletionContentPartRefusalParam & { type: "refusal" }) >; export type ChatCompletionAssistantMessageParamToolCall = - | ChatCompletionMessageFunctionToolCallParam - | ChatCompletionMessageCustomToolCallParam; + | (ChatCompletionMessageFunctionToolCallParam & { type: "function" }) + | (ChatCompletionMessageCustomToolCallParam & { type: "custom" }); export type ChatCompletionAssistantMessageParam = { role?: "assistant" | undefined; @@ -64,7 +65,8 @@ export type ChatCompletionAssistantMessageParam = { content?: | string | Array< - ChatCompletionContentPartTextParam | ChatCompletionContentPartRefusalParam + | (ChatCompletionContentPartTextParam & { type: "text" }) + | (ChatCompletionContentPartRefusalParam & { type: "refusal" }) > | null | undefined; @@ -73,8 +75,8 @@ export type ChatCompletionAssistantMessageParam = { refusal?: string | null | undefined; toolCalls?: | Array< - | ChatCompletionMessageFunctionToolCallParam - | ChatCompletionMessageCustomToolCallParam + | (ChatCompletionMessageFunctionToolCallParam & { type: "function" }) + | (ChatCompletionMessageCustomToolCallParam & { type: "custom" }) > | undefined; }; @@ -86,13 +88,17 @@ export const ChatCompletionAssistantMessageParamContent1$inboundSchema: z.ZodTypeDef, unknown > = z.union([ - ChatCompletionContentPartTextParam$inboundSchema, - ChatCompletionContentPartRefusalParam$inboundSchema, + ChatCompletionContentPartTextParam$inboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartRefusalParam$inboundSchema.and( + z.object({ type: z.literal("refusal") }), + ), ]); /** @internal */ export type ChatCompletionAssistantMessageParamContent1$Outbound = - | ChatCompletionContentPartTextParam$Outbound - | ChatCompletionContentPartRefusalParam$Outbound; + | (ChatCompletionContentPartTextParam$Outbound & { type: "text" }) + | (ChatCompletionContentPartRefusalParam$Outbound & { type: "refusal" }); /** @internal */ export const ChatCompletionAssistantMessageParamContent1$outboundSchema: @@ -101,8 +107,12 @@ export const ChatCompletionAssistantMessageParamContent1$outboundSchema: z.ZodTypeDef, ChatCompletionAssistantMessageParamContent1 > = z.union([ - ChatCompletionContentPartTextParam$outboundSchema, - ChatCompletionContentPartRefusalParam$outboundSchema, + ChatCompletionContentPartTextParam$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartRefusalParam$outboundSchema.and( + z.object({ type: z.literal("refusal") }), + ), ]); export function chatCompletionAssistantMessageParamContent1ToJSON( @@ -141,8 +151,12 @@ export const ChatCompletionAssistantMessageParamContent2$inboundSchema: z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$inboundSchema, - ChatCompletionContentPartRefusalParam$inboundSchema, + ChatCompletionContentPartTextParam$inboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartRefusalParam$inboundSchema.and( + z.object({ type: z.literal("refusal") }), + ), ]), ), ]); @@ -150,8 +164,8 @@ export const ChatCompletionAssistantMessageParamContent2$inboundSchema: export type ChatCompletionAssistantMessageParamContent2$Outbound = | string | Array< - | ChatCompletionContentPartTextParam$Outbound - | ChatCompletionContentPartRefusalParam$Outbound + | (ChatCompletionContentPartTextParam$Outbound & { type: "text" }) + | (ChatCompletionContentPartRefusalParam$Outbound & { type: "refusal" }) >; /** @internal */ @@ -164,8 +178,12 @@ export const ChatCompletionAssistantMessageParamContent2$outboundSchema: z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$outboundSchema, - ChatCompletionContentPartRefusalParam$outboundSchema, + ChatCompletionContentPartTextParam$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartRefusalParam$outboundSchema.and( + z.object({ type: z.literal("refusal") }), + ), ]), ), ]); @@ -203,13 +221,17 @@ export const ChatCompletionAssistantMessageParamToolCall$inboundSchema: z.ZodTypeDef, unknown > = z.union([ - ChatCompletionMessageFunctionToolCallParam$inboundSchema, - ChatCompletionMessageCustomToolCallParam$inboundSchema, + ChatCompletionMessageFunctionToolCallParam$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCallParam$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); /** @internal */ export type ChatCompletionAssistantMessageParamToolCall$Outbound = - | ChatCompletionMessageFunctionToolCallParam$Outbound - | ChatCompletionMessageCustomToolCallParam$Outbound; + | (ChatCompletionMessageFunctionToolCallParam$Outbound & { type: "function" }) + | (ChatCompletionMessageCustomToolCallParam$Outbound & { type: "custom" }); /** @internal */ export const ChatCompletionAssistantMessageParamToolCall$outboundSchema: @@ -218,8 +240,12 @@ export const ChatCompletionAssistantMessageParamToolCall$outboundSchema: z.ZodTypeDef, ChatCompletionAssistantMessageParamToolCall > = z.union([ - ChatCompletionMessageFunctionToolCallParam$outboundSchema, - ChatCompletionMessageCustomToolCallParam$outboundSchema, + ChatCompletionMessageFunctionToolCallParam$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCallParam$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); export function chatCompletionAssistantMessageParamToolCallToJSON( @@ -261,8 +287,12 @@ export const ChatCompletionAssistantMessageParam$inboundSchema: z.ZodType< z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$inboundSchema, - ChatCompletionContentPartRefusalParam$inboundSchema, + ChatCompletionContentPartTextParam$inboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartRefusalParam$inboundSchema.and( + z.object({ type: z.literal("refusal") }), + ), ]), ), ]), @@ -272,8 +302,12 @@ export const ChatCompletionAssistantMessageParam$inboundSchema: z.ZodType< refusal: z.nullable(z.string()).optional(), tool_calls: z.array( z.union([ - ChatCompletionMessageFunctionToolCallParam$inboundSchema, - ChatCompletionMessageCustomToolCallParam$inboundSchema, + ChatCompletionMessageFunctionToolCallParam$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCallParam$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ).optional(), }).transform((v) => { @@ -289,8 +323,8 @@ export type ChatCompletionAssistantMessageParam$Outbound = { content?: | string | Array< - | ChatCompletionContentPartTextParam$Outbound - | ChatCompletionContentPartRefusalParam$Outbound + | (ChatCompletionContentPartTextParam$Outbound & { type: "text" }) + | (ChatCompletionContentPartRefusalParam$Outbound & { type: "refusal" }) > | null | undefined; @@ -299,8 +333,10 @@ export type ChatCompletionAssistantMessageParam$Outbound = { refusal?: string | null | undefined; tool_calls?: | Array< - | ChatCompletionMessageFunctionToolCallParam$Outbound - | ChatCompletionMessageCustomToolCallParam$Outbound + | (ChatCompletionMessageFunctionToolCallParam$Outbound & { + type: "function"; + }) + | (ChatCompletionMessageCustomToolCallParam$Outbound & { type: "custom" }) > | undefined; }; @@ -318,8 +354,12 @@ export const ChatCompletionAssistantMessageParam$outboundSchema: z.ZodType< z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$outboundSchema, - ChatCompletionContentPartRefusalParam$outboundSchema, + ChatCompletionContentPartTextParam$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartRefusalParam$outboundSchema.and( + z.object({ type: z.literal("refusal") }), + ), ]), ), ]), @@ -329,8 +369,12 @@ export const ChatCompletionAssistantMessageParam$outboundSchema: z.ZodType< refusal: z.nullable(z.string()).optional(), toolCalls: z.array( z.union([ - ChatCompletionMessageFunctionToolCallParam$outboundSchema, - ChatCompletionMessageCustomToolCallParam$outboundSchema, + ChatCompletionMessageFunctionToolCallParam$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCallParam$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ).optional(), }).transform((v) => { diff --git a/src/models/chatcompletionmessage.ts b/src/models/chatcompletionmessage.ts index aac087d..29315d0 100644 --- a/src/models/chatcompletionmessage.ts +++ b/src/models/chatcompletionmessage.ts @@ -42,8 +42,8 @@ import { } from "./functioncalloutput.js"; export type ChatCompletionMessageToolCall = - | ChatCompletionMessageFunctionToolCall - | ChatCompletionMessageCustomToolCall; + | (ChatCompletionMessageFunctionToolCall & { type: "function" }) + | (ChatCompletionMessageCustomToolCall & { type: "custom" }); export type ChatCompletionMessage = { content?: string | null | undefined; @@ -54,8 +54,8 @@ export type ChatCompletionMessage = { functionCall?: FunctionCallOutput | null | undefined; toolCalls?: | Array< - | ChatCompletionMessageFunctionToolCall - | ChatCompletionMessageCustomToolCall + | (ChatCompletionMessageFunctionToolCall & { type: "function" }) + | (ChatCompletionMessageCustomToolCall & { type: "custom" }) > | null | undefined; @@ -68,13 +68,17 @@ export const ChatCompletionMessageToolCall$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ChatCompletionMessageFunctionToolCall$inboundSchema, - ChatCompletionMessageCustomToolCall$inboundSchema, + ChatCompletionMessageFunctionToolCall$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCall$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); /** @internal */ export type ChatCompletionMessageToolCall$Outbound = - | ChatCompletionMessageFunctionToolCall$Outbound - | ChatCompletionMessageCustomToolCall$Outbound; + | (ChatCompletionMessageFunctionToolCall$Outbound & { type: "function" }) + | (ChatCompletionMessageCustomToolCall$Outbound & { type: "custom" }); /** @internal */ export const ChatCompletionMessageToolCall$outboundSchema: z.ZodType< @@ -82,8 +86,12 @@ export const ChatCompletionMessageToolCall$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionMessageToolCall > = z.union([ - ChatCompletionMessageFunctionToolCall$outboundSchema, - ChatCompletionMessageCustomToolCall$outboundSchema, + ChatCompletionMessageFunctionToolCall$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCall$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); export function chatCompletionMessageToolCallToJSON( @@ -121,8 +129,12 @@ export const ChatCompletionMessage$inboundSchema: z.ZodType< tool_calls: z.nullable( z.array( z.union([ - ChatCompletionMessageFunctionToolCall$inboundSchema, - ChatCompletionMessageCustomToolCall$inboundSchema, + ChatCompletionMessageFunctionToolCall$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCall$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ), ).optional(), @@ -145,8 +157,8 @@ export type ChatCompletionMessage$Outbound = { function_call?: FunctionCallOutput$Outbound | null | undefined; tool_calls?: | Array< - | ChatCompletionMessageFunctionToolCall$Outbound - | ChatCompletionMessageCustomToolCall$Outbound + | (ChatCompletionMessageFunctionToolCall$Outbound & { type: "function" }) + | (ChatCompletionMessageCustomToolCall$Outbound & { type: "custom" }) > | null | undefined; @@ -168,8 +180,12 @@ export const ChatCompletionMessage$outboundSchema: z.ZodType< toolCalls: z.nullable( z.array( z.union([ - ChatCompletionMessageFunctionToolCall$outboundSchema, - ChatCompletionMessageCustomToolCall$outboundSchema, + ChatCompletionMessageFunctionToolCall$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionMessageCustomToolCall$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ), ).optional(), diff --git a/src/models/chatcompletionnonstreaming.ts b/src/models/chatcompletionnonstreaming.ts index 064430d..0232b6e 100644 --- a/src/models/chatcompletionnonstreaming.ts +++ b/src/models/chatcompletionnonstreaming.ts @@ -136,12 +136,12 @@ import { } from "./websearchoptions.js"; export type ChatCompletionNonStreamingMessage = - | ChatCompletionToolMessageParam - | ChatCompletionFunctionMessageParam - | ChatCompletionDeveloperMessageParam - | ChatCompletionSystemMessageParam - | ChatCompletionUserMessageParam - | ChatCompletionAssistantMessageParam; + | (ChatCompletionToolMessageParam & { role: "tool" }) + | (ChatCompletionFunctionMessageParam & { role: "function" }) + | (ChatCompletionDeveloperMessageParam & { role: "developer" }) + | (ChatCompletionSystemMessageParam & { role: "system" }) + | (ChatCompletionUserMessageParam & { role: "user" }) + | (ChatCompletionAssistantMessageParam & { role: "assistant" }); export const ChatCompletionNonStreamingFunctionCallEnum = { None: "none", @@ -174,9 +174,9 @@ export type ChatCompletionNonStreamingReasoningEffort = ClosedEnum< >; export type ChatCompletionNonStreamingResponseFormat = - | ResponseFormatJSONSchema - | ResponseFormatText - | ResponseFormatJSONObject; + | (ResponseFormatJSONSchema & { type: "json_schema" }) + | (ResponseFormatText & { type: "text" }) + | (ResponseFormatJSONObject & { type: "json_object" }); export const ChatCompletionNonStreamingServiceTier = { Auto: "auto", @@ -207,8 +207,8 @@ export type ChatCompletionNonStreamingToolChoiceUnion = | ChatCompletionNonStreamingToolChoiceEnum; export type ChatCompletionNonStreamingTool = - | ChatCompletionFunctionToolParam - | ChatCompletionCustomToolParam; + | (ChatCompletionFunctionToolParam & { type: "function" }) + | (ChatCompletionCustomToolParam & { type: "custom" }); export const ChatCompletionNonStreamingVerbosity = { Low: "low", @@ -221,12 +221,12 @@ export type ChatCompletionNonStreamingVerbosity = ClosedEnum< export type ChatCompletionNonStreaming = { messages: Array< - | ChatCompletionToolMessageParam - | ChatCompletionFunctionMessageParam - | ChatCompletionDeveloperMessageParam - | ChatCompletionSystemMessageParam - | ChatCompletionUserMessageParam - | ChatCompletionAssistantMessageParam + | (ChatCompletionToolMessageParam & { role: "tool" }) + | (ChatCompletionFunctionMessageParam & { role: "function" }) + | (ChatCompletionDeveloperMessageParam & { role: "developer" }) + | (ChatCompletionSystemMessageParam & { role: "system" }) + | (ChatCompletionUserMessageParam & { role: "user" }) + | (ChatCompletionAssistantMessageParam & { role: "assistant" }) >; model?: TModel | undefined; audio?: ChatCompletionAudioParam | null | undefined; @@ -252,9 +252,9 @@ export type ChatCompletionNonStreaming = { | null | undefined; responseFormat?: - | ResponseFormatJSONSchema - | ResponseFormatText - | ResponseFormatJSONObject + | (ResponseFormatJSONSchema & { type: "json_schema" }) + | (ResponseFormatText & { type: "text" }) + | (ResponseFormatJSONObject & { type: "json_object" }) | undefined; safetyIdentifier?: string | undefined; seed?: number | null | undefined; @@ -270,7 +270,10 @@ export type ChatCompletionNonStreaming = { | ChatCompletionNonStreamingToolChoiceEnum | undefined; tools?: - | Array + | Array< + | (ChatCompletionFunctionToolParam & { type: "function" }) + | (ChatCompletionCustomToolParam & { type: "custom" }) + > | undefined; topLogprobs?: number | null | undefined; topP?: number | null | undefined; @@ -288,21 +291,33 @@ export const ChatCompletionNonStreamingMessage$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ChatCompletionToolMessageParam$inboundSchema, - ChatCompletionFunctionMessageParam$inboundSchema, - ChatCompletionDeveloperMessageParam$inboundSchema, - ChatCompletionSystemMessageParam$inboundSchema, - ChatCompletionUserMessageParam$inboundSchema, - ChatCompletionAssistantMessageParam$inboundSchema, + ChatCompletionToolMessageParam$inboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$inboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$inboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$inboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$inboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$inboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]); /** @internal */ export type ChatCompletionNonStreamingMessage$Outbound = - | ChatCompletionToolMessageParam$Outbound - | ChatCompletionFunctionMessageParam$Outbound - | ChatCompletionDeveloperMessageParam$Outbound - | ChatCompletionSystemMessageParam$Outbound - | ChatCompletionUserMessageParam$Outbound - | ChatCompletionAssistantMessageParam$Outbound; + | (ChatCompletionToolMessageParam$Outbound & { role: "tool" }) + | (ChatCompletionFunctionMessageParam$Outbound & { role: "function" }) + | (ChatCompletionDeveloperMessageParam$Outbound & { role: "developer" }) + | (ChatCompletionSystemMessageParam$Outbound & { role: "system" }) + | (ChatCompletionUserMessageParam$Outbound & { role: "user" }) + | (ChatCompletionAssistantMessageParam$Outbound & { role: "assistant" }); /** @internal */ export const ChatCompletionNonStreamingMessage$outboundSchema: z.ZodType< @@ -310,12 +325,24 @@ export const ChatCompletionNonStreamingMessage$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionNonStreamingMessage > = z.union([ - ChatCompletionToolMessageParam$outboundSchema, - ChatCompletionFunctionMessageParam$outboundSchema, - ChatCompletionDeveloperMessageParam$outboundSchema, - ChatCompletionSystemMessageParam$outboundSchema, - ChatCompletionUserMessageParam$outboundSchema, - ChatCompletionAssistantMessageParam$outboundSchema, + ChatCompletionToolMessageParam$outboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$outboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$outboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$outboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$outboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$outboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]); export function chatCompletionNonStreamingMessageToJSON( @@ -422,15 +449,19 @@ export const ChatCompletionNonStreamingResponseFormat$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ResponseFormatJSONSchema$inboundSchema, - ResponseFormatText$inboundSchema, - ResponseFormatJSONObject$inboundSchema, + ResponseFormatJSONSchema$inboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$inboundSchema.and(z.object({ type: z.literal("text") })), + ResponseFormatJSONObject$inboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]); /** @internal */ export type ChatCompletionNonStreamingResponseFormat$Outbound = - | ResponseFormatJSONSchema$Outbound - | ResponseFormatText$Outbound - | ResponseFormatJSONObject$Outbound; + | (ResponseFormatJSONSchema$Outbound & { type: "json_schema" }) + | (ResponseFormatText$Outbound & { type: "text" }) + | (ResponseFormatJSONObject$Outbound & { type: "json_object" }); /** @internal */ export const ChatCompletionNonStreamingResponseFormat$outboundSchema: z.ZodType< @@ -438,9 +469,13 @@ export const ChatCompletionNonStreamingResponseFormat$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionNonStreamingResponseFormat > = z.union([ - ResponseFormatJSONSchema$outboundSchema, - ResponseFormatText$outboundSchema, - ResponseFormatJSONObject$outboundSchema, + ResponseFormatJSONSchema$outboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$outboundSchema.and(z.object({ type: z.literal("text") })), + ResponseFormatJSONObject$outboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]); export function chatCompletionNonStreamingResponseFormatToJSON( @@ -586,13 +621,17 @@ export const ChatCompletionNonStreamingTool$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ChatCompletionFunctionToolParam$inboundSchema, - ChatCompletionCustomToolParam$inboundSchema, + ChatCompletionFunctionToolParam$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); /** @internal */ export type ChatCompletionNonStreamingTool$Outbound = - | ChatCompletionFunctionToolParam$Outbound - | ChatCompletionCustomToolParam$Outbound; + | (ChatCompletionFunctionToolParam$Outbound & { type: "function" }) + | (ChatCompletionCustomToolParam$Outbound & { type: "custom" }); /** @internal */ export const ChatCompletionNonStreamingTool$outboundSchema: z.ZodType< @@ -600,8 +639,12 @@ export const ChatCompletionNonStreamingTool$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionNonStreamingTool > = z.union([ - ChatCompletionFunctionToolParam$outboundSchema, - ChatCompletionCustomToolParam$outboundSchema, + ChatCompletionFunctionToolParam$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); export function chatCompletionNonStreamingToolToJSON( @@ -640,12 +683,24 @@ export const ChatCompletionNonStreaming$inboundSchema: z.ZodType< > = z.object({ messages: z.array( z.union([ - ChatCompletionToolMessageParam$inboundSchema, - ChatCompletionFunctionMessageParam$inboundSchema, - ChatCompletionDeveloperMessageParam$inboundSchema, - ChatCompletionSystemMessageParam$inboundSchema, - ChatCompletionUserMessageParam$inboundSchema, - ChatCompletionAssistantMessageParam$inboundSchema, + ChatCompletionToolMessageParam$inboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$inboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$inboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$inboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$inboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$inboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]), ), model: TModel$inboundSchema.optional(), @@ -676,9 +731,13 @@ export const ChatCompletionNonStreaming$inboundSchema: z.ZodType< ChatCompletionNonStreamingReasoningEffort$inboundSchema, ).optional(), response_format: z.union([ - ResponseFormatJSONSchema$inboundSchema, - ResponseFormatText$inboundSchema, - ResponseFormatJSONObject$inboundSchema, + ResponseFormatJSONSchema$inboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$inboundSchema.and(z.object({ type: z.literal("text") })), + ResponseFormatJSONObject$inboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]).optional(), safety_identifier: z.string().optional(), seed: z.nullable(z.number().int()).optional(), @@ -697,8 +756,12 @@ export const ChatCompletionNonStreaming$inboundSchema: z.ZodType< ]).optional(), tools: z.array( z.union([ - ChatCompletionFunctionToolParam$inboundSchema, - ChatCompletionCustomToolParam$inboundSchema, + ChatCompletionFunctionToolParam$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ).optional(), top_logprobs: z.nullable(z.number().int()).optional(), @@ -735,12 +798,12 @@ export const ChatCompletionNonStreaming$inboundSchema: z.ZodType< /** @internal */ export type ChatCompletionNonStreaming$Outbound = { messages: Array< - | ChatCompletionToolMessageParam$Outbound - | ChatCompletionFunctionMessageParam$Outbound - | ChatCompletionDeveloperMessageParam$Outbound - | ChatCompletionSystemMessageParam$Outbound - | ChatCompletionUserMessageParam$Outbound - | ChatCompletionAssistantMessageParam$Outbound + | (ChatCompletionToolMessageParam$Outbound & { role: "tool" }) + | (ChatCompletionFunctionMessageParam$Outbound & { role: "function" }) + | (ChatCompletionDeveloperMessageParam$Outbound & { role: "developer" }) + | (ChatCompletionSystemMessageParam$Outbound & { role: "system" }) + | (ChatCompletionUserMessageParam$Outbound & { role: "user" }) + | (ChatCompletionAssistantMessageParam$Outbound & { role: "assistant" }) >; model?: TModel$Outbound | undefined; audio?: ChatCompletionAudioParam$Outbound | null | undefined; @@ -765,9 +828,9 @@ export type ChatCompletionNonStreaming$Outbound = { prompt_cache_key?: string | undefined; reasoning_effort?: string | null | undefined; response_format?: - | ResponseFormatJSONSchema$Outbound - | ResponseFormatText$Outbound - | ResponseFormatJSONObject$Outbound + | (ResponseFormatJSONSchema$Outbound & { type: "json_schema" }) + | (ResponseFormatText$Outbound & { type: "text" }) + | (ResponseFormatJSONObject$Outbound & { type: "json_object" }) | undefined; safety_identifier?: string | undefined; seed?: number | null | undefined; @@ -784,8 +847,8 @@ export type ChatCompletionNonStreaming$Outbound = { | undefined; tools?: | Array< - | ChatCompletionFunctionToolParam$Outbound - | ChatCompletionCustomToolParam$Outbound + | (ChatCompletionFunctionToolParam$Outbound & { type: "function" }) + | (ChatCompletionCustomToolParam$Outbound & { type: "custom" }) > | undefined; top_logprobs?: number | null | undefined; @@ -806,12 +869,24 @@ export const ChatCompletionNonStreaming$outboundSchema: z.ZodType< > = z.object({ messages: z.array( z.union([ - ChatCompletionToolMessageParam$outboundSchema, - ChatCompletionFunctionMessageParam$outboundSchema, - ChatCompletionDeveloperMessageParam$outboundSchema, - ChatCompletionSystemMessageParam$outboundSchema, - ChatCompletionUserMessageParam$outboundSchema, - ChatCompletionAssistantMessageParam$outboundSchema, + ChatCompletionToolMessageParam$outboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$outboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$outboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$outboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$outboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$outboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]), ), model: TModel$outboundSchema.optional(), @@ -842,9 +917,15 @@ export const ChatCompletionNonStreaming$outboundSchema: z.ZodType< ChatCompletionNonStreamingReasoningEffort$outboundSchema, ).optional(), responseFormat: z.union([ - ResponseFormatJSONSchema$outboundSchema, - ResponseFormatText$outboundSchema, - ResponseFormatJSONObject$outboundSchema, + ResponseFormatJSONSchema$outboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ResponseFormatJSONObject$outboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]).optional(), safetyIdentifier: z.string().optional(), seed: z.nullable(z.number().int()).optional(), @@ -863,8 +944,12 @@ export const ChatCompletionNonStreaming$outboundSchema: z.ZodType< ]).optional(), tools: z.array( z.union([ - ChatCompletionFunctionToolParam$outboundSchema, - ChatCompletionCustomToolParam$outboundSchema, + ChatCompletionFunctionToolParam$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ).optional(), topLogprobs: z.nullable(z.number().int()).optional(), diff --git a/src/models/chatcompletionstreaming.ts b/src/models/chatcompletionstreaming.ts index c22c5f3..4567d03 100644 --- a/src/models/chatcompletionstreaming.ts +++ b/src/models/chatcompletionstreaming.ts @@ -136,12 +136,12 @@ import { } from "./websearchoptions.js"; export type ChatCompletionStreamingMessage = - | ChatCompletionToolMessageParam - | ChatCompletionFunctionMessageParam - | ChatCompletionDeveloperMessageParam - | ChatCompletionSystemMessageParam - | ChatCompletionUserMessageParam - | ChatCompletionAssistantMessageParam; + | (ChatCompletionToolMessageParam & { role: "tool" }) + | (ChatCompletionFunctionMessageParam & { role: "function" }) + | (ChatCompletionDeveloperMessageParam & { role: "developer" }) + | (ChatCompletionSystemMessageParam & { role: "system" }) + | (ChatCompletionUserMessageParam & { role: "user" }) + | (ChatCompletionAssistantMessageParam & { role: "assistant" }); export const ChatCompletionStreamingFunctionCallEnum = { None: "none", @@ -174,9 +174,9 @@ export type ChatCompletionStreamingReasoningEffort = ClosedEnum< >; export type ChatCompletionStreamingResponseFormat = - | ResponseFormatJSONSchema - | ResponseFormatText - | ResponseFormatJSONObject; + | (ResponseFormatJSONSchema & { type: "json_schema" }) + | (ResponseFormatText & { type: "text" }) + | (ResponseFormatJSONObject & { type: "json_object" }); export const ChatCompletionStreamingServiceTier = { Auto: "auto", @@ -207,8 +207,8 @@ export type ChatCompletionStreamingToolChoiceUnion = | ChatCompletionStreamingToolChoiceEnum; export type ChatCompletionStreamingTool = - | ChatCompletionFunctionToolParam - | ChatCompletionCustomToolParam; + | (ChatCompletionFunctionToolParam & { type: "function" }) + | (ChatCompletionCustomToolParam & { type: "custom" }); export const ChatCompletionStreamingVerbosity = { Low: "low", @@ -221,12 +221,12 @@ export type ChatCompletionStreamingVerbosity = ClosedEnum< export type ChatCompletionStreaming = { messages: Array< - | ChatCompletionToolMessageParam - | ChatCompletionFunctionMessageParam - | ChatCompletionDeveloperMessageParam - | ChatCompletionSystemMessageParam - | ChatCompletionUserMessageParam - | ChatCompletionAssistantMessageParam + | (ChatCompletionToolMessageParam & { role: "tool" }) + | (ChatCompletionFunctionMessageParam & { role: "function" }) + | (ChatCompletionDeveloperMessageParam & { role: "developer" }) + | (ChatCompletionSystemMessageParam & { role: "system" }) + | (ChatCompletionUserMessageParam & { role: "user" }) + | (ChatCompletionAssistantMessageParam & { role: "assistant" }) >; model?: TModel | undefined; audio?: ChatCompletionAudioParam | null | undefined; @@ -249,9 +249,9 @@ export type ChatCompletionStreaming = { promptCacheKey?: string | undefined; reasoningEffort?: ChatCompletionStreamingReasoningEffort | null | undefined; responseFormat?: - | ResponseFormatJSONSchema - | ResponseFormatText - | ResponseFormatJSONObject + | (ResponseFormatJSONSchema & { type: "json_schema" }) + | (ResponseFormatText & { type: "text" }) + | (ResponseFormatJSONObject & { type: "json_object" }) | undefined; safetyIdentifier?: string | undefined; seed?: number | null | undefined; @@ -267,7 +267,10 @@ export type ChatCompletionStreaming = { | ChatCompletionStreamingToolChoiceEnum | undefined; tools?: - | Array + | Array< + | (ChatCompletionFunctionToolParam & { type: "function" }) + | (ChatCompletionCustomToolParam & { type: "custom" }) + > | undefined; topLogprobs?: number | null | undefined; topP?: number | null | undefined; @@ -285,21 +288,33 @@ export const ChatCompletionStreamingMessage$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ChatCompletionToolMessageParam$inboundSchema, - ChatCompletionFunctionMessageParam$inboundSchema, - ChatCompletionDeveloperMessageParam$inboundSchema, - ChatCompletionSystemMessageParam$inboundSchema, - ChatCompletionUserMessageParam$inboundSchema, - ChatCompletionAssistantMessageParam$inboundSchema, + ChatCompletionToolMessageParam$inboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$inboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$inboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$inboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$inboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$inboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]); /** @internal */ export type ChatCompletionStreamingMessage$Outbound = - | ChatCompletionToolMessageParam$Outbound - | ChatCompletionFunctionMessageParam$Outbound - | ChatCompletionDeveloperMessageParam$Outbound - | ChatCompletionSystemMessageParam$Outbound - | ChatCompletionUserMessageParam$Outbound - | ChatCompletionAssistantMessageParam$Outbound; + | (ChatCompletionToolMessageParam$Outbound & { role: "tool" }) + | (ChatCompletionFunctionMessageParam$Outbound & { role: "function" }) + | (ChatCompletionDeveloperMessageParam$Outbound & { role: "developer" }) + | (ChatCompletionSystemMessageParam$Outbound & { role: "system" }) + | (ChatCompletionUserMessageParam$Outbound & { role: "user" }) + | (ChatCompletionAssistantMessageParam$Outbound & { role: "assistant" }); /** @internal */ export const ChatCompletionStreamingMessage$outboundSchema: z.ZodType< @@ -307,12 +322,24 @@ export const ChatCompletionStreamingMessage$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionStreamingMessage > = z.union([ - ChatCompletionToolMessageParam$outboundSchema, - ChatCompletionFunctionMessageParam$outboundSchema, - ChatCompletionDeveloperMessageParam$outboundSchema, - ChatCompletionSystemMessageParam$outboundSchema, - ChatCompletionUserMessageParam$outboundSchema, - ChatCompletionAssistantMessageParam$outboundSchema, + ChatCompletionToolMessageParam$outboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$outboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$outboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$outboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$outboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$outboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]); export function chatCompletionStreamingMessageToJSON( @@ -418,15 +445,19 @@ export const ChatCompletionStreamingResponseFormat$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ResponseFormatJSONSchema$inboundSchema, - ResponseFormatText$inboundSchema, - ResponseFormatJSONObject$inboundSchema, + ResponseFormatJSONSchema$inboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$inboundSchema.and(z.object({ type: z.literal("text") })), + ResponseFormatJSONObject$inboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]); /** @internal */ export type ChatCompletionStreamingResponseFormat$Outbound = - | ResponseFormatJSONSchema$Outbound - | ResponseFormatText$Outbound - | ResponseFormatJSONObject$Outbound; + | (ResponseFormatJSONSchema$Outbound & { type: "json_schema" }) + | (ResponseFormatText$Outbound & { type: "text" }) + | (ResponseFormatJSONObject$Outbound & { type: "json_object" }); /** @internal */ export const ChatCompletionStreamingResponseFormat$outboundSchema: z.ZodType< @@ -434,9 +465,13 @@ export const ChatCompletionStreamingResponseFormat$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionStreamingResponseFormat > = z.union([ - ResponseFormatJSONSchema$outboundSchema, - ResponseFormatText$outboundSchema, - ResponseFormatJSONObject$outboundSchema, + ResponseFormatJSONSchema$outboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$outboundSchema.and(z.object({ type: z.literal("text") })), + ResponseFormatJSONObject$outboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]); export function chatCompletionStreamingResponseFormatToJSON( @@ -570,13 +605,17 @@ export const ChatCompletionStreamingTool$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ChatCompletionFunctionToolParam$inboundSchema, - ChatCompletionCustomToolParam$inboundSchema, + ChatCompletionFunctionToolParam$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); /** @internal */ export type ChatCompletionStreamingTool$Outbound = - | ChatCompletionFunctionToolParam$Outbound - | ChatCompletionCustomToolParam$Outbound; + | (ChatCompletionFunctionToolParam$Outbound & { type: "function" }) + | (ChatCompletionCustomToolParam$Outbound & { type: "custom" }); /** @internal */ export const ChatCompletionStreamingTool$outboundSchema: z.ZodType< @@ -584,8 +623,12 @@ export const ChatCompletionStreamingTool$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionStreamingTool > = z.union([ - ChatCompletionFunctionToolParam$outboundSchema, - ChatCompletionCustomToolParam$outboundSchema, + ChatCompletionFunctionToolParam$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]); export function chatCompletionStreamingToolToJSON( @@ -624,12 +667,24 @@ export const ChatCompletionStreaming$inboundSchema: z.ZodType< > = z.object({ messages: z.array( z.union([ - ChatCompletionToolMessageParam$inboundSchema, - ChatCompletionFunctionMessageParam$inboundSchema, - ChatCompletionDeveloperMessageParam$inboundSchema, - ChatCompletionSystemMessageParam$inboundSchema, - ChatCompletionUserMessageParam$inboundSchema, - ChatCompletionAssistantMessageParam$inboundSchema, + ChatCompletionToolMessageParam$inboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$inboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$inboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$inboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$inboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$inboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]), ), model: TModel$inboundSchema.optional(), @@ -659,9 +714,13 @@ export const ChatCompletionStreaming$inboundSchema: z.ZodType< ChatCompletionStreamingReasoningEffort$inboundSchema, ).optional(), response_format: z.union([ - ResponseFormatJSONSchema$inboundSchema, - ResponseFormatText$inboundSchema, - ResponseFormatJSONObject$inboundSchema, + ResponseFormatJSONSchema$inboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$inboundSchema.and(z.object({ type: z.literal("text") })), + ResponseFormatJSONObject$inboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]).optional(), safety_identifier: z.string().optional(), seed: z.nullable(z.number().int()).optional(), @@ -680,8 +739,12 @@ export const ChatCompletionStreaming$inboundSchema: z.ZodType< ]).optional(), tools: z.array( z.union([ - ChatCompletionFunctionToolParam$inboundSchema, - ChatCompletionCustomToolParam$inboundSchema, + ChatCompletionFunctionToolParam$inboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$inboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ).optional(), top_logprobs: z.nullable(z.number().int()).optional(), @@ -718,12 +781,12 @@ export const ChatCompletionStreaming$inboundSchema: z.ZodType< /** @internal */ export type ChatCompletionStreaming$Outbound = { messages: Array< - | ChatCompletionToolMessageParam$Outbound - | ChatCompletionFunctionMessageParam$Outbound - | ChatCompletionDeveloperMessageParam$Outbound - | ChatCompletionSystemMessageParam$Outbound - | ChatCompletionUserMessageParam$Outbound - | ChatCompletionAssistantMessageParam$Outbound + | (ChatCompletionToolMessageParam$Outbound & { role: "tool" }) + | (ChatCompletionFunctionMessageParam$Outbound & { role: "function" }) + | (ChatCompletionDeveloperMessageParam$Outbound & { role: "developer" }) + | (ChatCompletionSystemMessageParam$Outbound & { role: "system" }) + | (ChatCompletionUserMessageParam$Outbound & { role: "user" }) + | (ChatCompletionAssistantMessageParam$Outbound & { role: "assistant" }) >; model?: TModel$Outbound | undefined; audio?: ChatCompletionAudioParam$Outbound | null | undefined; @@ -748,9 +811,9 @@ export type ChatCompletionStreaming$Outbound = { prompt_cache_key?: string | undefined; reasoning_effort?: string | null | undefined; response_format?: - | ResponseFormatJSONSchema$Outbound - | ResponseFormatText$Outbound - | ResponseFormatJSONObject$Outbound + | (ResponseFormatJSONSchema$Outbound & { type: "json_schema" }) + | (ResponseFormatText$Outbound & { type: "text" }) + | (ResponseFormatJSONObject$Outbound & { type: "json_object" }) | undefined; safety_identifier?: string | undefined; seed?: number | null | undefined; @@ -767,8 +830,8 @@ export type ChatCompletionStreaming$Outbound = { | undefined; tools?: | Array< - | ChatCompletionFunctionToolParam$Outbound - | ChatCompletionCustomToolParam$Outbound + | (ChatCompletionFunctionToolParam$Outbound & { type: "function" }) + | (ChatCompletionCustomToolParam$Outbound & { type: "custom" }) > | undefined; top_logprobs?: number | null | undefined; @@ -789,12 +852,24 @@ export const ChatCompletionStreaming$outboundSchema: z.ZodType< > = z.object({ messages: z.array( z.union([ - ChatCompletionToolMessageParam$outboundSchema, - ChatCompletionFunctionMessageParam$outboundSchema, - ChatCompletionDeveloperMessageParam$outboundSchema, - ChatCompletionSystemMessageParam$outboundSchema, - ChatCompletionUserMessageParam$outboundSchema, - ChatCompletionAssistantMessageParam$outboundSchema, + ChatCompletionToolMessageParam$outboundSchema.and( + z.object({ role: z.literal("tool") }), + ), + ChatCompletionFunctionMessageParam$outboundSchema.and( + z.object({ role: z.literal("function") }), + ), + ChatCompletionDeveloperMessageParam$outboundSchema.and( + z.object({ role: z.literal("developer") }), + ), + ChatCompletionSystemMessageParam$outboundSchema.and( + z.object({ role: z.literal("system") }), + ), + ChatCompletionUserMessageParam$outboundSchema.and( + z.object({ role: z.literal("user") }), + ), + ChatCompletionAssistantMessageParam$outboundSchema.and( + z.object({ role: z.literal("assistant") }), + ), ]), ), model: TModel$outboundSchema.optional(), @@ -825,9 +900,15 @@ export const ChatCompletionStreaming$outboundSchema: z.ZodType< ChatCompletionStreamingReasoningEffort$outboundSchema, ).optional(), responseFormat: z.union([ - ResponseFormatJSONSchema$outboundSchema, - ResponseFormatText$outboundSchema, - ResponseFormatJSONObject$outboundSchema, + ResponseFormatJSONSchema$outboundSchema.and( + z.object({ type: z.literal("json_schema") }), + ), + ResponseFormatText$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ResponseFormatJSONObject$outboundSchema.and( + z.object({ type: z.literal("json_object") }), + ), ]).optional(), safetyIdentifier: z.string().optional(), seed: z.nullable(z.number().int()).optional(), @@ -846,8 +927,12 @@ export const ChatCompletionStreaming$outboundSchema: z.ZodType< ]).optional(), tools: z.array( z.union([ - ChatCompletionFunctionToolParam$outboundSchema, - ChatCompletionCustomToolParam$outboundSchema, + ChatCompletionFunctionToolParam$outboundSchema.and( + z.object({ type: z.literal("function") }), + ), + ChatCompletionCustomToolParam$outboundSchema.and( + z.object({ type: z.literal("custom") }), + ), ]), ).optional(), topLogprobs: z.nullable(z.number().int()).optional(), diff --git a/src/models/chatcompletionusermessageparam.ts b/src/models/chatcompletionusermessageparam.ts index b31ad64..f66cb8f 100644 --- a/src/models/chatcompletionusermessageparam.ts +++ b/src/models/chatcompletionusermessageparam.ts @@ -32,28 +32,28 @@ import { } from "./file.js"; export type ChatCompletionUserMessageParamContent1 = - | ChatCompletionContentPartTextParam - | ChatCompletionContentPartImageParam - | ChatCompletionContentPartInputAudioParam - | FileT; + | (ChatCompletionContentPartTextParam & { type: "text" }) + | (ChatCompletionContentPartImageParam & { type: "image_url" }) + | (ChatCompletionContentPartInputAudioParam & { type: "input_audio" }) + | (FileT & { type: "file" }); export type ChatCompletionUserMessageParamContent2 = | string | Array< - | ChatCompletionContentPartTextParam - | ChatCompletionContentPartImageParam - | ChatCompletionContentPartInputAudioParam - | FileT + | (ChatCompletionContentPartTextParam & { type: "text" }) + | (ChatCompletionContentPartImageParam & { type: "image_url" }) + | (ChatCompletionContentPartInputAudioParam & { type: "input_audio" }) + | (FileT & { type: "file" }) >; export type ChatCompletionUserMessageParam = { content: | string | Array< - | ChatCompletionContentPartTextParam - | ChatCompletionContentPartImageParam - | ChatCompletionContentPartInputAudioParam - | FileT + | (ChatCompletionContentPartTextParam & { type: "text" }) + | (ChatCompletionContentPartImageParam & { type: "image_url" }) + | (ChatCompletionContentPartInputAudioParam & { type: "input_audio" }) + | (FileT & { type: "file" }) >; role?: "user" | undefined; name?: string | undefined; @@ -65,17 +65,25 @@ export const ChatCompletionUserMessageParamContent1$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.union([ - ChatCompletionContentPartTextParam$inboundSchema, - ChatCompletionContentPartImageParam$inboundSchema, - ChatCompletionContentPartInputAudioParam$inboundSchema, - FileT$inboundSchema, + ChatCompletionContentPartTextParam$inboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartImageParam$inboundSchema.and( + z.object({ type: z.literal("image_url") }), + ), + ChatCompletionContentPartInputAudioParam$inboundSchema.and( + z.object({ type: z.literal("input_audio") }), + ), + FileT$inboundSchema.and(z.object({ type: z.literal("file") })), ]); /** @internal */ export type ChatCompletionUserMessageParamContent1$Outbound = - | ChatCompletionContentPartTextParam$Outbound - | ChatCompletionContentPartImageParam$Outbound - | ChatCompletionContentPartInputAudioParam$Outbound - | FileT$Outbound; + | (ChatCompletionContentPartTextParam$Outbound & { type: "text" }) + | (ChatCompletionContentPartImageParam$Outbound & { type: "image_url" }) + | (ChatCompletionContentPartInputAudioParam$Outbound & { + type: "input_audio"; + }) + | (FileT$Outbound & { type: "file" }); /** @internal */ export const ChatCompletionUserMessageParamContent1$outboundSchema: z.ZodType< @@ -83,10 +91,16 @@ export const ChatCompletionUserMessageParamContent1$outboundSchema: z.ZodType< z.ZodTypeDef, ChatCompletionUserMessageParamContent1 > = z.union([ - ChatCompletionContentPartTextParam$outboundSchema, - ChatCompletionContentPartImageParam$outboundSchema, - ChatCompletionContentPartInputAudioParam$outboundSchema, - FileT$outboundSchema, + ChatCompletionContentPartTextParam$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartImageParam$outboundSchema.and( + z.object({ type: z.literal("image_url") }), + ), + ChatCompletionContentPartInputAudioParam$outboundSchema.and( + z.object({ type: z.literal("input_audio") }), + ), + FileT$outboundSchema.and(z.object({ type: z.literal("file") })), ]); export function chatCompletionUserMessageParamContent1ToJSON( @@ -119,10 +133,16 @@ export const ChatCompletionUserMessageParamContent2$inboundSchema: z.ZodType< z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$inboundSchema, - ChatCompletionContentPartImageParam$inboundSchema, - ChatCompletionContentPartInputAudioParam$inboundSchema, - FileT$inboundSchema, + ChatCompletionContentPartTextParam$inboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartImageParam$inboundSchema.and( + z.object({ type: z.literal("image_url") }), + ), + ChatCompletionContentPartInputAudioParam$inboundSchema.and( + z.object({ type: z.literal("input_audio") }), + ), + FileT$inboundSchema.and(z.object({ type: z.literal("file") })), ]), ), ]); @@ -130,10 +150,12 @@ export const ChatCompletionUserMessageParamContent2$inboundSchema: z.ZodType< export type ChatCompletionUserMessageParamContent2$Outbound = | string | Array< - | ChatCompletionContentPartTextParam$Outbound - | ChatCompletionContentPartImageParam$Outbound - | ChatCompletionContentPartInputAudioParam$Outbound - | FileT$Outbound + | (ChatCompletionContentPartTextParam$Outbound & { type: "text" }) + | (ChatCompletionContentPartImageParam$Outbound & { type: "image_url" }) + | (ChatCompletionContentPartInputAudioParam$Outbound & { + type: "input_audio"; + }) + | (FileT$Outbound & { type: "file" }) >; /** @internal */ @@ -145,10 +167,16 @@ export const ChatCompletionUserMessageParamContent2$outboundSchema: z.ZodType< z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$outboundSchema, - ChatCompletionContentPartImageParam$outboundSchema, - ChatCompletionContentPartInputAudioParam$outboundSchema, - FileT$outboundSchema, + ChatCompletionContentPartTextParam$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartImageParam$outboundSchema.and( + z.object({ type: z.literal("image_url") }), + ), + ChatCompletionContentPartInputAudioParam$outboundSchema.and( + z.object({ type: z.literal("input_audio") }), + ), + FileT$outboundSchema.and(z.object({ type: z.literal("file") })), ]), ), ]); @@ -184,10 +212,16 @@ export const ChatCompletionUserMessageParam$inboundSchema: z.ZodType< z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$inboundSchema, - ChatCompletionContentPartImageParam$inboundSchema, - ChatCompletionContentPartInputAudioParam$inboundSchema, - FileT$inboundSchema, + ChatCompletionContentPartTextParam$inboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartImageParam$inboundSchema.and( + z.object({ type: z.literal("image_url") }), + ), + ChatCompletionContentPartInputAudioParam$inboundSchema.and( + z.object({ type: z.literal("input_audio") }), + ), + FileT$inboundSchema.and(z.object({ type: z.literal("file") })), ]), ), ]), @@ -199,10 +233,12 @@ export type ChatCompletionUserMessageParam$Outbound = { content: | string | Array< - | ChatCompletionContentPartTextParam$Outbound - | ChatCompletionContentPartImageParam$Outbound - | ChatCompletionContentPartInputAudioParam$Outbound - | FileT$Outbound + | (ChatCompletionContentPartTextParam$Outbound & { type: "text" }) + | (ChatCompletionContentPartImageParam$Outbound & { type: "image_url" }) + | (ChatCompletionContentPartInputAudioParam$Outbound & { + type: "input_audio"; + }) + | (FileT$Outbound & { type: "file" }) >; role: "user"; name?: string | undefined; @@ -218,10 +254,16 @@ export const ChatCompletionUserMessageParam$outboundSchema: z.ZodType< z.string(), z.array( z.union([ - ChatCompletionContentPartTextParam$outboundSchema, - ChatCompletionContentPartImageParam$outboundSchema, - ChatCompletionContentPartInputAudioParam$outboundSchema, - FileT$outboundSchema, + ChatCompletionContentPartTextParam$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), + ChatCompletionContentPartImageParam$outboundSchema.and( + z.object({ type: z.literal("image_url") }), + ), + ChatCompletionContentPartInputAudioParam$outboundSchema.and( + z.object({ type: z.literal("input_audio") }), + ), + FileT$outboundSchema.and(z.object({ type: z.literal("file") })), ]), ), ]), diff --git a/src/models/filedownloadurlresponse.ts b/src/models/filedownloadurlresponse.ts new file mode 100644 index 0000000..30e3c36 --- /dev/null +++ b/src/models/filedownloadurlresponse.ts @@ -0,0 +1,70 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod/v3"; +import { remap as remap$ } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { Result as SafeParseResult } from "../types/fp.js"; +import { SDKValidationError } from "./errors/sdkvalidationerror.js"; + +export type FileDownloadUrlResponse = { + /** + * Presigned URL to download the file + */ + url: string; + /** + * Number of seconds until the URL expires + */ + expiresIn: number; +}; + +/** @internal */ +export const FileDownloadUrlResponse$inboundSchema: z.ZodType< + FileDownloadUrlResponse, + z.ZodTypeDef, + unknown +> = z.object({ + url: z.string(), + expires_in: z.number().int(), +}).transform((v) => { + return remap$(v, { + "expires_in": "expiresIn", + }); +}); +/** @internal */ +export type FileDownloadUrlResponse$Outbound = { + url: string; + expires_in: number; +}; + +/** @internal */ +export const FileDownloadUrlResponse$outboundSchema: z.ZodType< + FileDownloadUrlResponse$Outbound, + z.ZodTypeDef, + FileDownloadUrlResponse +> = z.object({ + url: z.string(), + expiresIn: z.number().int(), +}).transform((v) => { + return remap$(v, { + expiresIn: "expires_in", + }); +}); + +export function fileDownloadUrlResponseToJSON( + fileDownloadUrlResponse: FileDownloadUrlResponse, +): string { + return JSON.stringify( + FileDownloadUrlResponse$outboundSchema.parse(fileDownloadUrlResponse), + ); +} +export function fileDownloadUrlResponseFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => FileDownloadUrlResponse$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'FileDownloadUrlResponse' from JSON`, + ); +} diff --git a/src/models/index.ts b/src/models/index.ts index 3885194..476628b 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -67,6 +67,7 @@ export * from "./deleteknowledgebaseresponse.js"; export * from "./example.js"; export * from "./examplein.js"; export * from "./file.js"; +export * from "./filedownloadurlresponse.js"; export * from "./filefile.js"; export * from "./filter.js"; export * from "./functioncallconfigurationinput.js"; diff --git a/src/models/listfilesresponse.ts b/src/models/listfilesresponse.ts index 3502815..6ed5922 100644 --- a/src/models/listfilesresponse.ts +++ b/src/models/listfilesresponse.ts @@ -29,6 +29,10 @@ export type ListFilesResponse = { * The id of the associated document */ documentId: number; + /** + * The metadata attached to the file + */ + metadata?: { [k: string]: any } | undefined; }; /** @internal */ @@ -42,6 +46,7 @@ export const ListFilesResponse$inboundSchema: z.ZodType< size: z.number().int(), status: z.string(), document_id: z.number().int(), + metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { "original_filename": "originalFilename", @@ -55,6 +60,7 @@ export type ListFilesResponse$Outbound = { size: number; status: string; document_id: number; + metadata?: { [k: string]: any } | undefined; }; /** @internal */ @@ -68,6 +74,7 @@ export const ListFilesResponse$outboundSchema: z.ZodType< size: z.number().int(), status: z.string(), documentId: z.number().int(), + metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { originalFilename: "original_filename", diff --git a/src/models/openaitypeschatchatcompletioncustomtoolparamcustom.ts b/src/models/openaitypeschatchatcompletioncustomtoolparamcustom.ts index d707c24..ed53cc2 100644 --- a/src/models/openaitypeschatchatcompletioncustomtoolparamcustom.ts +++ b/src/models/openaitypeschatchatcompletioncustomtoolparamcustom.ts @@ -19,21 +19,31 @@ import { } from "./customformattext.js"; import { SDKValidationError } from "./errors/sdkvalidationerror.js"; -export type Format = CustomFormatGrammar | CustomFormatText; +export type Format = + | (CustomFormatGrammar & { type: "grammar" }) + | (CustomFormatText & { type: "text" }); export type OpenaiTypesChatChatCompletionCustomToolParamCustom = { name: string; description?: string | undefined; - format?: CustomFormatGrammar | CustomFormatText | undefined; + format?: + | (CustomFormatGrammar & { type: "grammar" }) + | (CustomFormatText & { type: "text" }) + | undefined; }; /** @internal */ export const Format$inboundSchema: z.ZodType = z - .union([CustomFormatGrammar$inboundSchema, CustomFormatText$inboundSchema]); + .union([ + CustomFormatGrammar$inboundSchema.and( + z.object({ type: z.literal("grammar") }), + ), + CustomFormatText$inboundSchema.and(z.object({ type: z.literal("text") })), + ]); /** @internal */ export type Format$Outbound = - | CustomFormatGrammar$Outbound - | CustomFormatText$Outbound; + | (CustomFormatGrammar$Outbound & { type: "grammar" }) + | (CustomFormatText$Outbound & { type: "text" }); /** @internal */ export const Format$outboundSchema: z.ZodType< @@ -41,8 +51,10 @@ export const Format$outboundSchema: z.ZodType< z.ZodTypeDef, Format > = z.union([ - CustomFormatGrammar$outboundSchema, - CustomFormatText$outboundSchema, + CustomFormatGrammar$outboundSchema.and( + z.object({ type: z.literal("grammar") }), + ), + CustomFormatText$outboundSchema.and(z.object({ type: z.literal("text") })), ]); export function formatToJSON(format: Format): string { @@ -68,15 +80,20 @@ export const OpenaiTypesChatChatCompletionCustomToolParamCustom$inboundSchema: name: z.string(), description: z.string().optional(), format: z.union([ - CustomFormatGrammar$inboundSchema, - CustomFormatText$inboundSchema, + CustomFormatGrammar$inboundSchema.and( + z.object({ type: z.literal("grammar") }), + ), + CustomFormatText$inboundSchema.and(z.object({ type: z.literal("text") })), ]).optional(), }); /** @internal */ export type OpenaiTypesChatChatCompletionCustomToolParamCustom$Outbound = { name: string; description?: string | undefined; - format?: CustomFormatGrammar$Outbound | CustomFormatText$Outbound | undefined; + format?: + | (CustomFormatGrammar$Outbound & { type: "grammar" }) + | (CustomFormatText$Outbound & { type: "text" }) + | undefined; }; /** @internal */ @@ -89,8 +106,12 @@ export const OpenaiTypesChatChatCompletionCustomToolParamCustom$outboundSchema: name: z.string(), description: z.string().optional(), format: z.union([ - CustomFormatGrammar$outboundSchema, - CustomFormatText$outboundSchema, + CustomFormatGrammar$outboundSchema.and( + z.object({ type: z.literal("grammar") }), + ), + CustomFormatText$outboundSchema.and( + z.object({ type: z.literal("text") }), + ), ]).optional(), }); diff --git a/src/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlget.ts b/src/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlget.ts new file mode 100644 index 0000000..7623520 --- /dev/null +++ b/src/models/operations/getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlget.ts @@ -0,0 +1,85 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod/v3"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; + +export type GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest = + { + /** + * The id of the knowledge base + */ + knowledgeBaseId: string; + /** + * The id of the file + */ + fileId: string; + }; + +/** @internal */ +export const GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$inboundSchema: + z.ZodType< + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest, + z.ZodTypeDef, + unknown + > = z.object({ + knowledge_base_id: z.string(), + file_id: z.string(), + }).transform((v) => { + return remap$(v, { + "knowledge_base_id": "knowledgeBaseId", + "file_id": "fileId", + }); + }); +/** @internal */ +export type GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$Outbound = + { + knowledge_base_id: string; + file_id: string; + }; + +/** @internal */ +export const GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$outboundSchema: + z.ZodType< + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$Outbound, + z.ZodTypeDef, + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest + > = z.object({ + knowledgeBaseId: z.string(), + fileId: z.string(), + }).transform((v) => { + return remap$(v, { + knowledgeBaseId: "knowledge_base_id", + fileId: "file_id", + }); + }); + +export function getFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequestToJSON( + getFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest: + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest, +): string { + return JSON.stringify( + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$outboundSchema + .parse( + getFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest, + ), + ); +} +export function getFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequestFromJSON( + jsonString: string, +): SafeParseResult< + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest, + SDKValidationError +> { + return safeParse( + jsonString, + (x) => + GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest$inboundSchema + .parse(JSON.parse(x)), + `Failed to parse 'GetFileDownloadUrlKnowledgeKnowledgeBaseIdFilesFileIdDownloadUrlGetRequest' from JSON`, + ); +} diff --git a/src/models/operations/index.ts b/src/models/operations/index.ts index eb84f06..01eef5e 100644 --- a/src/models/operations/index.ts +++ b/src/models/operations/index.ts @@ -21,6 +21,7 @@ export * from "./functionstreamcallstreampost.js"; export * from "./getcustommodelbynamemodelscustombynamenameget.js"; export * from "./getcustommodelmodelscustommodelidget.js"; export * from "./getdatasetentrydatasetsdatasetidentriesentryidget.js"; +export * from "./getfiledownloadurlknowledgeknowledgebaseidfilesfileiddownloadurlget.js"; export * from "./getfunctionbynamefunctionsbynamenameget.js"; export * from "./getfunctionbyrevisionfunctionsfunctionidrevisionsrevisionidget.js"; export * from "./getfunctionfunctionsfunctionidget.js"; diff --git a/src/models/registerfileuploadrequest.ts b/src/models/registerfileuploadrequest.ts index 8e99908..24fc4e7 100644 --- a/src/models/registerfileuploadrequest.ts +++ b/src/models/registerfileuploadrequest.ts @@ -31,6 +31,10 @@ export type RegisterFileUploadRequest = { * The configuration for the file to register */ configuration?: TextProcessingConfiguration | null | undefined; + /** + * Optional metadata to attach to the file + */ + metadata?: { [k: string]: any } | null | undefined; }; /** @internal */ @@ -44,6 +48,7 @@ export const RegisterFileUploadRequest$inboundSchema: z.ZodType< content_type: z.string(), configuration: z.nullable(TextProcessingConfiguration$inboundSchema) .optional(), + metadata: z.nullable(z.record(z.any())).optional(), }).transform((v) => { return remap$(v, { "file_id": "fileId", @@ -56,6 +61,7 @@ export type RegisterFileUploadRequest$Outbound = { file_id: string; content_type: string; configuration?: TextProcessingConfiguration$Outbound | null | undefined; + metadata?: { [k: string]: any } | null | undefined; }; /** @internal */ @@ -69,6 +75,7 @@ export const RegisterFileUploadRequest$outboundSchema: z.ZodType< contentType: z.string(), configuration: z.nullable(TextProcessingConfiguration$outboundSchema) .optional(), + metadata: z.nullable(z.record(z.any())).optional(), }).transform((v) => { return remap$(v, { fileId: "file_id", diff --git a/src/models/registerfileuploadresponse.ts b/src/models/registerfileuploadresponse.ts index 49605fa..f4d9729 100644 --- a/src/models/registerfileuploadresponse.ts +++ b/src/models/registerfileuploadresponse.ts @@ -13,6 +13,7 @@ export type RegisterFileUploadResponse = { key: string; originalFilename: string; documentId: number; + metadata?: { [k: string]: any } | undefined; }; /** @internal */ @@ -25,6 +26,7 @@ export const RegisterFileUploadResponse$inboundSchema: z.ZodType< key: z.string(), original_filename: z.string(), document_id: z.number().int(), + metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { "original_filename": "originalFilename", @@ -37,6 +39,7 @@ export type RegisterFileUploadResponse$Outbound = { key: string; original_filename: string; document_id: number; + metadata?: { [k: string]: any } | undefined; }; /** @internal */ @@ -49,6 +52,7 @@ export const RegisterFileUploadResponse$outboundSchema: z.ZodType< key: z.string(), originalFilename: z.string(), documentId: z.number().int(), + metadata: z.record(z.any()).optional(), }).transform((v) => { return remap$(v, { originalFilename: "original_filename", diff --git a/src/sdk/knowledge.ts b/src/sdk/knowledge.ts index df22063..a59c345 100644 --- a/src/sdk/knowledge.ts +++ b/src/sdk/knowledge.ts @@ -9,6 +9,7 @@ import { knowledgeDeleteDocuments } from "../funcs/knowledgeDeleteDocuments.js"; import { knowledgeDeleteFile } from "../funcs/knowledgeDeleteFile.js"; import { knowledgeGet } from "../funcs/knowledgeGet.js"; import { knowledgeGetByName } from "../funcs/knowledgeGetByName.js"; +import { knowledgeGetFileDownloadUrl } from "../funcs/knowledgeGetFileDownloadUrl.js"; import { knowledgeGetUploadUrl } from "../funcs/knowledgeGetUploadUrl.js"; import { knowledgeList } from "../funcs/knowledgeList.js"; import { knowledgeListFiles } from "../funcs/knowledgeListFiles.js"; @@ -173,6 +174,25 @@ export class Knowledge extends ClientSDK { )); } + /** + * Get File Download Url + * + * @remarks + * Get a presigned URL to download a file from a knowledge base + */ + async getFileDownloadUrl( + knowledgeBaseId: string, + fileId: string, + options?: RequestOptions, + ): Promise { + return unwrapAsync(knowledgeGetFileDownloadUrl( + this, + knowledgeBaseId, + fileId, + options, + )); + } + /** * List Files * diff --git a/src/types/unrecognized.ts b/src/types/unrecognized.ts index 08227f2..b7a2a13 100644 --- a/src/types/unrecognized.ts +++ b/src/types/unrecognized.ts @@ -16,8 +16,16 @@ export function startCountingUnrecognized() { refCount++; const start = globalCount; return { - end: () => { + /** + * Ends counting and returns the delta. + * @param delta - If provided, only this amount is added to the parent counter + * (used for nested unions where we only want to record the winning option's count). + * If not provided, records all counts since start(). + */ + end: (delta?: number) => { const count = globalCount - start; + // Reset globalCount back to start, then add only the specified delta + globalCount = start + (delta ?? count); if (--refCount === 0) globalCount = 0; return count; },