メインコンテンツまでスキップ

Google Drive

Google Drive の document と folder を、Squid AI agent の context として使用します。​

Google Drive connector を使用すると、user は Google Drive の file や folder を選択し、Squid AI agent の context として upload できます。AI agent は選択された file を information source として使用し、client prompt に response できます。custom AI agent の作成について詳しくは、AI agent documentationを参照してください。

Squid は Google Drive 固有の sharing setting を尊重できるため、agent は chat 中の person が Drive で開ける file のみを retrieve します。Respecting source permissionsを参照してください。

Google Drive connector を使用するには、Google Cloud project と Google Cloud 用の configuration step が必要です。必要な step は、この documentation 内で関連する Google documentation への link とともに説明されています。

Google Drive API を有効にする​

この Google Drive connector を使用開始するには、まず Google Cloud project で必要な Google API を有効にします。

  1. Google Cloud Console で、application の project を選択するか、新しい project を作成します。

  2. Google Cloud documentation の Set up your environment step に従い、Google Drive API を有効にして必要な credential を作成します。API key、client ID、client secret が必要です。

  3. Google Cloud Console で Google Picker API を有効にします。

Connector を追加する​

  1. Squid Console で、Connectors tab に移動します。

  2. Available Connectors をクリックします。

  3. Google Drive connector を見つけ、Add Connector を選択します。

  4. 次の configuration detail を指定します。

Connector ID: code 内で connector を一意に識別する string。

Client ID: Google Cloud Console の OAuth2 client ID。

Client Secret: Google Cloud Console の OAuth2 client secret。

Redirect URI: OAuth2 redirect URI(Google Cloud で構成したものと一致する必要があります)。

Connector の使用​

Google Drive connector を作成したら、studio または SDK で使用できます。

注記

Squid SDK の personal storage method には Squid API key への access が必要です。API key は admin access を可能にするため、personal storage は Squid backend のような secure admin environment でのみ使用してください。

No-code Studio​

Squid Agent Studio で no-code solution を作成します。

  1. Squid Console の Studio tab に移動します。

  2. Create AI Agent をクリックします。

  3. "gdrive-agent" や "This agent helps the user search for content inside Google Drive" などの Agent ID と description を指定します。

  4. Add Abilities をクリックし、Storage section まで scroll して、先ほど作成した Google Drive connector を選択します。

  5. 「user が Google Drive content について尋ねた場合にこれを call する」など、agent がこの connection を使用する方法について instruction を指定します。

  6. Test をクリックし、agent に「Google Drive から project proposal を検索して list 化してください」と尋ねてみます。

Code の基本 Building Block​

Squid application で Google Drive connector を使用するには、@squidcloud/google-drive-client npm package を install します。

npm install @squidcloud/google-drive-client

Client Setup​

import { GoogleDriveClient, GOOGLE_DRIVE_SCOPES } from '@squidcloud/google-drive-client';
import { Squid } from '@squidcloud/client';

const squid = new Squid({
appId: 'your-app-id',
region: 'us-east-1.aws',
environmentId: 'dev',
});

const driveClient = new GoogleDriveClient(
squid,
'google_drive' // your connector ID
);

Authentication​

Google Drive client は OAuth2 token management に Squid の External Authentication API を使用します。詳細については documentation を参照してください。

authorization code の取得後:

const response = await driveClient.saveAuthCode(authCode, userId);

Google 固有の OAuth2 requirement については、Google OAuth2 documentationを参照してください。

OAuth2 Scope​

Google Drive connector には、以下の OAuth2 scope が必要です。

const GOOGLE_DRIVE_SCOPES = ['openid', 'email', 'https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/drive.metadata.readonly'];

利便性のため、GOOGLE_DRIVE_SCOPES constant は @squidcloud/google-drive-client package から export されています。

Google Picker API の使用​

user が context として保存する file を選択できるようにするには、Google Picker API を使用します。Google documentation の step に従って Google Picker を load・display し、accessToken の value として Squid Drive client が生成した access token を渡します。

