diff --git a/packages/google-cloud-modelarmor/.gitattributes b/packages/google-cloud-modelarmor/.gitattributes new file mode 100644 index 000000000000..33739cb74e44 --- /dev/null +++ b/packages/google-cloud-modelarmor/.gitattributes @@ -0,0 +1,4 @@ +*.ts text eol=lf +*.js text eol=lf +protos/* linguist-generated +**/api-extractor.json linguist-language=JSON-with-Comments diff --git a/packages/google-cloud-modelarmor/CODE_OF_CONDUCT.md b/packages/google-cloud-modelarmor/CODE_OF_CONDUCT.md new file mode 100644 index 000000000000..2add2547a812 --- /dev/null +++ b/packages/google-cloud-modelarmor/CODE_OF_CONDUCT.md @@ -0,0 +1,94 @@ + +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/packages/google-cloud-modelarmor/CONTRIBUTING.md b/packages/google-cloud-modelarmor/CONTRIBUTING.md new file mode 100644 index 000000000000..300cc2a910b1 --- /dev/null +++ b/packages/google-cloud-modelarmor/CONTRIBUTING.md @@ -0,0 +1,76 @@ +# How to become a contributor and submit your own code + +**Table of contents** + +* [Contributor License Agreements](#contributor-license-agreements) +* [Contributing a patch](#contributing-a-patch) +* [Running the tests](#running-the-tests) +* [Releasing the library](#releasing-the-library) + +## Contributor License Agreements + +We'd love to accept your sample apps and patches! Before we can take them, we +have to jump a couple of legal hurdles. + +Please fill out either the individual or corporate Contributor License Agreement +(CLA). + + * If you are an individual writing original source code and you're sure you + own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). + * If you work for a company that wants to allow you to contribute your work, + then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). + +Follow either of the two links above to access the appropriate CLA and +instructions for how to sign and return it. Once we receive it, we'll be able to +accept your pull requests. + +## Contributing A Patch + +1. Submit an issue describing your proposed change to the repo in question. +1. The repo owner will respond to your issue promptly. +1. If your proposed change is accepted, and you haven't already done so, sign a + Contributor License Agreement (see details above). +1. Fork the desired repo, develop and test your code changes. +1. Ensure that your code adheres to the existing style in the code to which + you are contributing. +1. Ensure that your code has an appropriate set of tests which all pass. +1. Title your pull request following [Conventional Commits](https://www.conventionalcommits.org/) styling. +1. Submit a pull request. + +### Before you begin + +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Modelarmor API][enable_api]. +1. [Set up authentication with a service account][auth] so you can access the + API from your local workstation. + + +## Running the tests + +1. [Prepare your environment for Node.js setup][setup]. + +1. Install dependencies: + + npm install + +1. Run the tests: + + # Run unit tests. + npm test + + # Run sample integration tests. + npm run samples-test + + # Run all system tests. + npm run system-test + +1. Lint (and maybe fix) any changes: + + npm run fix + +[setup]: https://cloud.google.com/nodejs/docs/setup +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=modelarmor.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started \ No newline at end of file diff --git a/packages/google-cloud-modelarmor/LICENSE b/packages/google-cloud-modelarmor/LICENSE new file mode 100644 index 000000000000..d64569567334 --- /dev/null +++ b/packages/google-cloud-modelarmor/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/google-cloud-modelarmor/README.md b/packages/google-cloud-modelarmor/README.md index 568b4ef224cf..c765b6bd9ede 100644 --- a/packages/google-cloud-modelarmor/README.md +++ b/packages/google-cloud-modelarmor/README.md @@ -74,6 +74,8 @@ Samples are in the [`samples/`][homepage_samples] directory. Each sample's `READ | list templates | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.list_templates.js) | | sanitize model response | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_model_response.js) | | sanitize user prompt | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_user_prompt.js) | +| stream sanitize model response | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_model_response.js) | +| stream sanitize user prompt | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_user_prompt.js) | | update floor setting | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.update_floor_setting.js) | | update template | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.update_template.js) | | cloud | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-modelarmor/samples/generated/v1beta/snippet_metadata_google.cloud.modelarmor.v1beta.json) | diff --git a/packages/google-cloud-modelarmor/protos/google/cloud/modelarmor/v1beta/service.proto b/packages/google-cloud-modelarmor/protos/google/cloud/modelarmor/v1beta/service.proto index 4b0ab97abf0e..5984fad510d9 100644 --- a/packages/google-cloud-modelarmor/protos/google/cloud/modelarmor/v1beta/service.proto +++ b/packages/google-cloud-modelarmor/protos/google/cloud/modelarmor/v1beta/service.proto @@ -1,4 +1,4 @@ -// Copyright 2025 Google LLC +// Copyright 2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -128,6 +128,14 @@ service ModelArmor { body: "*" }; } + + // Streaming version of Sanitize User Prompt. + rpc StreamSanitizeUserPrompt(stream SanitizeUserPromptRequest) + returns (stream SanitizeUserPromptResponse) {} + + // Streaming version of Sanitizes Model Response. + rpc StreamSanitizeModelResponse(stream SanitizeModelResponseRequest) + returns (stream SanitizeModelResponseResponse) {} } // Option to specify filter match state. @@ -228,6 +236,18 @@ enum InvocationResult { FAILURE = 3; } +// Streaming Mode for Sanitize* API. +enum StreamingMode { + // Default value. + STREAMING_MODE_UNSPECIFIED = 0; + + // Buffered Streaming mode. + STREAMING_MODE_BUFFERED = 1; + + // Real Time Streaming mode. + STREAMING_MODE_REALTIME = 2; +} + // Message describing Template resource message Template { option (google.api.resource) = { @@ -354,6 +374,9 @@ message FloorSetting { // AI Platform. AI_PLATFORM = 1; + + // Google MCP Server (via Shim Service Extension) + GOOGLE_MCP_SERVER = 2; } // Identifier. The resource name. @@ -386,6 +409,33 @@ message FloorSetting { // Optional. Metadata for FloorSetting FloorSettingMetadata floor_setting_metadata = 8 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Google MCP Server floor setting. + optional McpServerFloorSetting google_mcp_server_floor_setting = 9 + [(google.api.field_behavior) = OPTIONAL]; +} + +// Message describing MCP Server Floor Setting. +message McpServerFloorSetting { + // enforcement type for Model Armor filters. + oneof enforcement_type { + // Optional. If true, Model Armor filters will be run in inspect only mode. + // No action will be taken on the request. + bool inspect_only = 1 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. If true, Model Armor filters will be run in inspect and block + // mode. Requests that trip Model Armor filters will be blocked. + bool inspect_and_block = 2 [(google.api.field_behavior) = OPTIONAL]; + } + + // Optional. If true, log Model Armor filter results to Cloud Logging. + bool enable_cloud_logging = 3 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. List of MCP servers for which the MCP floor setting is + // applicable. Examples: "bigquery.googleapis.com/mcp", + // "run.googleapis.com/mcp" Empty list denotes that the floor setting is + // applicable to all MCP servers. + repeated string apis = 4 [(google.api.field_behavior) = OPTIONAL]; } // message describing AiPlatformFloorSetting @@ -604,7 +654,7 @@ message PiAndJailbreakFilterSettings { // Enabled ENABLED = 1; - // Enabled + // Disabled DISABLED = 2; } @@ -745,6 +795,10 @@ message SanitizeUserPromptRequest { // Optional. Metadata related to Multi Language Detection. MultiLanguageDetectionMetadata multi_language_detection_metadata = 6 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Streaming Mode for StreamSanitize* API. + optional StreamingMode streaming_mode = 7 + [(google.api.field_behavior) = OPTIONAL]; } // Sanitize Model Response request. @@ -767,6 +821,10 @@ message SanitizeModelResponseRequest { // Optional. Metadata related for multi language detection. MultiLanguageDetectionMetadata multi_language_detection_metadata = 7 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Streaming Mode for StreamSanitize* API. + optional StreamingMode streaming_mode = 8 + [(google.api.field_behavior) = OPTIONAL]; } // Sanitized User Prompt Response. @@ -830,8 +888,18 @@ message SanitizationResult { message MultiLanguageDetectionMetadata { // Optional. Optional Source language of the user prompt. // - // If multi-language detection is enabled but language is not set in that case - // we would automatically detect the source language. + // If multi-language detection is enabled and this field is not set, the + // source language will be automatically detected. When a source language is + // provided, Model Armor uses it to sanitize the input. In that case the + // system does not perform auto-detection and relies solely on the specified + // language. + // + // This string field accepts a language code from the ISO-639 standard. + // For a list of languages supported by Model Armor, see + // [Model Armor supported languages] + // (https://cloud.google.com/security-command-center/docs/model-armor-overview#languages-supported). + // For a comprehensive list of language codes, see + // [ISO-639](https://cloud.google.com/translate/docs/languages#nmt). string source_language = 1 [(google.api.field_behavior) = OPTIONAL]; // Optional. Enable detection of multi-language prompts and responses. @@ -897,7 +965,8 @@ message RaiFilterResult { FilterMatchState match_state = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; // The map of RAI filter results where key is RAI filter type - either of - // "sexually_explicit", "hate_speech", "harassment", "dangerous". + // "sexually_explicit", "hate_speech", "harassment", "dangerous", "violence", + // "sexually_suggestive". map rai_filter_type_results = 4; } @@ -982,6 +1051,9 @@ message ByteDataItem { // CSV CSV = 7; + + // ZIP + ZIP = 9; } // Required. The type of byte data @@ -989,6 +1061,10 @@ message ByteDataItem { // Required. Bytes Data bytes byte_data = 2 [(google.api.field_behavior) = REQUIRED]; + + // Optional. Label of the file. This is used to identify the file in the + // response. + string file_label = 3 [(google.api.field_behavior) = OPTIONAL]; } // Sensitive Data Protection Deidentification Result. @@ -1026,11 +1102,13 @@ message SdpFinding { // These are relative to the finding's containing element. // Note that when the content is not textual, this references // the UTF-8 encoded textual representation of the content. + // Note: Omitted if content is an image. RangeInfo byte_range = 1; // Unicode character offsets delimiting the finding. // These are relative to the finding's containing element. // Provided when the content is text. + // Note: Omitted if content is an image. RangeInfo codepoint_range = 2; } diff --git a/packages/google-cloud-modelarmor/protos/protos.d.ts b/packages/google-cloud-modelarmor/protos/protos.d.ts index 3af31f880300..657ed010dc33 100644 --- a/packages/google-cloud-modelarmor/protos/protos.d.ts +++ b/packages/google-cloud-modelarmor/protos/protos.d.ts @@ -5804,6 +5804,34 @@ export namespace google { * @returns Promise */ public sanitizeModelResponse(request: google.cloud.modelarmor.v1beta.ISanitizeModelResponseRequest): Promise; + + /** + * Calls StreamSanitizeUserPrompt. + * @param request SanitizeUserPromptRequest message or plain object + * @param callback Node-style callback called with the error, if any, and SanitizeUserPromptResponse + */ + public streamSanitizeUserPrompt(request: google.cloud.modelarmor.v1beta.ISanitizeUserPromptRequest, callback: google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeUserPromptCallback): void; + + /** + * Calls StreamSanitizeUserPrompt. + * @param request SanitizeUserPromptRequest message or plain object + * @returns Promise + */ + public streamSanitizeUserPrompt(request: google.cloud.modelarmor.v1beta.ISanitizeUserPromptRequest): Promise; + + /** + * Calls StreamSanitizeModelResponse. + * @param request SanitizeModelResponseRequest message or plain object + * @param callback Node-style callback called with the error, if any, and SanitizeModelResponseResponse + */ + public streamSanitizeModelResponse(request: google.cloud.modelarmor.v1beta.ISanitizeModelResponseRequest, callback: google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeModelResponseCallback): void; + + /** + * Calls StreamSanitizeModelResponse. + * @param request SanitizeModelResponseRequest message or plain object + * @returns Promise + */ + public streamSanitizeModelResponse(request: google.cloud.modelarmor.v1beta.ISanitizeModelResponseRequest): Promise; } namespace ModelArmor { @@ -5870,6 +5898,20 @@ export namespace google { * @param [response] SanitizeModelResponseResponse */ type SanitizeModelResponseCallback = (error: (Error|null), response?: google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse) => void; + + /** + * Callback as used by {@link google.cloud.modelarmor.v1beta.ModelArmor|streamSanitizeUserPrompt}. + * @param error Error, if any + * @param [response] SanitizeUserPromptResponse + */ + type StreamSanitizeUserPromptCallback = (error: (Error|null), response?: google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse) => void; + + /** + * Callback as used by {@link google.cloud.modelarmor.v1beta.ModelArmor|streamSanitizeModelResponse}. + * @param error Error, if any + * @param [response] SanitizeModelResponseResponse + */ + type StreamSanitizeModelResponseCallback = (error: (Error|null), response?: google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse) => void; } /** FilterMatchState enum. */ @@ -5921,6 +5963,13 @@ export namespace google { FAILURE = 3 } + /** StreamingMode enum. */ + enum StreamingMode { + STREAMING_MODE_UNSPECIFIED = 0, + STREAMING_MODE_BUFFERED = 1, + STREAMING_MODE_REALTIME = 2 + } + /** Properties of a Template. */ interface ITemplate { @@ -6329,6 +6378,9 @@ export namespace google { /** FloorSetting floorSettingMetadata */ floorSettingMetadata?: (google.cloud.modelarmor.v1beta.FloorSetting.IFloorSettingMetadata|null); + + /** FloorSetting googleMcpServerFloorSetting */ + googleMcpServerFloorSetting?: (google.cloud.modelarmor.v1beta.IMcpServerFloorSetting|null); } /** Represents a FloorSetting. */ @@ -6364,6 +6416,9 @@ export namespace google { /** FloorSetting floorSettingMetadata. */ public floorSettingMetadata?: (google.cloud.modelarmor.v1beta.FloorSetting.IFloorSettingMetadata|null); + /** FloorSetting googleMcpServerFloorSetting. */ + public googleMcpServerFloorSetting?: (google.cloud.modelarmor.v1beta.IMcpServerFloorSetting|null); + /** * Creates a new FloorSetting instance using the specified properties. * @param [properties] Properties to set @@ -6644,10 +6699,129 @@ export namespace google { /** IntegratedService enum. */ enum IntegratedService { INTEGRATED_SERVICE_UNSPECIFIED = 0, - AI_PLATFORM = 1 + AI_PLATFORM = 1, + GOOGLE_MCP_SERVER = 2 } } + /** Properties of a McpServerFloorSetting. */ + interface IMcpServerFloorSetting { + + /** McpServerFloorSetting inspectOnly */ + inspectOnly?: (boolean|null); + + /** McpServerFloorSetting inspectAndBlock */ + inspectAndBlock?: (boolean|null); + + /** McpServerFloorSetting enableCloudLogging */ + enableCloudLogging?: (boolean|null); + + /** McpServerFloorSetting apis */ + apis?: (string[]|null); + } + + /** Represents a McpServerFloorSetting. */ + class McpServerFloorSetting implements IMcpServerFloorSetting { + + /** + * Constructs a new McpServerFloorSetting. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.modelarmor.v1beta.IMcpServerFloorSetting); + + /** McpServerFloorSetting inspectOnly. */ + public inspectOnly?: (boolean|null); + + /** McpServerFloorSetting inspectAndBlock. */ + public inspectAndBlock?: (boolean|null); + + /** McpServerFloorSetting enableCloudLogging. */ + public enableCloudLogging: boolean; + + /** McpServerFloorSetting apis. */ + public apis: string[]; + + /** McpServerFloorSetting enforcementType. */ + public enforcementType?: ("inspectOnly"|"inspectAndBlock"); + + /** + * Creates a new McpServerFloorSetting instance using the specified properties. + * @param [properties] Properties to set + * @returns McpServerFloorSetting instance + */ + public static create(properties?: google.cloud.modelarmor.v1beta.IMcpServerFloorSetting): google.cloud.modelarmor.v1beta.McpServerFloorSetting; + + /** + * Encodes the specified McpServerFloorSetting message. Does not implicitly {@link google.cloud.modelarmor.v1beta.McpServerFloorSetting.verify|verify} messages. + * @param message McpServerFloorSetting message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.modelarmor.v1beta.IMcpServerFloorSetting, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified McpServerFloorSetting message, length delimited. Does not implicitly {@link google.cloud.modelarmor.v1beta.McpServerFloorSetting.verify|verify} messages. + * @param message McpServerFloorSetting message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.modelarmor.v1beta.IMcpServerFloorSetting, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a McpServerFloorSetting message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns McpServerFloorSetting + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.modelarmor.v1beta.McpServerFloorSetting; + + /** + * Decodes a McpServerFloorSetting message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns McpServerFloorSetting + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.modelarmor.v1beta.McpServerFloorSetting; + + /** + * Verifies a McpServerFloorSetting message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a McpServerFloorSetting message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns McpServerFloorSetting + */ + public static fromObject(object: { [k: string]: any }): google.cloud.modelarmor.v1beta.McpServerFloorSetting; + + /** + * Creates a plain object from a McpServerFloorSetting message. Also converts values to other types if specified. + * @param message McpServerFloorSetting + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.modelarmor.v1beta.McpServerFloorSetting, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this McpServerFloorSetting to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for McpServerFloorSetting + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + /** Properties of an AiPlatformFloorSetting. */ interface IAiPlatformFloorSetting { @@ -8479,6 +8653,9 @@ export namespace google { /** SanitizeUserPromptRequest multiLanguageDetectionMetadata */ multiLanguageDetectionMetadata?: (google.cloud.modelarmor.v1beta.IMultiLanguageDetectionMetadata|null); + + /** SanitizeUserPromptRequest streamingMode */ + streamingMode?: (google.cloud.modelarmor.v1beta.StreamingMode|keyof typeof google.cloud.modelarmor.v1beta.StreamingMode|null); } /** Represents a SanitizeUserPromptRequest. */ @@ -8499,6 +8676,9 @@ export namespace google { /** SanitizeUserPromptRequest multiLanguageDetectionMetadata. */ public multiLanguageDetectionMetadata?: (google.cloud.modelarmor.v1beta.IMultiLanguageDetectionMetadata|null); + /** SanitizeUserPromptRequest streamingMode. */ + public streamingMode?: (google.cloud.modelarmor.v1beta.StreamingMode|keyof typeof google.cloud.modelarmor.v1beta.StreamingMode|null); + /** * Creates a new SanitizeUserPromptRequest instance using the specified properties. * @param [properties] Properties to set @@ -8591,6 +8771,9 @@ export namespace google { /** SanitizeModelResponseRequest multiLanguageDetectionMetadata */ multiLanguageDetectionMetadata?: (google.cloud.modelarmor.v1beta.IMultiLanguageDetectionMetadata|null); + + /** SanitizeModelResponseRequest streamingMode */ + streamingMode?: (google.cloud.modelarmor.v1beta.StreamingMode|keyof typeof google.cloud.modelarmor.v1beta.StreamingMode|null); } /** Represents a SanitizeModelResponseRequest. */ @@ -8614,6 +8797,9 @@ export namespace google { /** SanitizeModelResponseRequest multiLanguageDetectionMetadata. */ public multiLanguageDetectionMetadata?: (google.cloud.modelarmor.v1beta.IMultiLanguageDetectionMetadata|null); + /** SanitizeModelResponseRequest streamingMode. */ + public streamingMode?: (google.cloud.modelarmor.v1beta.StreamingMode|keyof typeof google.cloud.modelarmor.v1beta.StreamingMode|null); + /** * Creates a new SanitizeModelResponseRequest instance using the specified properties. * @param [properties] Properties to set @@ -9914,6 +10100,9 @@ export namespace google { /** ByteDataItem byteData */ byteData?: (Uint8Array|Buffer|string|null); + + /** ByteDataItem fileLabel */ + fileLabel?: (string|null); } /** Represents a ByteDataItem. */ @@ -9931,6 +10120,9 @@ export namespace google { /** ByteDataItem byteData. */ public byteData: (Uint8Array|Buffer|string); + /** ByteDataItem fileLabel. */ + public fileLabel: string; + /** * Creates a new ByteDataItem instance using the specified properties. * @param [properties] Properties to set @@ -10020,7 +10212,8 @@ export namespace google { EXCEL_DOCUMENT = 4, POWERPOINT_DOCUMENT = 5, TXT = 6, - CSV = 7 + CSV = 7, + ZIP = 9 } } diff --git a/packages/google-cloud-modelarmor/protos/protos.js b/packages/google-cloud-modelarmor/protos/protos.js index 170246720010..cd9fa3966f5b 100644 --- a/packages/google-cloud-modelarmor/protos/protos.js +++ b/packages/google-cloud-modelarmor/protos/protos.js @@ -14964,6 +14964,72 @@ * @variation 2 */ + /** + * Callback as used by {@link google.cloud.modelarmor.v1beta.ModelArmor|streamSanitizeUserPrompt}. + * @memberof google.cloud.modelarmor.v1beta.ModelArmor + * @typedef StreamSanitizeUserPromptCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse} [response] SanitizeUserPromptResponse + */ + + /** + * Calls StreamSanitizeUserPrompt. + * @function streamSanitizeUserPrompt + * @memberof google.cloud.modelarmor.v1beta.ModelArmor + * @instance + * @param {google.cloud.modelarmor.v1beta.ISanitizeUserPromptRequest} request SanitizeUserPromptRequest message or plain object + * @param {google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeUserPromptCallback} callback Node-style callback called with the error, if any, and SanitizeUserPromptResponse + * @returns {undefined} + * @variation 1 + */ + Object.defineProperty(ModelArmor.prototype.streamSanitizeUserPrompt = function streamSanitizeUserPrompt(request, callback) { + return this.rpcCall(streamSanitizeUserPrompt, $root.google.cloud.modelarmor.v1beta.SanitizeUserPromptRequest, $root.google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse, request, callback); + }, "name", { value: "StreamSanitizeUserPrompt" }); + + /** + * Calls StreamSanitizeUserPrompt. + * @function streamSanitizeUserPrompt + * @memberof google.cloud.modelarmor.v1beta.ModelArmor + * @instance + * @param {google.cloud.modelarmor.v1beta.ISanitizeUserPromptRequest} request SanitizeUserPromptRequest message or plain object + * @returns {Promise} Promise + * @variation 2 + */ + + /** + * Callback as used by {@link google.cloud.modelarmor.v1beta.ModelArmor|streamSanitizeModelResponse}. + * @memberof google.cloud.modelarmor.v1beta.ModelArmor + * @typedef StreamSanitizeModelResponseCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse} [response] SanitizeModelResponseResponse + */ + + /** + * Calls StreamSanitizeModelResponse. + * @function streamSanitizeModelResponse + * @memberof google.cloud.modelarmor.v1beta.ModelArmor + * @instance + * @param {google.cloud.modelarmor.v1beta.ISanitizeModelResponseRequest} request SanitizeModelResponseRequest message or plain object + * @param {google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeModelResponseCallback} callback Node-style callback called with the error, if any, and SanitizeModelResponseResponse + * @returns {undefined} + * @variation 1 + */ + Object.defineProperty(ModelArmor.prototype.streamSanitizeModelResponse = function streamSanitizeModelResponse(request, callback) { + return this.rpcCall(streamSanitizeModelResponse, $root.google.cloud.modelarmor.v1beta.SanitizeModelResponseRequest, $root.google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse, request, callback); + }, "name", { value: "StreamSanitizeModelResponse" }); + + /** + * Calls StreamSanitizeModelResponse. + * @function streamSanitizeModelResponse + * @memberof google.cloud.modelarmor.v1beta.ModelArmor + * @instance + * @param {google.cloud.modelarmor.v1beta.ISanitizeModelResponseRequest} request SanitizeModelResponseRequest message or plain object + * @returns {Promise} Promise + * @variation 2 + */ + return ModelArmor; })(); @@ -15077,6 +15143,22 @@ return values; })(); + /** + * StreamingMode enum. + * @name google.cloud.modelarmor.v1beta.StreamingMode + * @enum {number} + * @property {number} STREAMING_MODE_UNSPECIFIED=0 STREAMING_MODE_UNSPECIFIED value + * @property {number} STREAMING_MODE_BUFFERED=1 STREAMING_MODE_BUFFERED value + * @property {number} STREAMING_MODE_REALTIME=2 STREAMING_MODE_REALTIME value + */ + v1beta.StreamingMode = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "STREAMING_MODE_UNSPECIFIED"] = 0; + values[valuesById[1] = "STREAMING_MODE_BUFFERED"] = 1; + values[valuesById[2] = "STREAMING_MODE_REALTIME"] = 2; + return values; + })(); + v1beta.Template = (function() { /** @@ -16108,6 +16190,7 @@ * @property {Array.|null} [integratedServices] FloorSetting integratedServices * @property {google.cloud.modelarmor.v1beta.IAiPlatformFloorSetting|null} [aiPlatformFloorSetting] FloorSetting aiPlatformFloorSetting * @property {google.cloud.modelarmor.v1beta.FloorSetting.IFloorSettingMetadata|null} [floorSettingMetadata] FloorSetting floorSettingMetadata + * @property {google.cloud.modelarmor.v1beta.IMcpServerFloorSetting|null} [googleMcpServerFloorSetting] FloorSetting googleMcpServerFloorSetting */ /** @@ -16190,6 +16273,14 @@ */ FloorSetting.prototype.floorSettingMetadata = null; + /** + * FloorSetting googleMcpServerFloorSetting. + * @member {google.cloud.modelarmor.v1beta.IMcpServerFloorSetting|null|undefined} googleMcpServerFloorSetting + * @memberof google.cloud.modelarmor.v1beta.FloorSetting + * @instance + */ + FloorSetting.prototype.googleMcpServerFloorSetting = null; + // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -16205,6 +16296,12 @@ set: $util.oneOfSetter($oneOfFields) }); + // Virtual OneOf for proto3 optional field + Object.defineProperty(FloorSetting.prototype, "_googleMcpServerFloorSetting", { + get: $util.oneOfGetter($oneOfFields = ["googleMcpServerFloorSetting"]), + set: $util.oneOfSetter($oneOfFields) + }); + /** * Creates a new FloorSetting instance using the specified properties. * @function create @@ -16249,6 +16346,8 @@ $root.google.cloud.modelarmor.v1beta.AiPlatformFloorSetting.encode(message.aiPlatformFloorSetting, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim(); if (message.floorSettingMetadata != null && Object.hasOwnProperty.call(message, "floorSettingMetadata")) $root.google.cloud.modelarmor.v1beta.FloorSetting.FloorSettingMetadata.encode(message.floorSettingMetadata, writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); + if (message.googleMcpServerFloorSetting != null && Object.hasOwnProperty.call(message, "googleMcpServerFloorSetting")) + $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting.encode(message.googleMcpServerFloorSetting, writer.uint32(/* id 9, wireType 2 =*/74).fork()).ldelim(); return writer; }; @@ -16324,6 +16423,10 @@ message.floorSettingMetadata = $root.google.cloud.modelarmor.v1beta.FloorSetting.FloorSettingMetadata.decode(reader, reader.uint32()); break; } + case 9: { + message.googleMcpServerFloorSetting = $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting.decode(reader, reader.uint32()); + break; + } default: reader.skipType(tag & 7); break; @@ -16392,6 +16495,7 @@ return "integratedServices: enum value[] expected"; case 0: case 1: + case 2: break; } } @@ -16408,6 +16512,14 @@ if (error) return "floorSettingMetadata." + error; } + if (message.googleMcpServerFloorSetting != null && message.hasOwnProperty("googleMcpServerFloorSetting")) { + properties._googleMcpServerFloorSetting = 1; + { + var error = $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting.verify(message.googleMcpServerFloorSetting); + if (error) + return "googleMcpServerFloorSetting." + error; + } + } return null; }; @@ -16461,6 +16573,10 @@ case 1: message.integratedServices[i] = 1; break; + case "GOOGLE_MCP_SERVER": + case 2: + message.integratedServices[i] = 2; + break; } } if (object.aiPlatformFloorSetting != null) { @@ -16473,6 +16589,11 @@ throw TypeError(".google.cloud.modelarmor.v1beta.FloorSetting.floorSettingMetadata: object expected"); message.floorSettingMetadata = $root.google.cloud.modelarmor.v1beta.FloorSetting.FloorSettingMetadata.fromObject(object.floorSettingMetadata); } + if (object.googleMcpServerFloorSetting != null) { + if (typeof object.googleMcpServerFloorSetting !== "object") + throw TypeError(".google.cloud.modelarmor.v1beta.FloorSetting.googleMcpServerFloorSetting: object expected"); + message.googleMcpServerFloorSetting = $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting.fromObject(object.googleMcpServerFloorSetting); + } return message; }; @@ -16523,6 +16644,11 @@ } if (message.floorSettingMetadata != null && message.hasOwnProperty("floorSettingMetadata")) object.floorSettingMetadata = $root.google.cloud.modelarmor.v1beta.FloorSetting.FloorSettingMetadata.toObject(message.floorSettingMetadata, options); + if (message.googleMcpServerFloorSetting != null && message.hasOwnProperty("googleMcpServerFloorSetting")) { + object.googleMcpServerFloorSetting = $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting.toObject(message.googleMcpServerFloorSetting, options); + if (options.oneofs) + object._googleMcpServerFloorSetting = "googleMcpServerFloorSetting"; + } return object; }; @@ -16973,17 +17099,335 @@ * @enum {number} * @property {number} INTEGRATED_SERVICE_UNSPECIFIED=0 INTEGRATED_SERVICE_UNSPECIFIED value * @property {number} AI_PLATFORM=1 AI_PLATFORM value + * @property {number} GOOGLE_MCP_SERVER=2 GOOGLE_MCP_SERVER value */ FloorSetting.IntegratedService = (function() { var valuesById = {}, values = Object.create(valuesById); values[valuesById[0] = "INTEGRATED_SERVICE_UNSPECIFIED"] = 0; values[valuesById[1] = "AI_PLATFORM"] = 1; + values[valuesById[2] = "GOOGLE_MCP_SERVER"] = 2; return values; })(); return FloorSetting; })(); + v1beta.McpServerFloorSetting = (function() { + + /** + * Properties of a McpServerFloorSetting. + * @memberof google.cloud.modelarmor.v1beta + * @interface IMcpServerFloorSetting + * @property {boolean|null} [inspectOnly] McpServerFloorSetting inspectOnly + * @property {boolean|null} [inspectAndBlock] McpServerFloorSetting inspectAndBlock + * @property {boolean|null} [enableCloudLogging] McpServerFloorSetting enableCloudLogging + * @property {Array.|null} [apis] McpServerFloorSetting apis + */ + + /** + * Constructs a new McpServerFloorSetting. + * @memberof google.cloud.modelarmor.v1beta + * @classdesc Represents a McpServerFloorSetting. + * @implements IMcpServerFloorSetting + * @constructor + * @param {google.cloud.modelarmor.v1beta.IMcpServerFloorSetting=} [properties] Properties to set + */ + function McpServerFloorSetting(properties) { + this.apis = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * McpServerFloorSetting inspectOnly. + * @member {boolean|null|undefined} inspectOnly + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @instance + */ + McpServerFloorSetting.prototype.inspectOnly = null; + + /** + * McpServerFloorSetting inspectAndBlock. + * @member {boolean|null|undefined} inspectAndBlock + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @instance + */ + McpServerFloorSetting.prototype.inspectAndBlock = null; + + /** + * McpServerFloorSetting enableCloudLogging. + * @member {boolean} enableCloudLogging + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @instance + */ + McpServerFloorSetting.prototype.enableCloudLogging = false; + + /** + * McpServerFloorSetting apis. + * @member {Array.} apis + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @instance + */ + McpServerFloorSetting.prototype.apis = $util.emptyArray; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * McpServerFloorSetting enforcementType. + * @member {"inspectOnly"|"inspectAndBlock"|undefined} enforcementType + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @instance + */ + Object.defineProperty(McpServerFloorSetting.prototype, "enforcementType", { + get: $util.oneOfGetter($oneOfFields = ["inspectOnly", "inspectAndBlock"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Creates a new McpServerFloorSetting instance using the specified properties. + * @function create + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {google.cloud.modelarmor.v1beta.IMcpServerFloorSetting=} [properties] Properties to set + * @returns {google.cloud.modelarmor.v1beta.McpServerFloorSetting} McpServerFloorSetting instance + */ + McpServerFloorSetting.create = function create(properties) { + return new McpServerFloorSetting(properties); + }; + + /** + * Encodes the specified McpServerFloorSetting message. Does not implicitly {@link google.cloud.modelarmor.v1beta.McpServerFloorSetting.verify|verify} messages. + * @function encode + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {google.cloud.modelarmor.v1beta.IMcpServerFloorSetting} message McpServerFloorSetting message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + McpServerFloorSetting.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.inspectOnly != null && Object.hasOwnProperty.call(message, "inspectOnly")) + writer.uint32(/* id 1, wireType 0 =*/8).bool(message.inspectOnly); + if (message.inspectAndBlock != null && Object.hasOwnProperty.call(message, "inspectAndBlock")) + writer.uint32(/* id 2, wireType 0 =*/16).bool(message.inspectAndBlock); + if (message.enableCloudLogging != null && Object.hasOwnProperty.call(message, "enableCloudLogging")) + writer.uint32(/* id 3, wireType 0 =*/24).bool(message.enableCloudLogging); + if (message.apis != null && message.apis.length) + for (var i = 0; i < message.apis.length; ++i) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.apis[i]); + return writer; + }; + + /** + * Encodes the specified McpServerFloorSetting message, length delimited. Does not implicitly {@link google.cloud.modelarmor.v1beta.McpServerFloorSetting.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {google.cloud.modelarmor.v1beta.IMcpServerFloorSetting} message McpServerFloorSetting message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + McpServerFloorSetting.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a McpServerFloorSetting message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.modelarmor.v1beta.McpServerFloorSetting} McpServerFloorSetting + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + McpServerFloorSetting.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting(); + while (reader.pos < end) { + var tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + message.inspectOnly = reader.bool(); + break; + } + case 2: { + message.inspectAndBlock = reader.bool(); + break; + } + case 3: { + message.enableCloudLogging = reader.bool(); + break; + } + case 4: { + if (!(message.apis && message.apis.length)) + message.apis = []; + message.apis.push(reader.string()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a McpServerFloorSetting message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.modelarmor.v1beta.McpServerFloorSetting} McpServerFloorSetting + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + McpServerFloorSetting.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a McpServerFloorSetting message. + * @function verify + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + McpServerFloorSetting.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + var properties = {}; + if (message.inspectOnly != null && message.hasOwnProperty("inspectOnly")) { + properties.enforcementType = 1; + if (typeof message.inspectOnly !== "boolean") + return "inspectOnly: boolean expected"; + } + if (message.inspectAndBlock != null && message.hasOwnProperty("inspectAndBlock")) { + if (properties.enforcementType === 1) + return "enforcementType: multiple values"; + properties.enforcementType = 1; + if (typeof message.inspectAndBlock !== "boolean") + return "inspectAndBlock: boolean expected"; + } + if (message.enableCloudLogging != null && message.hasOwnProperty("enableCloudLogging")) + if (typeof message.enableCloudLogging !== "boolean") + return "enableCloudLogging: boolean expected"; + if (message.apis != null && message.hasOwnProperty("apis")) { + if (!Array.isArray(message.apis)) + return "apis: array expected"; + for (var i = 0; i < message.apis.length; ++i) + if (!$util.isString(message.apis[i])) + return "apis: string[] expected"; + } + return null; + }; + + /** + * Creates a McpServerFloorSetting message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.modelarmor.v1beta.McpServerFloorSetting} McpServerFloorSetting + */ + McpServerFloorSetting.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting) + return object; + var message = new $root.google.cloud.modelarmor.v1beta.McpServerFloorSetting(); + if (object.inspectOnly != null) + message.inspectOnly = Boolean(object.inspectOnly); + if (object.inspectAndBlock != null) + message.inspectAndBlock = Boolean(object.inspectAndBlock); + if (object.enableCloudLogging != null) + message.enableCloudLogging = Boolean(object.enableCloudLogging); + if (object.apis) { + if (!Array.isArray(object.apis)) + throw TypeError(".google.cloud.modelarmor.v1beta.McpServerFloorSetting.apis: array expected"); + message.apis = []; + for (var i = 0; i < object.apis.length; ++i) + message.apis[i] = String(object.apis[i]); + } + return message; + }; + + /** + * Creates a plain object from a McpServerFloorSetting message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {google.cloud.modelarmor.v1beta.McpServerFloorSetting} message McpServerFloorSetting + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + McpServerFloorSetting.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.apis = []; + if (options.defaults) + object.enableCloudLogging = false; + if (message.inspectOnly != null && message.hasOwnProperty("inspectOnly")) { + object.inspectOnly = message.inspectOnly; + if (options.oneofs) + object.enforcementType = "inspectOnly"; + } + if (message.inspectAndBlock != null && message.hasOwnProperty("inspectAndBlock")) { + object.inspectAndBlock = message.inspectAndBlock; + if (options.oneofs) + object.enforcementType = "inspectAndBlock"; + } + if (message.enableCloudLogging != null && message.hasOwnProperty("enableCloudLogging")) + object.enableCloudLogging = message.enableCloudLogging; + if (message.apis && message.apis.length) { + object.apis = []; + for (var j = 0; j < message.apis.length; ++j) + object.apis[j] = message.apis[j]; + } + return object; + }; + + /** + * Converts this McpServerFloorSetting to JSON. + * @function toJSON + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @instance + * @returns {Object.} JSON object + */ + McpServerFloorSetting.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for McpServerFloorSetting + * @function getTypeUrl + * @memberof google.cloud.modelarmor.v1beta.McpServerFloorSetting + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + McpServerFloorSetting.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.modelarmor.v1beta.McpServerFloorSetting"; + }; + + return McpServerFloorSetting; + })(); + v1beta.AiPlatformFloorSetting = (function() { /** @@ -21371,6 +21815,7 @@ * @property {string|null} [name] SanitizeUserPromptRequest name * @property {google.cloud.modelarmor.v1beta.IDataItem|null} [userPromptData] SanitizeUserPromptRequest userPromptData * @property {google.cloud.modelarmor.v1beta.IMultiLanguageDetectionMetadata|null} [multiLanguageDetectionMetadata] SanitizeUserPromptRequest multiLanguageDetectionMetadata + * @property {google.cloud.modelarmor.v1beta.StreamingMode|null} [streamingMode] SanitizeUserPromptRequest streamingMode */ /** @@ -21412,6 +21857,23 @@ */ SanitizeUserPromptRequest.prototype.multiLanguageDetectionMetadata = null; + /** + * SanitizeUserPromptRequest streamingMode. + * @member {google.cloud.modelarmor.v1beta.StreamingMode|null|undefined} streamingMode + * @memberof google.cloud.modelarmor.v1beta.SanitizeUserPromptRequest + * @instance + */ + SanitizeUserPromptRequest.prototype.streamingMode = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + // Virtual OneOf for proto3 optional field + Object.defineProperty(SanitizeUserPromptRequest.prototype, "_streamingMode", { + get: $util.oneOfGetter($oneOfFields = ["streamingMode"]), + set: $util.oneOfSetter($oneOfFields) + }); + /** * Creates a new SanitizeUserPromptRequest instance using the specified properties. * @function create @@ -21442,6 +21904,8 @@ $root.google.cloud.modelarmor.v1beta.DataItem.encode(message.userPromptData, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); if (message.multiLanguageDetectionMetadata != null && Object.hasOwnProperty.call(message, "multiLanguageDetectionMetadata")) $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.encode(message.multiLanguageDetectionMetadata, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); + if (message.streamingMode != null && Object.hasOwnProperty.call(message, "streamingMode")) + writer.uint32(/* id 7, wireType 0 =*/56).int32(message.streamingMode); return writer; }; @@ -21490,6 +21954,10 @@ message.multiLanguageDetectionMetadata = $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.decode(reader, reader.uint32()); break; } + case 7: { + message.streamingMode = reader.int32(); + break; + } default: reader.skipType(tag & 7); break; @@ -21525,6 +21993,7 @@ SanitizeUserPromptRequest.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + var properties = {}; if (message.name != null && message.hasOwnProperty("name")) if (!$util.isString(message.name)) return "name: string expected"; @@ -21538,6 +22007,17 @@ if (error) return "multiLanguageDetectionMetadata." + error; } + if (message.streamingMode != null && message.hasOwnProperty("streamingMode")) { + properties._streamingMode = 1; + switch (message.streamingMode) { + default: + return "streamingMode: enum value expected"; + case 0: + case 1: + case 2: + break; + } + } return null; }; @@ -21565,6 +22045,26 @@ throw TypeError(".google.cloud.modelarmor.v1beta.SanitizeUserPromptRequest.multiLanguageDetectionMetadata: object expected"); message.multiLanguageDetectionMetadata = $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.fromObject(object.multiLanguageDetectionMetadata); } + switch (object.streamingMode) { + default: + if (typeof object.streamingMode === "number") { + message.streamingMode = object.streamingMode; + break; + } + break; + case "STREAMING_MODE_UNSPECIFIED": + case 0: + message.streamingMode = 0; + break; + case "STREAMING_MODE_BUFFERED": + case 1: + message.streamingMode = 1; + break; + case "STREAMING_MODE_REALTIME": + case 2: + message.streamingMode = 2; + break; + } return message; }; @@ -21592,6 +22092,11 @@ object.userPromptData = $root.google.cloud.modelarmor.v1beta.DataItem.toObject(message.userPromptData, options); if (message.multiLanguageDetectionMetadata != null && message.hasOwnProperty("multiLanguageDetectionMetadata")) object.multiLanguageDetectionMetadata = $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.toObject(message.multiLanguageDetectionMetadata, options); + if (message.streamingMode != null && message.hasOwnProperty("streamingMode")) { + object.streamingMode = options.enums === String ? $root.google.cloud.modelarmor.v1beta.StreamingMode[message.streamingMode] === undefined ? message.streamingMode : $root.google.cloud.modelarmor.v1beta.StreamingMode[message.streamingMode] : message.streamingMode; + if (options.oneofs) + object._streamingMode = "streamingMode"; + } return object; }; @@ -21634,6 +22139,7 @@ * @property {google.cloud.modelarmor.v1beta.IDataItem|null} [modelResponseData] SanitizeModelResponseRequest modelResponseData * @property {string|null} [userPrompt] SanitizeModelResponseRequest userPrompt * @property {google.cloud.modelarmor.v1beta.IMultiLanguageDetectionMetadata|null} [multiLanguageDetectionMetadata] SanitizeModelResponseRequest multiLanguageDetectionMetadata + * @property {google.cloud.modelarmor.v1beta.StreamingMode|null} [streamingMode] SanitizeModelResponseRequest streamingMode */ /** @@ -21683,6 +22189,23 @@ */ SanitizeModelResponseRequest.prototype.multiLanguageDetectionMetadata = null; + /** + * SanitizeModelResponseRequest streamingMode. + * @member {google.cloud.modelarmor.v1beta.StreamingMode|null|undefined} streamingMode + * @memberof google.cloud.modelarmor.v1beta.SanitizeModelResponseRequest + * @instance + */ + SanitizeModelResponseRequest.prototype.streamingMode = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + // Virtual OneOf for proto3 optional field + Object.defineProperty(SanitizeModelResponseRequest.prototype, "_streamingMode", { + get: $util.oneOfGetter($oneOfFields = ["streamingMode"]), + set: $util.oneOfSetter($oneOfFields) + }); + /** * Creates a new SanitizeModelResponseRequest instance using the specified properties. * @function create @@ -21715,6 +22238,8 @@ writer.uint32(/* id 4, wireType 2 =*/34).string(message.userPrompt); if (message.multiLanguageDetectionMetadata != null && Object.hasOwnProperty.call(message, "multiLanguageDetectionMetadata")) $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.encode(message.multiLanguageDetectionMetadata, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim(); + if (message.streamingMode != null && Object.hasOwnProperty.call(message, "streamingMode")) + writer.uint32(/* id 8, wireType 0 =*/64).int32(message.streamingMode); return writer; }; @@ -21767,6 +22292,10 @@ message.multiLanguageDetectionMetadata = $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.decode(reader, reader.uint32()); break; } + case 8: { + message.streamingMode = reader.int32(); + break; + } default: reader.skipType(tag & 7); break; @@ -21802,6 +22331,7 @@ SanitizeModelResponseRequest.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + var properties = {}; if (message.name != null && message.hasOwnProperty("name")) if (!$util.isString(message.name)) return "name: string expected"; @@ -21818,6 +22348,17 @@ if (error) return "multiLanguageDetectionMetadata." + error; } + if (message.streamingMode != null && message.hasOwnProperty("streamingMode")) { + properties._streamingMode = 1; + switch (message.streamingMode) { + default: + return "streamingMode: enum value expected"; + case 0: + case 1: + case 2: + break; + } + } return null; }; @@ -21847,6 +22388,26 @@ throw TypeError(".google.cloud.modelarmor.v1beta.SanitizeModelResponseRequest.multiLanguageDetectionMetadata: object expected"); message.multiLanguageDetectionMetadata = $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.fromObject(object.multiLanguageDetectionMetadata); } + switch (object.streamingMode) { + default: + if (typeof object.streamingMode === "number") { + message.streamingMode = object.streamingMode; + break; + } + break; + case "STREAMING_MODE_UNSPECIFIED": + case 0: + message.streamingMode = 0; + break; + case "STREAMING_MODE_BUFFERED": + case 1: + message.streamingMode = 1; + break; + case "STREAMING_MODE_REALTIME": + case 2: + message.streamingMode = 2; + break; + } return message; }; @@ -21877,6 +22438,11 @@ object.userPrompt = message.userPrompt; if (message.multiLanguageDetectionMetadata != null && message.hasOwnProperty("multiLanguageDetectionMetadata")) object.multiLanguageDetectionMetadata = $root.google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata.toObject(message.multiLanguageDetectionMetadata, options); + if (message.streamingMode != null && message.hasOwnProperty("streamingMode")) { + object.streamingMode = options.enums === String ? $root.google.cloud.modelarmor.v1beta.StreamingMode[message.streamingMode] === undefined ? message.streamingMode : $root.google.cloud.modelarmor.v1beta.StreamingMode[message.streamingMode] : message.streamingMode; + if (options.oneofs) + object._streamingMode = "streamingMode"; + } return object; }; @@ -25251,6 +25817,7 @@ * @interface IByteDataItem * @property {google.cloud.modelarmor.v1beta.ByteDataItem.ByteItemType|null} [byteDataType] ByteDataItem byteDataType * @property {Uint8Array|null} [byteData] ByteDataItem byteData + * @property {string|null} [fileLabel] ByteDataItem fileLabel */ /** @@ -25284,6 +25851,14 @@ */ ByteDataItem.prototype.byteData = $util.newBuffer([]); + /** + * ByteDataItem fileLabel. + * @member {string} fileLabel + * @memberof google.cloud.modelarmor.v1beta.ByteDataItem + * @instance + */ + ByteDataItem.prototype.fileLabel = ""; + /** * Creates a new ByteDataItem instance using the specified properties. * @function create @@ -25312,6 +25887,8 @@ writer.uint32(/* id 1, wireType 0 =*/8).int32(message.byteDataType); if (message.byteData != null && Object.hasOwnProperty.call(message, "byteData")) writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.byteData); + if (message.fileLabel != null && Object.hasOwnProperty.call(message, "fileLabel")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.fileLabel); return writer; }; @@ -25356,6 +25933,10 @@ message.byteData = reader.bytes(); break; } + case 3: { + message.fileLabel = reader.string(); + break; + } default: reader.skipType(tag & 7); break; @@ -25403,11 +25984,15 @@ case 5: case 6: case 7: + case 9: break; } if (message.byteData != null && message.hasOwnProperty("byteData")) if (!(message.byteData && typeof message.byteData.length === "number" || $util.isString(message.byteData))) return "byteData: buffer expected"; + if (message.fileLabel != null && message.hasOwnProperty("fileLabel")) + if (!$util.isString(message.fileLabel)) + return "fileLabel: string expected"; return null; }; @@ -25462,12 +26047,18 @@ case 7: message.byteDataType = 7; break; + case "ZIP": + case 9: + message.byteDataType = 9; + break; } if (object.byteData != null) if (typeof object.byteData === "string") $util.base64.decode(object.byteData, message.byteData = $util.newBuffer($util.base64.length(object.byteData)), 0); else if (object.byteData.length >= 0) message.byteData = object.byteData; + if (object.fileLabel != null) + message.fileLabel = String(object.fileLabel); return message; }; @@ -25493,11 +26084,14 @@ if (options.bytes !== Array) object.byteData = $util.newBuffer(object.byteData); } + object.fileLabel = ""; } if (message.byteDataType != null && message.hasOwnProperty("byteDataType")) object.byteDataType = options.enums === String ? $root.google.cloud.modelarmor.v1beta.ByteDataItem.ByteItemType[message.byteDataType] === undefined ? message.byteDataType : $root.google.cloud.modelarmor.v1beta.ByteDataItem.ByteItemType[message.byteDataType] : message.byteDataType; if (message.byteData != null && message.hasOwnProperty("byteData")) object.byteData = options.bytes === String ? $util.base64.encode(message.byteData, 0, message.byteData.length) : options.bytes === Array ? Array.prototype.slice.call(message.byteData) : message.byteData; + if (message.fileLabel != null && message.hasOwnProperty("fileLabel")) + object.fileLabel = message.fileLabel; return object; }; @@ -25539,6 +26133,7 @@ * @property {number} POWERPOINT_DOCUMENT=5 POWERPOINT_DOCUMENT value * @property {number} TXT=6 TXT value * @property {number} CSV=7 CSV value + * @property {number} ZIP=9 ZIP value */ ByteDataItem.ByteItemType = (function() { var valuesById = {}, values = Object.create(valuesById); @@ -25550,6 +26145,7 @@ values[valuesById[5] = "POWERPOINT_DOCUMENT"] = 5; values[valuesById[6] = "TXT"] = 6; values[valuesById[7] = "CSV"] = 7; + values[valuesById[9] = "ZIP"] = 9; return values; })(); diff --git a/packages/google-cloud-modelarmor/protos/protos.json b/packages/google-cloud-modelarmor/protos/protos.json index 6bb3d884314f..a00caed237a5 100644 --- a/packages/google-cloud-modelarmor/protos/protos.json +++ b/packages/google-cloud-modelarmor/protos/protos.json @@ -1742,6 +1742,18 @@ } } ] + }, + "StreamSanitizeUserPrompt": { + "requestType": "SanitizeUserPromptRequest", + "requestStream": true, + "responseType": "SanitizeUserPromptResponse", + "responseStream": true + }, + "StreamSanitizeModelResponse": { + "requestType": "SanitizeModelResponseRequest", + "requestStream": true, + "responseType": "SanitizeModelResponseResponse", + "responseStream": true } } }, @@ -1794,6 +1806,13 @@ "FAILURE": 3 } }, + "StreamingMode": { + "values": { + "STREAMING_MODE_UNSPECIFIED": 0, + "STREAMING_MODE_BUFFERED": 1, + "STREAMING_MODE_REALTIME": 2 + } + }, "Template": { "options": { "(google.api.resource).type": "modelarmor.googleapis.com/Template", @@ -1953,6 +1972,11 @@ "oneof": [ "aiPlatformFloorSetting" ] + }, + "_googleMcpServerFloorSetting": { + "oneof": [ + "googleMcpServerFloorSetting" + ] } }, "fields": { @@ -2014,6 +2038,14 @@ "options": { "(google.api.field_behavior)": "OPTIONAL" } + }, + "googleMcpServerFloorSetting": { + "type": "McpServerFloorSetting", + "id": 9, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "proto3_optional": true + } } }, "nested": { @@ -2044,7 +2076,49 @@ "IntegratedService": { "values": { "INTEGRATED_SERVICE_UNSPECIFIED": 0, - "AI_PLATFORM": 1 + "AI_PLATFORM": 1, + "GOOGLE_MCP_SERVER": 2 + } + } + } + }, + "McpServerFloorSetting": { + "oneofs": { + "enforcementType": { + "oneof": [ + "inspectOnly", + "inspectAndBlock" + ] + } + }, + "fields": { + "inspectOnly": { + "type": "bool", + "id": 1, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "inspectAndBlock": { + "type": "bool", + "id": 2, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "enableCloudLogging": { + "type": "bool", + "id": 3, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "apis": { + "rule": "repeated", + "type": "string", + "id": 4, + "options": { + "(google.api.field_behavior)": "OPTIONAL" } } } @@ -2438,6 +2512,13 @@ } }, "SanitizeUserPromptRequest": { + "oneofs": { + "_streamingMode": { + "oneof": [ + "streamingMode" + ] + } + }, "fields": { "name": { "type": "string", @@ -2460,10 +2541,25 @@ "options": { "(google.api.field_behavior)": "OPTIONAL" } + }, + "streamingMode": { + "type": "StreamingMode", + "id": 7, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "proto3_optional": true + } } } }, "SanitizeModelResponseRequest": { + "oneofs": { + "_streamingMode": { + "oneof": [ + "streamingMode" + ] + } + }, "fields": { "name": { "type": "string", @@ -2493,6 +2589,14 @@ "options": { "(google.api.field_behavior)": "OPTIONAL" } + }, + "streamingMode": { + "type": "StreamingMode", + "id": 8, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "proto3_optional": true + } } } }, @@ -2763,6 +2867,13 @@ "options": { "(google.api.field_behavior)": "REQUIRED" } + }, + "fileLabel": { + "type": "string", + "id": 3, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } } }, "nested": { @@ -2775,7 +2886,8 @@ "EXCEL_DOCUMENT": 4, "POWERPOINT_DOCUMENT": 5, "TXT": 6, - "CSV": 7 + "CSV": 7, + "ZIP": 9 } } } diff --git a/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_model_response.js b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_model_response.js index ab8b43a92ceb..ff8661b213c7 100644 --- a/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_model_response.js +++ b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_model_response.js @@ -45,6 +45,10 @@ function main(name, modelResponseData) { * Optional. Metadata related for multi language detection. */ // const multiLanguageDetectionMetadata = {} + /** + * Optional. Streaming Mode for StreamSanitize* API. + */ + // const streamingMode = {} // Imports the Modelarmor library const {ModelArmorClient} = require('@google-cloud/modelarmor').v1beta; diff --git a/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_user_prompt.js b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_user_prompt.js index 9be991bb8e50..3ca6c61d46c7 100644 --- a/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_user_prompt.js +++ b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.sanitize_user_prompt.js @@ -41,6 +41,10 @@ function main(name, userPromptData) { * Optional. Metadata related to Multi Language Detection. */ // const multiLanguageDetectionMetadata = {} + /** + * Optional. Streaming Mode for StreamSanitize* API. + */ + // const streamingMode = {} // Imports the Modelarmor library const {ModelArmorClient} = require('@google-cloud/modelarmor').v1beta; diff --git a/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_model_response.js b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_model_response.js new file mode 100644 index 000000000000..53003fec9ee1 --- /dev/null +++ b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_model_response.js @@ -0,0 +1,83 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main(name, modelResponseData) { + // [START modelarmor_v1beta_generated_ModelArmor_StreamSanitizeModelResponse_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. Represents resource name of template + * e.g. name=projects/sample-project/locations/us-central1/templates/templ01 + */ + // const name = 'abc123' + /** + * Required. Model response data to sanitize. + */ + // const modelResponseData = {} + /** + * Optional. User Prompt associated with Model response. + */ + // const userPrompt = 'abc123' + /** + * Optional. Metadata related for multi language detection. + */ + // const multiLanguageDetectionMetadata = {} + /** + * Optional. Streaming Mode for StreamSanitize* API. + */ + // const streamingMode = {} + + // Imports the Modelarmor library + const {ModelArmorClient} = require('@google-cloud/modelarmor').v1beta; + + // Instantiates a client + const modelarmorClient = new ModelArmorClient(); + + async function callStreamSanitizeModelResponse() { + // Construct request + const request = { + name, + modelResponseData, + }; + + // Run request + const stream = await modelarmorClient.streamSanitizeModelResponse(); + stream.on('data', (response) => { console.log(response) }); + stream.on('error', (err) => { throw(err) }); + stream.on('end', () => { /* API call completed */ }); + stream.write(request); + stream.end(); + } + + callStreamSanitizeModelResponse(); + // [END modelarmor_v1beta_generated_ModelArmor_StreamSanitizeModelResponse_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_user_prompt.js b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_user_prompt.js new file mode 100644 index 000000000000..7c8c1c9482e8 --- /dev/null +++ b/packages/google-cloud-modelarmor/samples/generated/v1beta/model_armor.stream_sanitize_user_prompt.js @@ -0,0 +1,79 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main(name, userPromptData) { + // [START modelarmor_v1beta_generated_ModelArmor_StreamSanitizeUserPrompt_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. Represents resource name of template + * e.g. name=projects/sample-project/locations/us-central1/templates/templ01 + */ + // const name = 'abc123' + /** + * Required. User prompt data to sanitize. + */ + // const userPromptData = {} + /** + * Optional. Metadata related to Multi Language Detection. + */ + // const multiLanguageDetectionMetadata = {} + /** + * Optional. Streaming Mode for StreamSanitize* API. + */ + // const streamingMode = {} + + // Imports the Modelarmor library + const {ModelArmorClient} = require('@google-cloud/modelarmor').v1beta; + + // Instantiates a client + const modelarmorClient = new ModelArmorClient(); + + async function callStreamSanitizeUserPrompt() { + // Construct request + const request = { + name, + userPromptData, + }; + + // Run request + const stream = await modelarmorClient.streamSanitizeUserPrompt(); + stream.on('data', (response) => { console.log(response) }); + stream.on('error', (err) => { throw(err) }); + stream.on('end', () => { /* API call completed */ }); + stream.write(request); + stream.end(); + } + + callStreamSanitizeUserPrompt(); + // [END modelarmor_v1beta_generated_ModelArmor_StreamSanitizeUserPrompt_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-modelarmor/samples/generated/v1beta/snippet_metadata_google.cloud.modelarmor.v1beta.json b/packages/google-cloud-modelarmor/samples/generated/v1beta/snippet_metadata_google.cloud.modelarmor.v1beta.json index d0a88c3654a5..ebea3de18755 100644 --- a/packages/google-cloud-modelarmor/samples/generated/v1beta/snippet_metadata_google.cloud.modelarmor.v1beta.json +++ b/packages/google-cloud-modelarmor/samples/generated/v1beta/snippet_metadata_google.cloud.modelarmor.v1beta.json @@ -346,7 +346,7 @@ "segments": [ { "start": 25, - "end": 63, + "end": 67, "type": "FULL" } ], @@ -366,6 +366,10 @@ { "name": "multi_language_detection_metadata", "type": ".google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata" + }, + { + "name": "streaming_mode", + "type": ".google.cloud.modelarmor.v1beta.StreamingMode" } ], "resultType": ".google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse", @@ -394,7 +398,7 @@ "segments": [ { "start": 25, - "end": 67, + "end": 71, "type": "FULL" } ], @@ -418,6 +422,10 @@ { "name": "multi_language_detection_metadata", "type": ".google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata" + }, + { + "name": "streaming_mode", + "type": ".google.cloud.modelarmor.v1beta.StreamingMode" } ], "resultType": ".google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse", @@ -434,6 +442,114 @@ } } } + }, + { + "regionTag": "modelarmor_v1beta_generated_ModelArmor_StreamSanitizeUserPrompt_async", + "title": "ModelArmor streamSanitizeUserPrompt Sample", + "origin": "API_DEFINITION", + "description": " Streaming version of Sanitize User Prompt.", + "canonical": true, + "file": "model_armor.stream_sanitize_user_prompt.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 71, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "StreamSanitizeUserPrompt", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeUserPrompt", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "user_prompt_data", + "type": ".google.cloud.modelarmor.v1beta.DataItem" + }, + { + "name": "multi_language_detection_metadata", + "type": ".google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata" + }, + { + "name": "streaming_mode", + "type": ".google.cloud.modelarmor.v1beta.StreamingMode" + } + ], + "resultType": ".google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse", + "client": { + "shortName": "ModelArmorClient", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmorClient" + }, + "method": { + "shortName": "StreamSanitizeUserPrompt", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeUserPrompt", + "service": { + "shortName": "ModelArmor", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmor" + } + } + } + }, + { + "regionTag": "modelarmor_v1beta_generated_ModelArmor_StreamSanitizeModelResponse_async", + "title": "ModelArmor streamSanitizeModelResponse Sample", + "origin": "API_DEFINITION", + "description": " Streaming version of Sanitizes Model Response.", + "canonical": true, + "file": "model_armor.stream_sanitize_model_response.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 75, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "StreamSanitizeModelResponse", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeModelResponse", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "model_response_data", + "type": ".google.cloud.modelarmor.v1beta.DataItem" + }, + { + "name": "user_prompt", + "type": "TYPE_STRING" + }, + { + "name": "multi_language_detection_metadata", + "type": ".google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata" + }, + { + "name": "streaming_mode", + "type": ".google.cloud.modelarmor.v1beta.StreamingMode" + } + ], + "resultType": ".google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse", + "client": { + "shortName": "ModelArmorClient", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmorClient" + }, + "method": { + "shortName": "StreamSanitizeModelResponse", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmor.StreamSanitizeModelResponse", + "service": { + "shortName": "ModelArmor", + "fullName": "google.cloud.modelarmor.v1beta.ModelArmor" + } + } + } } ] } diff --git a/packages/google-cloud-modelarmor/src/v1beta/gapic_metadata.json b/packages/google-cloud-modelarmor/src/v1beta/gapic_metadata.json index 197556959084..75ae88d290ac 100644 --- a/packages/google-cloud-modelarmor/src/v1beta/gapic_metadata.json +++ b/packages/google-cloud-modelarmor/src/v1beta/gapic_metadata.json @@ -50,6 +50,16 @@ "sanitizeModelResponse" ] }, + "StreamSanitizeUserPrompt": { + "methods": [ + "streamSanitizeUserPrompt" + ] + }, + "StreamSanitizeModelResponse": { + "methods": [ + "streamSanitizeModelResponse" + ] + }, "ListTemplates": { "methods": [ "listTemplates", diff --git a/packages/google-cloud-modelarmor/src/v1beta/model_armor_client.ts b/packages/google-cloud-modelarmor/src/v1beta/model_armor_client.ts index f8ed2ce8c937..98d48ac8361c 100644 --- a/packages/google-cloud-modelarmor/src/v1beta/model_armor_client.ts +++ b/packages/google-cloud-modelarmor/src/v1beta/model_armor_client.ts @@ -19,7 +19,7 @@ /* global window */ import type * as gax from 'google-gax'; import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, LocationsClient, LocationProtos} from 'google-gax'; -import {Transform} from 'stream'; +import {Transform, PassThrough} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; @@ -211,6 +211,13 @@ export class ModelArmorClient { new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'templates') }; + // Some of the methods on this service provide streaming responses. + // Provide descriptors for these. + this.descriptors.stream = { + streamSanitizeUserPrompt: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries), + streamSanitizeModelResponse: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries) + }; + // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.modelarmor.v1beta.ModelArmor', gapicConfig as gax.ClientConfig, @@ -254,11 +261,18 @@ export class ModelArmorClient { // Iterate over each of the methods that the service provides // and create an API call method for each. const modelArmorStubMethods = - ['listTemplates', 'getTemplate', 'createTemplate', 'updateTemplate', 'deleteTemplate', 'getFloorSetting', 'updateFloorSetting', 'sanitizeUserPrompt', 'sanitizeModelResponse']; + ['listTemplates', 'getTemplate', 'createTemplate', 'updateTemplate', 'deleteTemplate', 'getFloorSetting', 'updateFloorSetting', 'sanitizeUserPrompt', 'sanitizeModelResponse', 'streamSanitizeUserPrompt', 'streamSanitizeModelResponse']; for (const methodName of modelArmorStubMethods) { const callPromise = this.modelArmorStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { + if (methodName in this.descriptors.stream) { + const stream = new PassThrough({objectMode: true}); + setImmediate(() => { + stream.emit('error', new this._gaxModule.GoogleError('The client has already been closed.')); + }); + return stream; + } return Promise.reject('The client has already been closed.'); } const func = stub[methodName]; @@ -270,6 +284,7 @@ export class ModelArmorClient { const descriptor = this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || undefined; const apiCall = this._gaxModule.createApiCall( callPromise, @@ -994,6 +1009,8 @@ export class ModelArmorClient { * Required. User prompt data to sanitize. * @param {google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata} [request.multiLanguageDetectionMetadata] * Optional. Metadata related to Multi Language Detection. + * @param {google.cloud.modelarmor.v1beta.StreamingMode} [request.streamingMode] + * Optional. Streaming Mode for StreamSanitize* API. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -1095,6 +1112,8 @@ export class ModelArmorClient { * Optional. User Prompt associated with Model response. * @param {google.cloud.modelarmor.v1beta.MultiLanguageDetectionMetadata} [request.multiLanguageDetectionMetadata] * Optional. Metadata related for multi language detection. + * @param {google.cloud.modelarmor.v1beta.StreamingMode} [request.streamingMode] + * Optional. Streaming Mode for StreamSanitize* API. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -1183,6 +1202,50 @@ export class ModelArmorClient { }); } +/** + * Streaming version of Sanitize User Prompt. + * + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which is both readable and writable. It accepts objects + * representing {@link protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptRequest|SanitizeUserPromptRequest} for write() method, and + * will emit objects representing {@link protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse|SanitizeUserPromptResponse} on 'data' event asynchronously. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } + * for more details and examples. + * @example include:samples/generated/v1beta/model_armor.stream_sanitize_user_prompt.js + * region_tag:modelarmor_v1beta_generated_ModelArmor_StreamSanitizeUserPrompt_async + */ + streamSanitizeUserPrompt( + options?: CallOptions): + gax.CancellableStream { + this.initialize().catch(err => {throw err}); + this._log.info('streamSanitizeUserPrompt stream %j', options); + return this.innerApiCalls.streamSanitizeUserPrompt(null, options); + } + +/** + * Streaming version of Sanitizes Model Response. + * + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which is both readable and writable. It accepts objects + * representing {@link protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseRequest|SanitizeModelResponseRequest} for write() method, and + * will emit objects representing {@link protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse|SanitizeModelResponseResponse} on 'data' event asynchronously. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } + * for more details and examples. + * @example include:samples/generated/v1beta/model_armor.stream_sanitize_model_response.js + * region_tag:modelarmor_v1beta_generated_ModelArmor_StreamSanitizeModelResponse_async + */ + streamSanitizeModelResponse( + options?: CallOptions): + gax.CancellableStream { + this.initialize().catch(err => {throw err}); + this._log.info('streamSanitizeModelResponse stream %j', options); + return this.innerApiCalls.streamSanitizeModelResponse(null, options); + } + /** * Lists Templates in a given project and location. * diff --git a/packages/google-cloud-modelarmor/src/v1beta/model_armor_client_config.json b/packages/google-cloud-modelarmor/src/v1beta/model_armor_client_config.json index 73f1e2fdf781..345fd79f2798 100644 --- a/packages/google-cloud-modelarmor/src/v1beta/model_armor_client_config.json +++ b/packages/google-cloud-modelarmor/src/v1beta/model_armor_client_config.json @@ -76,6 +76,14 @@ "timeout_millis": 60000, "retry_codes_name": "unavailable", "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "StreamSanitizeUserPrompt": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "StreamSanitizeModelResponse": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" } } } diff --git a/packages/google-cloud-modelarmor/test/gapic_model_armor_v1beta.ts b/packages/google-cloud-modelarmor/test/gapic_model_armor_v1beta.ts index ddb2bcf0d56c..ac5943005662 100644 --- a/packages/google-cloud-modelarmor/test/gapic_model_armor_v1beta.ts +++ b/packages/google-cloud-modelarmor/test/gapic_model_armor_v1beta.ts @@ -54,6 +54,15 @@ function stubSimpleCallWithCallback(response?: ResponseType, error return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); } +function stubBidiStreamingCall(response?: ResponseType, error?: Error) { + const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + return sinon.stub().returns(mockStream); +} + function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { const pagingStub = sinon.stub(); if (responses) { @@ -1131,6 +1140,134 @@ describe('v1beta.ModelArmorClient', () => { }); }); + describe('streamSanitizeUserPrompt', () => { + it('invokes streamSanitizeUserPrompt without error', async () => { + const client = new modelarmorModule.v1beta.ModelArmorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptRequest() + ); + + const expectedResponse = generateSampleMessage( + new protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse() + ); + client.innerApiCalls.streamSanitizeUserPrompt = stubBidiStreamingCall(expectedResponse); + const stream = client.streamSanitizeUserPrompt(); + const promise = new Promise((resolve, reject) => { + stream.on('data', (response: protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse) => { + resolve(response); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + stream.write(request); + stream.end(); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.streamSanitizeUserPrompt as SinonStub) + .getCall(0).calledWith(null)); + assert.deepStrictEqual(((stream as unknown as PassThrough) + ._transform as SinonStub).getCall(0).args[0], request); + }); + + it('invokes streamSanitizeUserPrompt with error', async () => { + const client = new modelarmorModule.v1beta.ModelArmorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.streamSanitizeUserPrompt = stubBidiStreamingCall(undefined, expectedError); + const stream = client.streamSanitizeUserPrompt(); + const promise = new Promise((resolve, reject) => { + stream.on('data', (response: protos.google.cloud.modelarmor.v1beta.SanitizeUserPromptResponse) => { + resolve(response); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + stream.write(request); + stream.end(); + }); + await assert.rejects(promise, expectedError); + assert((client.innerApiCalls.streamSanitizeUserPrompt as SinonStub) + .getCall(0).calledWith(null)); + assert.deepStrictEqual(((stream as unknown as PassThrough) + ._transform as SinonStub).getCall(0).args[0], request); + }); + }); + + describe('streamSanitizeModelResponse', () => { + it('invokes streamSanitizeModelResponse without error', async () => { + const client = new modelarmorModule.v1beta.ModelArmorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseRequest() + ); + + const expectedResponse = generateSampleMessage( + new protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse() + ); + client.innerApiCalls.streamSanitizeModelResponse = stubBidiStreamingCall(expectedResponse); + const stream = client.streamSanitizeModelResponse(); + const promise = new Promise((resolve, reject) => { + stream.on('data', (response: protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse) => { + resolve(response); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + stream.write(request); + stream.end(); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.streamSanitizeModelResponse as SinonStub) + .getCall(0).calledWith(null)); + assert.deepStrictEqual(((stream as unknown as PassThrough) + ._transform as SinonStub).getCall(0).args[0], request); + }); + + it('invokes streamSanitizeModelResponse with error', async () => { + const client = new modelarmorModule.v1beta.ModelArmorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.streamSanitizeModelResponse = stubBidiStreamingCall(undefined, expectedError); + const stream = client.streamSanitizeModelResponse(); + const promise = new Promise((resolve, reject) => { + stream.on('data', (response: protos.google.cloud.modelarmor.v1beta.SanitizeModelResponseResponse) => { + resolve(response); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + stream.write(request); + stream.end(); + }); + await assert.rejects(promise, expectedError); + assert((client.innerApiCalls.streamSanitizeModelResponse as SinonStub) + .getCall(0).calledWith(null)); + assert.deepStrictEqual(((stream as unknown as PassThrough) + ._transform as SinonStub).getCall(0).args[0], request); + }); + }); + describe('listTemplates', () => { it('invokes listTemplates without error', async () => { const client = new modelarmorModule.v1beta.ModelArmorClient({