opencode-gemini-tools 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex Grad <alex@grad.dev> (https://grad.dev)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# opencode-gemini-tools
|
|
2
|
+
|
|
3
|
+
A plugin for the OpenCode that enables Google Gemini's built-in tools: Google Search, Google Maps, URL Context, and Code Execution.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the plugin to your OpenCode configuration file (e.g. `~/.config/opencode/opencode.json` or `.opencode/opencode.json` in your project):
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"plugin": ["opencode-gemini-tools"]
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
OpenCode will automatically download and install the plugin from npm the next time it starts.
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function GeminiToolsPlugin(): {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const originalFetch = globalThis.fetch;
|
|
2
|
+
const customFetch = async (input, init) => {
|
|
3
|
+
const fallback = () => originalFetch.call(globalThis, input, init);
|
|
4
|
+
if (!isGeminiEndpoint(input)) {
|
|
5
|
+
return fallback();
|
|
6
|
+
}
|
|
7
|
+
if (!init || !init.body || typeof init.body !== "string") {
|
|
8
|
+
return fallback();
|
|
9
|
+
}
|
|
10
|
+
const body = JSON.parse(init.body);
|
|
11
|
+
if (!isRecord(body)) {
|
|
12
|
+
return fallback();
|
|
13
|
+
}
|
|
14
|
+
body.tools ??= [];
|
|
15
|
+
if (!Array.isArray(body.tools)) {
|
|
16
|
+
return fallback();
|
|
17
|
+
}
|
|
18
|
+
body.tools = [
|
|
19
|
+
{ googleSearch: {} },
|
|
20
|
+
{ googleMaps: {} },
|
|
21
|
+
{ urlContext: {} },
|
|
22
|
+
{ codeExecution: {} },
|
|
23
|
+
...body.tools,
|
|
24
|
+
];
|
|
25
|
+
init.body = JSON.stringify(body);
|
|
26
|
+
return originalFetch(input, init);
|
|
27
|
+
};
|
|
28
|
+
export function GeminiToolsPlugin() {
|
|
29
|
+
globalThis.fetch = Object.assign(customFetch, originalFetch);
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
function isGeminiEndpoint(value) {
|
|
33
|
+
try {
|
|
34
|
+
if (typeof value !== "string") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const url = new URL(value);
|
|
38
|
+
const isGoogleHost = url.hostname === "generativelanguage.googleapis.com" ||
|
|
39
|
+
url.hostname.endsWith("aiplatform.googleapis.com");
|
|
40
|
+
const isGenerateContent = url.pathname.includes("streamGenerateContent");
|
|
41
|
+
return isGoogleHost && isGenerateContent;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isRecord(value) {
|
|
48
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC;AAKvC,MAAM,WAAW,GAAG,KAAK,EAAE,KAAY,EAAE,IAAU,EAAE,EAAE;IACtD,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAEnE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,QAAQ,EAAE,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1D,OAAO,QAAQ,EAAE,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAY,CAAC;IAE9C,IAAI,CAAC,QAAQ,CAAC,IA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IACd,CAAC;AACF,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC;AACpE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-gemini-tools",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Alex Grad",
|
|
6
|
+
"email": "alex@grad.dev",
|
|
7
|
+
"url": "https://grad.dev"
|
|
8
|
+
},
|
|
9
|
+
"description": "A plugin for the OpenCode that enables Google Gemini's built-in tools: Google Search, Google Maps, URL Context, and Code Execution",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"opencode",
|
|
12
|
+
"gemini",
|
|
13
|
+
"google",
|
|
14
|
+
"google-search",
|
|
15
|
+
"google-maps",
|
|
16
|
+
"url-context",
|
|
17
|
+
"code-execution"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/graddotdev/opencode-gemini-tools.git"
|
|
24
|
+
},
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc"
|
|
38
|
+
},
|
|
39
|
+
"prepublishOnly": "bun run build",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/bun": "latest",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
43
|
+
}
|
|
44
|
+
}
|