Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/generate-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ fn generate_google_types_with_quicktype(spec: &serde_json::Value) {

let _ = std::fs::remove_file(&temp_schema_path);

let quicktype_output = strip_quicktype_preamble(&quicktype_output);
let processed_output = post_process_quicktype_output_for_google(&quicktype_output);

let dest_path = "crates/lingua/src/providers/google/generated.rs";
Expand Down Expand Up @@ -1647,6 +1648,27 @@ fn add_default_derive_to_structs(content: &str) -> String {
result_lines.join("\n")
}

/// Strip non-Rust preamble lines from quicktype stdout.
/// CI environments or quicktype itself may emit diagnostic text before the
/// actual generated Rust code. We skip forward to the first line that looks
/// like valid Rust source (comments, use/extern statements, attributes, etc.).
fn strip_quicktype_preamble(output: &str) -> String {
let lines: Vec<&str> = output.lines().collect();
let start = lines
.iter()
.position(|line| {
let trimmed = line.trim();
trimmed.is_empty()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip blank lines while stripping quicktype diagnostics

When quicktype or a CI wrapper emits a diagnostic preamble that contains a blank line before the first real Rust line, this predicate selects that blank line as the start of the generated source. Any subsequent non-Rust diagnostic lines remain in generated.rs, and the later cargo fmt result is ignored, so the generator can report success after writing an uncompilable file. Please skip empty lines until a real Rust token/comment has been found, then preserve blanks from there.

Useful? React with 👍 / 👎.

|| trimmed.starts_with("//")
|| trimmed.starts_with("use ")
|| trimmed.starts_with("extern ")
|| trimmed.starts_with("#[")
|| trimmed.starts_with("pub ")
})
.unwrap_or(0);
lines[start..].join("\n")
}

fn post_process_quicktype_output_for_google(quicktype_output: &str) -> String {
let mut processed = quicktype_output.to_string();

Expand Down
32 changes: 32 additions & 0 deletions crates/lingua/src/providers/google/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,12 @@ pub struct Tool {
#[serde(rename_all = "camelCase")]
#[ts(export_to = "google/")]
pub struct ComputerUse {
/// Optional. Disabled safety policies for computer use.
#[serde(skip_serializing_if = "Option::is_none")]
pub disabled_safety_policies: Option<Vec<DisabledSafetyPolicy>>,
/// Optional. Whether enable the prompt injection detection check on computer-use request.
#[serde(skip_serializing_if = "Option::is_none")]
pub enable_prompt_injection_detection: Option<bool>,
/// Required. The environment being operated.
#[serde(skip_serializing_if = "Option::is_none")]
pub environment: Option<Environment>,
Expand All @@ -1401,13 +1407,39 @@ pub struct ComputerUse {
pub excluded_predefined_functions: Option<Vec<String>>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[ts(export_to = "google/")]
pub enum DisabledSafetyPolicy {
#[serde(rename = "ACCOUNT_CREATION")]
AccountCreation,
#[serde(rename = "COMMUNICATION_TOOL")]
CommunicationTool,
#[serde(rename = "DATA_MODIFICATION")]
DataModification,
#[serde(rename = "FINANCIAL_TRANSACTIONS")]
FinancialTransactions,
#[serde(rename = "LEGAL_TERMS_AND_AGREEMENTS")]
LegalTermsAndAgreements,
#[serde(rename = "SAFETY_POLICY_UNSPECIFIED")]
SafetyPolicyUnspecified,
#[serde(rename = "SENSITIVE_DATA_MODIFICATION")]
SensitiveDataModification,
#[serde(rename = "USER_CONSENT_MANAGEMENT")]
UserConsentManagement,
}

/// Required. The environment being operated.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[ts(export_to = "google/")]
pub enum Environment {
#[serde(rename = "ENVIRONMENT_BROWSER")]
EnvironmentBrowser,
#[serde(rename = "ENVIRONMENT_DESKTOP")]
EnvironmentDesktop,
#[serde(rename = "ENVIRONMENT_MOBILE")]
EnvironmentMobile,
#[serde(rename = "ENVIRONMENT_UNSPECIFIED")]
EnvironmentUnspecified,
}
Expand Down
29 changes: 29 additions & 0 deletions provider-type-update-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Google provider type update notes

## Changes in this update

### `ComputerUse` struct (additive, optional fields)

Two new optional fields added:
- `disabled_safety_policies: Option<Vec<DisabledSafetyPolicy>>` -- safety policies to disable during computer use
- `enable_prompt_injection_detection: Option<bool>` -- flag for prompt injection detection

### New `DisabledSafetyPolicy` enum

Eight variants: `AccountCreation`, `CommunicationTool`, `DataModification`, `FinancialTransactions`, `LegalTermsAndAgreements`, `SafetyPolicyUnspecified`, `SensitiveDataModification`, `UserConsentManagement`.

### `Environment` enum (additive variants)

Two new variants: `EnvironmentDesktop`, `EnvironmentMobile` (joining existing `EnvironmentBrowser`, `EnvironmentUnspecified`).

### Generator improvement

New `strip_quicktype_preamble()` function strips non-Rust diagnostic lines that CI environments or quicktype may emit before generated code.

## Adapter/converter impact

No hand-written code changes required. All changes are within the `ComputerUse` type hierarchy, which is a field on the `Tool` struct. The tool converter already does not convert `computer_use` to/from `UniversalTool` (pre-existing gap -- it handles `function_declarations`, `google_search`, `code_execution`, `google_search_retrieval`, and `url_context` only). The new fields and variants are all optional/additive, so serialization and deserialization remain backward-compatible.

## Items for human review

**`computer_use` tool conversion**: If cross-provider computer-use support is planned, the `Tool.computer_use` field needs a `UniversalTool` representation (likely a new builtin tool type). The new `DisabledSafetyPolicy` and expanded `Environment` variants would need to be modeled as part of that builtin tool's config. This is a pre-existing gap, not caused by this update.
Loading
Loading