Skip to content

Commit a650d04

Browse files
committed
Modified
1 parent b2410c8 commit a650d04

File tree

5 files changed

+108
-4
lines changed

5 files changed

+108
-4
lines changed

A2AApp.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* This is used for building both an Agent2Agent (A2A) server and an A2A client with Google Apps Script.
44
*
55
* Author: Kanshi Tanaike
6-
* 20250527 13:34
7-
* version 2.0.0
6+
* 20250529 10:04
7+
* version 2.0.1
88
* @class
99
*/
1010
class A2AApp {
@@ -91,6 +91,34 @@ class A2AApp {
9191

9292
/** @private */
9393
this.headers = { authorization: "Bearer " + ScriptApp.getOAuthToken() };
94+
95+
this.lock = this.lock || LockService.getScriptLock();
96+
97+
this.properties = this.properties || PropertiesService.getScriptProperties();
98+
}
99+
100+
/**
101+
* ### Description
102+
* Set services depend on each script. For example, those are LockService and PropertiesService.
103+
* For example, if you don't set these properties, you cannot use this as a library.
104+
* If you want to use A2AApp as a library, please set the services.
105+
*
106+
* In the current stage, only LockService is used and PropertiesService is not used in A2AApp. PropertiesService is for the future update.
107+
*
108+
* @param {Object} services Array including the services you want to use.
109+
* @params {LockService.Lock} services.lock One of LockService.getDocumentLock(), LockService.getScriptLock(), or LockService.getUserLock(). Default is LockService.getScriptLock().
110+
* @params {PropertiesService.Properties} services.properties One of PropertiesService.getDocumentProperties(), PropertiesService.getScriptProperties(), or PropertiesService.getUserProperties(). Default is PropertiesService.getScriptProperties().
111+
* @return {A2AApp}
112+
*/
113+
setServices(services) {
114+
const { lock, properties } = services;
115+
if (lock && lock.toString() == "Lock") {
116+
this.lock = lock;
117+
}
118+
if (properties && lock.toString() == "Properties") {
119+
this.properties = properties;
120+
}
121+
return this;
94122
}
95123

96124
/**
@@ -108,7 +136,7 @@ class A2AApp {
108136
console.log("Server side");
109137
this.errorProcess_(object);
110138
let id = "No ID";
111-
const lock = LockService.getScriptLock();
139+
const lock = this.lock;
112140
if (lock.tryLock(350000)) {
113141
try {
114142
let obj = {};
@@ -172,7 +200,7 @@ class A2AApp {
172200
*/
173201
client(object = {}) {
174202
console.log("Client side");
175-
const lock = LockService.getScriptLock();
203+
const lock = this.lock;
176204
if (lock.tryLock(350000)) {
177205
try {
178206
const { agentCardUrls = [], agentCards = [] } = object;

Use_A2AApp_as_library/A2AApp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// https://github.com/tanaikech/A2AApp/blob/master/A2AApp.js
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Please use the latest version.
2+
// https://github.com/tanaikech/GeminiWithFiles/blob/master/classGeminiWithFiles.js
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// https://github.com/tanaikech/A2AApp/blob/master/index.html

Use_A2AApp_as_library/main.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* GitHub https://github.com/tanaikech/A2AApp<br>
3+
* Library name
4+
* @type {string}
5+
* @const {string}
6+
* @readonly
7+
*/
8+
var appName = "A2AApp";
9+
10+
/**
11+
* Main Class
12+
*
13+
* @param {Object} object Object using this script.
14+
* @param {Boolean} object.log Default is false. When this is true, the log between A2A is stored to Google Sheets.
15+
* @param {String} object.spreadsheetId Spreadsheet ID. Log is storead to "Log" sheet of this spreadsheet.
16+
* @returns {A2AApp}
17+
*/
18+
function a2aApp(object) {
19+
this.a2aApp = new A2AApp(object);
20+
return this.a2aApp;
21+
}
22+
23+
/**
24+
* ### Description
25+
* Set services depend on each script. For example, those are LockService and PropertiesService.
26+
* For example, if you don't set these properties, you cannot use this as a library.
27+
* If you want to use A2AApp as a library, please set the services.
28+
*
29+
* In the current stage, only LockService is used and PropertiesService is not used in A2AApp. PropertiesService is for the future update.
30+
*
31+
* @param {Object} services Array including the services you want to use.
32+
* @params {LockService.Lock} services.lock One of LockService.getDocumentLock(), LockService.getScriptLock(), or LockService.getUserLock(). Default is LockService.getScriptLock().
33+
* @params {PropertiesService.Properties} services.properties One of PropertiesService.getDocumentProperties(), PropertiesService.getScriptProperties(), or PropertiesService.getUserProperties(). Default is PropertiesService.getScriptProperties().
34+
* @return {A2AApp}
35+
*/
36+
function setServices(services) {
37+
const { lock, properties } = services;
38+
if (lock) {
39+
/** @private */
40+
this.a2aApp.lock = lock;
41+
}
42+
if (properties) {
43+
/** @private */
44+
this.a2aApp.properties = properties;
45+
}
46+
return this.a2aApp;
47+
}
48+
49+
/**
50+
* ### Description
51+
* Method for the A2A server.
52+
*
53+
* @param {Object} object Object using this script.
54+
* @param {Object} object.eventObject Event object from doPost and doGet functions.
55+
* @param {Object} object.apiKey API key for using Gemini API.
56+
* @param {Object} object.agentCard Object for registering your agent card.
57+
* @param {Object} object.functions Functions.
58+
* @return {ContentService.TextOutput}
59+
*/
60+
function server(object) {
61+
return this.a2aApp.server(object);
62+
}
63+
64+
/**
65+
* ### Description
66+
* Return HtmlService.HtmlOutput for UI of A2A client.
67+
*
68+
* @return {HtmlService.HtmlOutput}
69+
*/
70+
function getClientIndex() {
71+
return HtmlService.createHtmlOutputFromFile("index_client").setTitle("A2A client from A2AApp");
72+
}

0 commit comments

Comments
 (0)