diff --git a/packages/pangea-node-sdk/CHANGELOG.md b/packages/pangea-node-sdk/CHANGELOG.md index d35de134c..a1789193f 100644 --- a/packages/pangea-node-sdk/CHANGELOG.md +++ b/packages/pangea-node-sdk/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## 5.3.0-beta.2 - 2025-07-25 + +### Changed + +- AI Guard: updated to latest multimodal guard API as of 2025-07-25. + ## 5.3.0-beta.1 - 2025-07-21 ### Changed diff --git a/packages/pangea-node-sdk/package.json b/packages/pangea-node-sdk/package.json index 113e46156..716cddda9 100644 --- a/packages/pangea-node-sdk/package.json +++ b/packages/pangea-node-sdk/package.json @@ -1,6 +1,6 @@ { "name": "pangea-node-sdk", - "version": "5.3.0-beta.1", + "version": "5.3.0-beta.2", "type": "commonjs", "main": "./dist/index.cjs", "types": "./dist/index.d.cts", diff --git a/packages/pangea-node-sdk/src/config.ts b/packages/pangea-node-sdk/src/config.ts index 4d0811bc9..7d722c944 100644 --- a/packages/pangea-node-sdk/src/config.ts +++ b/packages/pangea-node-sdk/src/config.ts @@ -1,4 +1,4 @@ -export const version = "5.3.0-beta.1"; +export const version = "5.3.0-beta.2"; /** Configuration for a Pangea service client. */ class PangeaConfig { diff --git a/packages/pangea-node-sdk/src/services/ai_guard.ts b/packages/pangea-node-sdk/src/services/ai_guard.ts index 147273e40..395736fd8 100644 --- a/packages/pangea-node-sdk/src/services/ai_guard.ts +++ b/packages/pangea-node-sdk/src/services/ai_guard.ts @@ -86,7 +86,7 @@ export class AIGuardService extends BaseService { */ async guard( request: Simplify - ): Promise> { + ): Promise> { return await this.post("v1beta/guard", request); } diff --git a/packages/pangea-node-sdk/src/types.ts b/packages/pangea-node-sdk/src/types.ts index f01488ab7..859b2b44a 100644 --- a/packages/pangea-node-sdk/src/types.ts +++ b/packages/pangea-node-sdk/src/types.ts @@ -517,6 +517,49 @@ export namespace Audit { } export namespace AIGuard { + export type SingleEntityResult = { + /** The action taken by this Detector */ + action?: string; + /** Detected entities. */ + entities?: string[]; + }; + + export type LanguageResult = { + /** The action taken by this Detector */ + action?: string; + language?: string; + }; + + export type TopicResult = { + /** The action taken by this Detector */ + action?: string; + /** List of topics detected */ + topics?: { topic: string; confidence: number }[]; + }; + + export type HardeningResult = { + /** The action taken by this Detector */ + action?: string; + /** Descriptive information about the hardening detector execution */ + message?: string; + /** Number of tokens counted in the last user prompt */ + token_count?: number; + }; + + export type PromptInjectionResult = { + /** The action taken by this Detector */ + action?: string; + /** Triggered prompt injection analyzers. */ + analyzer_responses?: { analyzer: string; confidence: number }[]; + }; + + export type ClassificationResult = { + /** The action taken by this Detector */ + action?: string; + /** Triggered classifications. */ + classifications?: { category: string; confidence: number }[]; + }; + export interface RedactEntityResult { /** Detected redaction rules. */ entities: { @@ -529,6 +572,17 @@ export namespace AIGuard { }[]; } + export type MaliciousEntityResult = { + /** Detected harmful items. */ + entities?: { + type: string; + value: string; + redacted?: boolean; + start_pos?: number; + raw?: { [key: string]: unknown }; + }[]; + }; + /** Additional fields to include in activity log */ export interface LogFields { /** Origin or source application of the event */ @@ -696,6 +750,111 @@ export namespace AIGuard { }; }; + /** + * Overrides flags. Note: This parameter has no effect when the request is + * made by AIDR + */ + export type GuardOverrides2 = { + /** Bypass existing Recipe content and create an on-the-fly Recipe. */ + ignore_recipe?: boolean; + code?: { + disabled?: boolean; + action?: "report" | "block"; + threshold?: number; + }; + language?: { + disabled?: boolean; + action?: "" | "report" | "allow" | "block"; + languages?: string[]; + threshold?: number; + }; + topic?: { + disabled?: boolean; + action?: "" | "report" | "block"; + topics?: string[]; + threshold?: number; + }; + malicious_prompt?: { + disabled?: boolean; + action?: PromptInjectionAction; + }; + malicious_entity?: { + disabled?: boolean; + ip_address?: MaliciousEntityAction; + url?: MaliciousEntityAction; + domain?: MaliciousEntityAction; + }; + competitors?: { + disabled?: boolean; + action?: "report" | "block"; + }; + confidential_and_pii_entity?: { + disabled?: boolean; + email_address?: PiiEntityAction; + nrp?: PiiEntityAction; + location?: PiiEntityAction; + person?: PiiEntityAction; + phone_number?: PiiEntityAction; + date_time?: PiiEntityAction; + ip_address?: PiiEntityAction; + url?: PiiEntityAction; + money?: PiiEntityAction; + credit_card?: PiiEntityAction; + crypto?: PiiEntityAction; + iban_code?: PiiEntityAction; + us_bank_number?: PiiEntityAction; + nif?: PiiEntityAction; + "fin/nric"?: PiiEntityAction; + au_abn?: PiiEntityAction; + au_acn?: PiiEntityAction; + au_tfn?: PiiEntityAction; + medical_license?: PiiEntityAction; + uk_nhs?: PiiEntityAction; + au_medicare?: PiiEntityAction; + us_drivers_license?: PiiEntityAction; + us_itin?: PiiEntityAction; + us_passport?: PiiEntityAction; + us_ssn?: PiiEntityAction; + }; + secret_and_key_entity?: { + disabled?: boolean; + slack_token?: PiiEntityAction; + rsa_private_key?: PiiEntityAction; + ssh_dsa_private_key?: PiiEntityAction; + ssh_ec_private_key?: PiiEntityAction; + pgp_private_key_block?: PiiEntityAction; + amazon_aws_access_key_id?: PiiEntityAction; + amazon_aws_secret_access_key?: PiiEntityAction; + amazon_mws_auth_token?: PiiEntityAction; + facebook_access_token?: PiiEntityAction; + github_access_token?: PiiEntityAction; + jwt_token?: PiiEntityAction; + google_api_key?: PiiEntityAction; + google_cloud_platform_api_key?: PiiEntityAction; + google_drive_api_key?: PiiEntityAction; + google_cloud_platform_service_account?: PiiEntityAction; + google_gmail_api_key?: PiiEntityAction; + youtube_api_key?: PiiEntityAction; + mailchimp_api_key?: PiiEntityAction; + mailgun_api_key?: PiiEntityAction; + basic_auth?: PiiEntityAction; + picatic_api_key?: PiiEntityAction; + slack_webhook?: PiiEntityAction; + stripe_api_key?: PiiEntityAction; + stripe_restricted_api_key?: PiiEntityAction; + square_access_token?: PiiEntityAction; + square_oauth_secret?: PiiEntityAction; + twilio_api_key?: PiiEntityAction; + pangea_token?: PiiEntityAction; + }; + image?: { + disabled?: boolean; + action?: "" | "report" | "block"; + topics?: string[]; + threshold?: number; + }; + }; + export interface TextGuardRequest { /** * Recipe key of a configuration of data types and settings defined in the @@ -719,41 +878,24 @@ export namespace AIGuard { export interface TextGuardResult { /** Result of the recipe analyzing and input prompt. */ detectors: { - prompt_injection: Detector<{ - /** The action taken by this Detector */ - action: string; - - /** Triggered prompt injection analyzers. */ - analyzer_responses: { analyzer: string; confidence: number }[]; - }>; + prompt_injection?: Detector; + gibberish?: Detector; + sentiment?: Detector; + selfharm?: Detector; pii_entity?: Detector; - malicious_entity?: Detector<{ - /** Detected harmful items. */ - entities: MaliciousEntity[]; - }>; + malicious_entity?: Detector; custom_entity?: Detector; secrets_detection?: Detector; - profanity_and_toxicity?: Detector; - language_detection?: Detector<{ - /** The action taken by this Detector */ - action: string; - language: string; - }>; - topic_detection?: Detector<{ - /** The action taken by this Detector */ - action: string; - }>; - topic?: Detector<{ - /** The action taken by this Detector */ - action?: string; - /** List of topics detected */ - topics?: { topic: string; confidence: number }[]; - }>; - code_detection?: Detector<{ - /** The action taken by this Detector */ - action: string; - language: string; - }>; + competitors?: Detector; + profanity_and_toxicity?: Detector; + // Prompt Hardening does not have `detected`. + hardening?: { + /** Details about the detected languages. */ + data?: HardeningResult; + }; + language_detection?: Detector; + topic?: Detector; + code_detection?: Detector; }; /** Updated prompt text, if applicable. */ @@ -802,9 +944,8 @@ export namespace AIGuard { * data. */ debug?: boolean; - overrides?: GuardOverrides; - /** Name of source application. */ - app_name?: string; + overrides?: GuardOverrides2; + /** Id of source application. */ app_id?: string; /** User/Service account id. */ @@ -825,8 +966,8 @@ export namespace AIGuard { source_location?: string; /** For gateway-like integrations with multi-tenant support. */ tenant_id?: string; - /** (AIDR) sensor mode. */ - sensor_mode?: "input" | "output"; + /** (AIDR) Event Type. */ + event_type?: "input" | "output"; /** (AIDR) sensor instance id. */ sensor_instance_id?: string; /** (AIDR) Logging schema. */ @@ -855,6 +996,46 @@ export namespace AIGuard { count_tokens?: boolean; }; + export type MultimodalGuardResult = { + /** Updated structured prompt. */ + output?: { + [key: string]: unknown; + }; + /** Whether or not the prompt triggered a block detection. */ + blocked?: boolean; + /** Whether or not the original input was transformed. */ + transformed?: boolean; + /** The Recipe that was used. */ + recipe?: string; + /** Result of the recipe analyzing and input prompt. */ + detectors: { + malicious_prompt?: Detector; + confidential_and_pii_entity?: Detector; + malicious_entity?: Detector; + custom_entity?: Detector; + secret_and_key_entity?: Detector; + competitors?: Detector; + // Prompt Hardening does not have `detected`. + prompt_hardening?: { + /** Details about the detected languages. */ + data?: HardeningResult; + }; + language?: Detector; + topic?: Detector; + code?: Detector; + }; + access_rules?: { [key: string]: unknown }; + /** + * If an FPE redaction method returned results, this will be the context + * passed to unredact. + */ + fpe_context?: string; + /** Number of tokens counted in the input */ + input_token_count?: number; + /** Number of tokens counted in the output */ + output_token_count?: number; + }; + export type AuditDataActivityConfig = { enabled: boolean; audit_service_config_id: string; diff --git a/packages/pangea-node-sdk/tests/integration2/ai_guard.test.ts b/packages/pangea-node-sdk/tests/integration2/ai_guard.test.ts index 8a859cdd9..9b3694a37 100644 --- a/packages/pangea-node-sdk/tests/integration2/ai_guard.test.ts +++ b/packages/pangea-node-sdk/tests/integration2/ai_guard.test.ts @@ -56,7 +56,7 @@ describe("AI Guard", () => { app_id: "app_id", llm_provider: "llm_provider", model: "model", - sensor_mode: "input", + event_type: "input", extra_info: { tool_name: "tool_name", }, diff --git a/packages/pangea-node-sdk/tests/testdata/ai-guard.openapi.json b/packages/pangea-node-sdk/tests/testdata/ai-guard.openapi.json index dd22d4ba0..0f9103fe8 100644 --- a/packages/pangea-node-sdk/tests/testdata/ai-guard.openapi.json +++ b/packages/pangea-node-sdk/tests/testdata/ai-guard.openapi.json @@ -707,7 +707,7 @@ "type": "object", "description": "Result of the recipe analyzing and input prompt.", "properties": { - "prompt_injection": { + "malicious_prompt": { "type": "object", "properties": { "detected": { @@ -721,49 +721,7 @@ } } }, - "gibberish": { - "type": "object", - "properties": { - "detected": { - "type": "boolean", - "description": "Whether or not the Gibberish was detected." - }, - "data": { - "type": "object", - "description": "Details about the analyzers.", - "$ref": "#/components/schemas/classification-result" - } - } - }, - "sentiment": { - "type": "object", - "properties": { - "detected": { - "type": "boolean", - "description": "Whether or not the Negative Sentiment was detected." - }, - "data": { - "type": "object", - "description": "Details about the analyzers.", - "$ref": "#/components/schemas/classification-result" - } - } - }, - "selfharm": { - "type": "object", - "properties": { - "detected": { - "type": "boolean", - "description": "Whether or not the Self-harm was detected." - }, - "data": { - "type": "object", - "description": "Details about the analyzers.", - "$ref": "#/components/schemas/classification-result" - } - } - }, - "pii_entity": { + "confidential_and_pii_entity": { "type": "object", "properties": { "detected": { @@ -805,7 +763,7 @@ } } }, - "secrets_detection": { + "secret_and_key_entity": { "type": "object", "properties": { "detected": { @@ -833,21 +791,7 @@ } } }, - "profanity_and_toxicity": { - "type": "object", - "properties": { - "detected": { - "type": "boolean", - "description": "Whether or not the Profanity and Toxic were detected." - }, - "data": { - "type": "object", - "description": "Details about the detected entities.", - "$ref": "#/components/schemas/classification-result" - } - } - }, - "hardening": { + "prompt_hardening": { "type": "object", "properties": { "data": { @@ -857,7 +801,7 @@ } } }, - "language_detection": { + "language": { "type": "object", "properties": { "detected": { @@ -885,7 +829,7 @@ } } }, - "code_detection": { + "code": { "type": "object", "properties": { "detected": { @@ -1376,14 +1320,13 @@ "examples": [ { "messages": [ + { + "role": "system", + "content": "You are a helpful assistant. Here are the tools: Tool1(calc), Tool2(site), Tool3(reverse)" + }, { "role": "user", - "content": [ - { - "type": "image_url", - "image_url": "https://pangea.cloud/home/home-callout-technologies.png" - } - ] + "content": "What is the sum of resopnse time abc.com and cde.com?" } ] } @@ -1400,11 +1343,7 @@ "default": false }, "overrides": { - "$ref": "#/components/schemas/guard-overrides" - }, - "app_name": { - "type": "string", - "description": "Name of source application." + "$ref": "#/components/schemas/guard-overrides-2" }, "app_id": { "type": "string", @@ -1446,9 +1385,9 @@ "type": "string", "description": "For gateway-like integrations with multi-tenant support." }, - "sensor_mode": { + "event_type": { "type": "string", - "description": "(AIDR) sensor mode.", + "description": "(AIDR) Event Type.", "enum": ["input", "output"], "default": "input" }, @@ -1813,6 +1752,261 @@ }, "additionalProperties": false }, + "guard-overrides-2": { + "type": "object", + "description": "Overrides flags. Note: This parameter has no effect when the request is made by AIDR", + "properties": { + "ignore_recipe": { + "type": "boolean", + "description": "Bypass existing Recipe content and create an on-the-fly Recipe.", + "default": false + }, + "code": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "action": { + "$ref": "#/components/schemas/code-detection-action" + }, + "threshold": { + "$ref": "#/components/schemas/classify-threshold" + } + }, + "additionalProperties": false + }, + "language": { + "$ref": "#/components/schemas/language-detection-items" + }, + "topic": { + "$ref": "#/components/schemas/topic-detection-items" + }, + "malicious_prompt": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "action": { + "$ref": "#/components/schemas/prompt-injection-action" + } + }, + "additionalProperties": false + }, + "malicious_entity": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "ip_address": { + "$ref": "#/components/schemas/malicious-entity-action" + }, + "url": { + "$ref": "#/components/schemas/malicious-entity-action" + }, + "domain": { + "$ref": "#/components/schemas/malicious-entity-action" + } + }, + "additionalProperties": false + }, + "competitors": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "action": { + "$ref": "#/components/schemas/competitors-action" + } + }, + "additionalProperties": false + }, + "confidential_and_pii_entity": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "email_address": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "nrp": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "location": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "person": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "phone_number": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "date_time": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "ip_address": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "url": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "money": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "credit_card": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "crypto": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "iban_code": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "us_bank_number": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "nif": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "fin/nric": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "au_abn": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "au_acn": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "au_tfn": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "medical_license": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "uk_nhs": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "au_medicare": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "us_drivers_license": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "us_itin": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "us_passport": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "us_ssn": { + "$ref": "#/components/schemas/pii-entity-action" + } + }, + "additionalProperties": false + }, + "secret_and_key_entity": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "slack_token": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "rsa_private_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "ssh_dsa_private_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "ssh_ec_private_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "pgp_private_key_block": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "amazon_aws_access_key_id": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "amazon_aws_secret_access_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "amazon_mws_auth_token": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "facebook_access_token": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "github_access_token": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "jwt_token": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "google_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "google_cloud_platform_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "google_drive_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "google_cloud_platform_service_account": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "google_gmail_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "youtube_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "mailchimp_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "mailgun_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "basic_auth": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "picatic_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "slack_webhook": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "stripe_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "stripe_restricted_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "square_access_token": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "square_oauth_secret": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "twilio_api_key": { + "$ref": "#/components/schemas/pii-entity-action" + }, + "pangea_token": { + "$ref": "#/components/schemas/pii-entity-action" + } + }, + "additionalProperties": false + }, + "image": { + "$ref": "#/components/schemas/image-detection-items" + } + }, + "additionalProperties": false + }, "language-result": { "type": "object", "properties": { @@ -1887,6 +2081,12 @@ "minimum": 0, "maximum": 1 }, + "image-threshold": { + "type": "number", + "multipleOf": 0.01, + "minimum": 0, + "maximum": 1 + }, "language-threshold": { "type": "number", "multipleOf": 0.01, @@ -1962,6 +2162,25 @@ }, "default": [] }, + "image-detection-items": { + "type": "object", + "properties": { + "disabled": { + "type": "boolean" + }, + "action": { + "type": "string", + "enum": ["", "report", "block"], + "default": "" + }, + "topics": { + "$ref": "#/components/schemas/topics" + }, + "threshold": { + "$ref": "#/components/schemas/image-threshold" + } + } + }, "code-detection-action": { "type": "string", "enum": ["report", "block"]