const showPicker = () => {
// TODO(developer): Replace with your API key
const picker = new google.picker.PickerBuilder()
.addView(google.picker.ViewId.DOCS)
.setOAuthToken(accessToken) // From Squid
.setDeveloperKey('API_KEY')
.setCallback(pickerCallback)
.setAppId(APP_ID)
.build();
picker.setVisible(true);
};

implementation に関する最新 information については、Google Picker documentationを参照してください。

Document と Folder の Indexing​

AI processing 用に document を index 化するには、indexDocumentOrFolder method を使用します。individual file または folder 全体(内部の全 file を recursive に index 化)を index 化できます。

// Index a single document
const errors = await driveClient.indexDocumentOrFolder(documentId, userId, {
category: 'documentation',
description: 'Product documentation',
});

// Index an entire folder recursively
const folderErrors = await driveClient.indexDocumentOrFolder(folderId, userId, {
category: 'project-files',
});

if (folderErrors.length > 0) {
console.error('Some files failed to index:', folderErrors);
}

Index 済み Document の List 化​

// List all indexed documents
const allDocuments = await driveClient.listIndexedDocuments(userId);

// List only files
const files = await driveClient.listIndexedDocuments(userId, 'file');

// List only folders
const folders = await driveClient.listIndexedDocuments(userId, 'folder');

Document Content の抽出​

// Extract text content from a document
const extractedData = await driveClient.extractDataFromDocument(documentId, userId);

console.log('Pages:', extractedData.pages.length);
extractedData.pages.forEach((page, i) => {
console.log(`Page ${i + 1}: ${page.content.substring(0, 200)}...`);
});

Index から Document を削除する​

// Unindex a document or folder
const errors = await driveClient.unindexDocumentOrFolder(documentId, userId);

if (errors.length === 0) {
console.log('Successfully unindexed');
}

Automatic Document Synchronization​

index 済み document は background reindexing process により Google Drive と自動的に sync されます。これにより AI agent は常に最新 content に access できます。

automatic sync process:

  • File change を検出する: Google Drive 内で変更された index 済み document を update する
  • Delete を処理する: Drive から document が delete されると、自動的に index から remove する
  • Folder update を処理する: 新規 file、変更、delete を folder 内で monitor する
  • Metadata を保持する: reindexing 中も custom metadata を維持する
  • Sharing change を追跡する: source permission の尊重が有効な場合、document permission を最新の状態に維持する

必要な action はありません。document は一度 index 化されると自動的に最新状態に保たれます。

AI Agent での使用​

Google Drive connector は、AI agent が index 済み document を操作できるようにする AI function を提供します。user identifier は agent に構成するか、runtime に渡せます。

Agent の構成​

// Configure the agent with Google Drive integration and user identifier
const agent = squid.ai().agent('document_agent');
await agent.setAgentOptionInPath('connectedIntegrations', [
{
integrationId: 'google_drive',
integrationType: 'google_drive',
options: {
identifier: userId, // unique identifier per user
},
},
]);
注記

identifier を構成するための no-code Studio support は近日提供予定です。現在は、identifier を持つ AI Agent を構成するために SDK を使用する必要があります。

Index 済み Document を使用した Query​

document を index 化すると、AI agent は index 済み content を使用して question に answer できます。

// The agent will search through indexed documents to answer
const response = await agent.ask('In Google Drive, what are the key points in the product documentation?');

AI Function の使用​

Google Drive connector は、index 済み document を list 化する AI function を提供します。

// List documents using AI function
const response = await agent.ask('List all my indexed Google Drive documents', {
agentContext: { identifier: userId }, // Override default identifier if needed
});

Dynamic User Context​

request ごとに default identifier を override できます。

// Use a different user's documents for this query
const response = await agent.ask('Search for project proposals in my Google Drive', {
agentContext: { identifier: differentUserId },
});

これで AI agent を通じて Google Drive の content を検索できます!