@agentproto/adapter-gemini 0.2.0
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/GEMINI.md +102 -0
- package/LICENSE +202 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.mjs +195 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/GEMINI.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gemini
|
|
3
|
+
id: gemini
|
|
4
|
+
description: Google's Gemini CLI in ACP mode (`gemini --experimental-acp`) — an open-source terminal agent driving Gemini models over the Agent Client Protocol via stdio JSON-RPC. Native adapter (over the generic `gemini-cli` catalog entry) so subscription billing-auth — "use my existing Gemini login" — is a verified, money-safe opt-in.
|
|
5
|
+
version: 0.1.0
|
|
6
|
+
bin: gemini
|
|
7
|
+
bin_args: ["--experimental-acp"]
|
|
8
|
+
install:
|
|
9
|
+
- method: npm
|
|
10
|
+
package: "@google/gemini-cli"
|
|
11
|
+
global: true
|
|
12
|
+
version_check:
|
|
13
|
+
cmd: gemini --version
|
|
14
|
+
parse: "(\\d+\\.\\d+\\.\\d+)"
|
|
15
|
+
range: ">=0.1.0"
|
|
16
|
+
timeout_ms: 15000
|
|
17
|
+
auth:
|
|
18
|
+
ref: ./SECRETS.md
|
|
19
|
+
state:
|
|
20
|
+
env: [GEMINI_API_KEY, GOOGLE_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY]
|
|
21
|
+
provider: google
|
|
22
|
+
authSubscription:
|
|
23
|
+
external: true
|
|
24
|
+
conflictEnv: [GEMINI_API_KEY, GOOGLE_API_KEY]
|
|
25
|
+
sandbox: ./SANDBOX.md
|
|
26
|
+
protocol: acp
|
|
27
|
+
acp: ./gemini-acp.ACP.md
|
|
28
|
+
session:
|
|
29
|
+
mode: persistent
|
|
30
|
+
idle_timeout_ms: 1800000
|
|
31
|
+
context_carryover: true
|
|
32
|
+
models:
|
|
33
|
+
default: gemini-2.5-pro
|
|
34
|
+
allowed:
|
|
35
|
+
- gemini-2.5-pro
|
|
36
|
+
- gemini-2.5-flash
|
|
37
|
+
- gemini-2.5-flash-lite
|
|
38
|
+
- gemini-3.5-flash
|
|
39
|
+
- gemini-3.1-pro-preview
|
|
40
|
+
- gemini-3-flash-preview
|
|
41
|
+
- gemini-3.1-flash-lite
|
|
42
|
+
env:
|
|
43
|
+
google: GOOGLE_GENERATIVE_AI_API_KEY
|
|
44
|
+
gemini: GEMINI_API_KEY
|
|
45
|
+
apply: arg
|
|
46
|
+
bin_args_template: ["-m", "{model}"]
|
|
47
|
+
capabilities:
|
|
48
|
+
streaming: true
|
|
49
|
+
tool_calls: true
|
|
50
|
+
sub_agents: false
|
|
51
|
+
file_io: true
|
|
52
|
+
multimodal: true
|
|
53
|
+
resumable: true
|
|
54
|
+
bidirectional: true
|
|
55
|
+
tags: ["gemini", "google", "acp", "agent-runtime", "coding"]
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
# Gemini adapter
|
|
59
|
+
|
|
60
|
+
`@agentproto/adapter-gemini` wraps Google's open-source **Gemini CLI** as an
|
|
61
|
+
AIP-45 agent CLI by spawning it in ACP mode (`gemini --experimental-acp`) and
|
|
62
|
+
driving it over stdio JSON-RPC.
|
|
63
|
+
|
|
64
|
+
## Why a native adapter (vs the generic `gemini-cli` entry)
|
|
65
|
+
|
|
66
|
+
The generic ACP catalog already knows how to spawn `gemini --experimental-acp`,
|
|
67
|
+
but a catalog entry carries no `provider` and no `authSubscription`, so it's
|
|
68
|
+
pure-ambient — the daemon can't verify or guarantee which billing rail a spawn
|
|
69
|
+
uses. This native adapter adds the billing-auth surface: a catalog `provider`
|
|
70
|
+
(`google`) and a file-based (external) subscription so **"use my existing Gemini
|
|
71
|
+
login"** is an explicit, verified, money-safe opt-in.
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install -g @google/gemini-cli
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`--experimental-acp` starts ACP mode. Current Gemini CLI builds prefer the
|
|
80
|
+
shorter `--acp`; the experimental spelling is kept as a working alias and
|
|
81
|
+
matches the rest of the ACP catalog.
|
|
82
|
+
|
|
83
|
+
## Auth
|
|
84
|
+
|
|
85
|
+
Gemini authenticates one of three ways:
|
|
86
|
+
|
|
87
|
+
| Mechanism | How |
|
|
88
|
+
|------------------|-----------------------------------------------------------|
|
|
89
|
+
| Existing login | The CLI's own OAuth login (`~/.gemini/oauth_creds.json`) |
|
|
90
|
+
| Gemini API key | `GEMINI_API_KEY=…` |
|
|
91
|
+
| Google API key | `GOOGLE_API_KEY=…` / `GOOGLE_GENERATIVE_AI_API_KEY=…` |
|
|
92
|
+
|
|
93
|
+
### "Use my existing Gemini login" (file-based subscription)
|
|
94
|
+
|
|
95
|
+
`authSubscription: { external: true }`. The Gemini CLI reads its own
|
|
96
|
+
`~/.gemini/oauth_creds.json`, so the daemon injects **nothing** — it verifies
|
|
97
|
+
the login is present (fail-loud) and **scrubs** every api-key var
|
|
98
|
+
(`GEMINI_API_KEY`, `GOOGLE_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`) so a stray
|
|
99
|
+
key can't silently flip the spawn to per-token API billing. An env API key
|
|
100
|
+
*overrides* the OAuth login in Google's precedence, which is exactly why all
|
|
101
|
+
three are scrubbed. Money-safe by construction: no OAuth bearer is ever written
|
|
102
|
+
into an api-key env var, because no bearer is injected at all.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AgentCliHandle, AgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
2
|
+
export { AgentCliHandle, AgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
3
|
+
import { CapabilityStrategy } from '@agentproto/provider-kit';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @agentproto/adapter-gemini — AIP-45 adapter for Google's Gemini CLI in ACP
|
|
7
|
+
* mode (`gemini --experimental-acp`).
|
|
8
|
+
*
|
|
9
|
+
* The Gemini CLI is an open-source terminal agent that speaks the Agent Client
|
|
10
|
+
* Protocol when launched with `--experimental-acp` (aliased to `--acp` on
|
|
11
|
+
* current builds; the experimental spelling still works and matches the wider
|
|
12
|
+
* ACP catalog). Install it with `npm i -g @google/gemini-cli`, then:
|
|
13
|
+
*
|
|
14
|
+
* import { gemini, geminiRuntime } from "@agentproto/adapter-gemini"
|
|
15
|
+
* const session = await geminiRuntime().start({
|
|
16
|
+
* env: { GEMINI_API_KEY: "..." },
|
|
17
|
+
* })
|
|
18
|
+
* for await (const evt of session.send({ role: "user", content: "..." })) {
|
|
19
|
+
* console.log(evt)
|
|
20
|
+
* }
|
|
21
|
+
* await session.close()
|
|
22
|
+
*
|
|
23
|
+
* The headline feature over the generic `gemini-cli` ACP catalog entry is
|
|
24
|
+
* billing-auth: a native `provider` + a FILE-BASED (external) subscription so
|
|
25
|
+
* "use my existing Gemini login" is a verified, observable, money-safe opt-in.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
declare const gemini: AgentCliHandle;
|
|
29
|
+
declare function geminiRuntime(): AgentCliRuntime;
|
|
30
|
+
/**
|
|
31
|
+
* Best-effort capability discovery for gemini: parses the Gemini CLI's own
|
|
32
|
+
* `~/.gemini/settings.json` (`security.auth.selectedType`) plus the
|
|
33
|
+
* presence of `~/.gemini/oauth_creds.json` to report whether the "use my
|
|
34
|
+
* existing Gemini login" file-based subscription is actually live on this
|
|
35
|
+
* host, alongside the api-key fallback path. Never throws — a malformed
|
|
36
|
+
* settings.json just leaves `selectedType` undetermined rather than
|
|
37
|
+
* blanking the whole result.
|
|
38
|
+
*/
|
|
39
|
+
declare const geminiCapabilities: CapabilityStrategy;
|
|
40
|
+
|
|
41
|
+
export { gemini, geminiCapabilities, geminiRuntime };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { defineAgentCli, createAgentCliRuntime } from '@agentproto/driver-agent-cli';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @agentproto/adapter-gemini v0.1.0-alpha
|
|
6
|
+
* AIP-45 adapter for Google's Gemini CLI in ACP mode (`gemini --experimental-acp`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var gemini = defineAgentCli({
|
|
10
|
+
name: "gemini",
|
|
11
|
+
id: "gemini",
|
|
12
|
+
description: 'Google\'s Gemini CLI in ACP mode (`gemini --experimental-acp`) \u2014 an open-source terminal agent driving Gemini models over the Agent Client Protocol via stdio JSON-RPC. Native adapter (over the generic `gemini-cli` catalog entry) so subscription billing-auth \u2014 "use my existing Gemini login" \u2014 is a verified, money-safe opt-in.',
|
|
13
|
+
version: "0.1.0",
|
|
14
|
+
bin: "gemini",
|
|
15
|
+
// `--experimental-acp` starts ACP mode. Current Gemini CLI (0.45.x) prefers
|
|
16
|
+
// the shorter `--acp`, but keeps `--experimental-acp` as a working alias, and
|
|
17
|
+
// it's the spelling the rest of the ACP catalog uses — so keep it for parity.
|
|
18
|
+
bin_args: ["--experimental-acp"],
|
|
19
|
+
install: [
|
|
20
|
+
{
|
|
21
|
+
method: "npm",
|
|
22
|
+
package: "@google/gemini-cli",
|
|
23
|
+
global: true
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
version_check: {
|
|
27
|
+
cmd: "gemini --version",
|
|
28
|
+
parse: "(\\d+\\.\\d+\\.\\d+)",
|
|
29
|
+
range: ">=0.1.0",
|
|
30
|
+
timeout_ms: 15e3
|
|
31
|
+
},
|
|
32
|
+
auth: {
|
|
33
|
+
ref: "./SECRETS.md",
|
|
34
|
+
// Every api-key rail the Gemini CLI honors — all three are scrubbed under a
|
|
35
|
+
// file-based subscription so a stray key can't flip billing (see below).
|
|
36
|
+
state: {
|
|
37
|
+
env: ["GEMINI_API_KEY", "GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
// Billing-auth (opt-in — no authEnforce, so unconfigured spawns stay
|
|
41
|
+
// ambient). Single-provider adapter: api-key mode SETS providerEnvVar
|
|
42
|
+
// ("google") = GOOGLE_GENERATIVE_AI_API_KEY, derived from the catalog.
|
|
43
|
+
provider: "google",
|
|
44
|
+
// "Use my existing Gemini login" — a FILE-BASED (external) subscription. The
|
|
45
|
+
// Gemini CLI's OAuth login lives in `~/.gemini/oauth_creds.json`
|
|
46
|
+
// (`access_token`), which the CLI reads ITSELF; it has no env-bearer channel
|
|
47
|
+
// like claude-code's CLAUDE_CODE_OAUTH_TOKEN. So `external: true`: subscription
|
|
48
|
+
// mode injects NOTHING (no setEnv) — the host verifies the login is present
|
|
49
|
+
// (fail-loud, via the `gemini` provision recipe) and the driver only SCRUBS
|
|
50
|
+
// the api-key vars so a leftover key can't silently flip the spawn to per-token
|
|
51
|
+
// API billing under a "subscription" label.
|
|
52
|
+
//
|
|
53
|
+
// GOOGLE_GENERATIVE_AI_API_KEY is scrubbed automatically (it's the provider's
|
|
54
|
+
// api-key var). GEMINI_API_KEY and GOOGLE_API_KEY are the two SIBLING keys the
|
|
55
|
+
// Gemini CLI also honors — and, critically, an env API key OVERRIDES the OAuth
|
|
56
|
+
// login in Google's auth precedence, so BOTH must be scrubbed for the login to
|
|
57
|
+
// win (they're listed as conflictEnv). Money-safe by construction: no OAuth
|
|
58
|
+
// bearer is ever written into an api-key env var, because no bearer is injected
|
|
59
|
+
// at all. An unconfigured gemini spawn stays ambient — the CLI uses its own
|
|
60
|
+
// oauth_creds.json precedence — so this only ADDS an explicit, verified,
|
|
61
|
+
// billing-guaranteed, observable opt-in on top of that.
|
|
62
|
+
authSubscription: {
|
|
63
|
+
external: true,
|
|
64
|
+
conflictEnv: ["GEMINI_API_KEY", "GOOGLE_API_KEY"]
|
|
65
|
+
},
|
|
66
|
+
sandbox: "./SANDBOX.md",
|
|
67
|
+
protocol: "acp",
|
|
68
|
+
acp: "./gemini-acp.ACP.md",
|
|
69
|
+
session: {
|
|
70
|
+
mode: "persistent",
|
|
71
|
+
idle_timeout_ms: 18e5,
|
|
72
|
+
context_carryover: true
|
|
73
|
+
},
|
|
74
|
+
models: {
|
|
75
|
+
default: "gemini-2.5-pro",
|
|
76
|
+
// Sourced from the model catalog's curated Google (vendor "google") text
|
|
77
|
+
// models — NOT hand-invented ids (see packages/model-catalog/src/llm/
|
|
78
|
+
// catalog.ts). Kept to the stable + current preview lines the CLI serves.
|
|
79
|
+
allowed: [
|
|
80
|
+
"gemini-2.5-pro",
|
|
81
|
+
"gemini-2.5-flash",
|
|
82
|
+
"gemini-2.5-flash-lite",
|
|
83
|
+
"gemini-3.5-flash",
|
|
84
|
+
"gemini-3.1-pro-preview",
|
|
85
|
+
"gemini-3-flash-preview",
|
|
86
|
+
"gemini-3.1-flash-lite"
|
|
87
|
+
],
|
|
88
|
+
env: {
|
|
89
|
+
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
90
|
+
gemini: "GEMINI_API_KEY"
|
|
91
|
+
},
|
|
92
|
+
// The Gemini CLI takes its model as the documented global `-m/--model`
|
|
93
|
+
// flag, composed into argv at spawn time (confirmed present on 0.45.2 via
|
|
94
|
+
// `gemini --help`). It's a global flag, so it applies alongside
|
|
95
|
+
// `--experimental-acp`; worst case a future ACP build ignores it and the
|
|
96
|
+
// session falls back to the CLI's default model — never a mis-bill.
|
|
97
|
+
apply: "arg",
|
|
98
|
+
bin_args_template: ["-m", "{model}"]
|
|
99
|
+
},
|
|
100
|
+
capabilities: {
|
|
101
|
+
streaming: true,
|
|
102
|
+
tool_calls: true,
|
|
103
|
+
sub_agents: false,
|
|
104
|
+
file_io: true,
|
|
105
|
+
// Gemini models are natively multimodal; the CLI forwards ACP image content
|
|
106
|
+
// blocks into the Gemini vision pipeline.
|
|
107
|
+
multimodal: true,
|
|
108
|
+
// The Gemini CLI implements ACP session lifecycle (newSession / loadSession).
|
|
109
|
+
resumable: true,
|
|
110
|
+
bidirectional: true
|
|
111
|
+
},
|
|
112
|
+
options: [
|
|
113
|
+
{
|
|
114
|
+
id: "model",
|
|
115
|
+
type: "enum",
|
|
116
|
+
enum: [
|
|
117
|
+
"gemini-2.5-pro",
|
|
118
|
+
"gemini-2.5-flash",
|
|
119
|
+
"gemini-2.5-flash-lite",
|
|
120
|
+
"gemini-3.5-flash",
|
|
121
|
+
"gemini-3.1-pro-preview",
|
|
122
|
+
"gemini-3-flash-preview",
|
|
123
|
+
"gemini-3.1-flash-lite"
|
|
124
|
+
],
|
|
125
|
+
description: "Override the default model for this operator binding."
|
|
126
|
+
// Real composition happens via `models.apply: "arg"` above; this option
|
|
127
|
+
// exists so `config.options.model` validates.
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
continuation: {
|
|
131
|
+
default: "native-resume",
|
|
132
|
+
supported: ["native-resume", "pinned-session", "transcript", "none"],
|
|
133
|
+
pinned_session: {
|
|
134
|
+
idle_timeout_ms: 18e5,
|
|
135
|
+
key_scope: ["conversation", "operator"]
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
tags: ["gemini", "google", "acp", "agent-runtime", "coding"]
|
|
139
|
+
});
|
|
140
|
+
function geminiRuntime() {
|
|
141
|
+
return createAgentCliRuntime(gemini);
|
|
142
|
+
}
|
|
143
|
+
var geminiCapabilities = async (def, ctx) => {
|
|
144
|
+
const settingsPath = join(ctx.homeDir, ".gemini", "settings.json");
|
|
145
|
+
const oauthPath = join(ctx.homeDir, ".gemini", "oauth_creds.json");
|
|
146
|
+
let selectedType;
|
|
147
|
+
const settingsRaw = await ctx.readFile(settingsPath);
|
|
148
|
+
if (settingsRaw !== null) {
|
|
149
|
+
try {
|
|
150
|
+
const parsed = JSON.parse(settingsRaw);
|
|
151
|
+
if (typeof parsed.security?.auth?.selectedType === "string") {
|
|
152
|
+
selectedType = parsed.security.auth.selectedType;
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
ctx.warn(
|
|
156
|
+
`gemini capability discovery: could not parse ~/.gemini/settings.json: ${err instanceof Error ? err.message : String(err)}`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const oauthLoginPresent = await ctx.readFile(oauthPath) !== null;
|
|
161
|
+
const oauthSelected = selectedType !== void 0 && selectedType.toLowerCase().includes("oauth");
|
|
162
|
+
const apiKeyEnvVar = def.models?.env?.google ?? "GOOGLE_GENERATIVE_AI_API_KEY";
|
|
163
|
+
const apiKeyPresent = !!ctx.env[apiKeyEnvVar];
|
|
164
|
+
const oauthPresent = oauthSelected && oauthLoginPresent;
|
|
165
|
+
const source = oauthPresent ? { kind: "oauth-file", path: "~/.gemini/oauth_creds.json" } : { kind: "env", var: apiKeyEnvVar };
|
|
166
|
+
const authStores = [
|
|
167
|
+
{ kind: "oauth-file", path: "~/.gemini/oauth_creds.json", format: "json", providerKeyed: false },
|
|
168
|
+
{ kind: "env", providerKeyed: false }
|
|
169
|
+
];
|
|
170
|
+
const modelApply = def.models?.apply;
|
|
171
|
+
return {
|
|
172
|
+
adapter: def.id,
|
|
173
|
+
source: "discovered",
|
|
174
|
+
discoverable: "parse",
|
|
175
|
+
authStores,
|
|
176
|
+
providers: [
|
|
177
|
+
{
|
|
178
|
+
id: "google",
|
|
179
|
+
billingEndpoint: "google",
|
|
180
|
+
cred: { present: oauthPresent || apiKeyPresent, source }
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
models: { mechanism: "catalog" },
|
|
184
|
+
endpointCompat: {},
|
|
185
|
+
application: {
|
|
186
|
+
modelApply: modelApply === "command" || modelApply === "arg" ? modelApply : "config",
|
|
187
|
+
postureApply: "none",
|
|
188
|
+
coupled: false
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export { gemini, geminiCapabilities, geminiRuntime };
|
|
194
|
+
//# sourceMappingURL=index.mjs.map
|
|
195
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;AAgCO,IAAM,SAAyB,cAAA,CAAe;AAAA,EACnD,IAAA,EAAM,QAAA;AAAA,EACN,EAAA,EAAI,QAAA;AAAA,EACJ,WAAA,EACE,uVAAA;AAAA,EACF,OAAA,EAAS,OAAA;AAAA,EACT,GAAA,EAAK,QAAA;AAAA;AAAA;AAAA;AAAA,EAIL,QAAA,EAAU,CAAC,oBAAoB,CAAA;AAAA,EAC/B,OAAA,EAAS;AAAA,IACP;AAAA,MACE,MAAA,EAAQ,KAAA;AAAA,MACR,OAAA,EAAS,oBAAA;AAAA,MACT,MAAA,EAAQ;AAAA;AACV,GACF;AAAA,EACA,aAAA,EAAe;AAAA,IACb,GAAA,EAAK,kBAAA;AAAA,IACL,KAAA,EAAO,sBAAA;AAAA,IACP,KAAA,EAAO,SAAA;AAAA,IACP,UAAA,EAAY;AAAA,GACd;AAAA,EACA,IAAA,EAAM;AAAA,IACJ,GAAA,EAAK,cAAA;AAAA;AAAA;AAAA,IAGL,KAAA,EAAO;AAAA,MACL,GAAA,EAAK,CAAC,gBAAA,EAAkB,gBAAA,EAAkB,8BAA8B;AAAA;AAC1E,GACF;AAAA;AAAA;AAAA;AAAA,EAIA,QAAA,EAAU,QAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmB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,EAAC;AAAA,IACjB,WAAA,EAAa;AAAA,MACX,UAAA,EAAY,UAAA,KAAe,SAAA,IAAa,UAAA,KAAe,QAAQ,UAAA,GAAa,QAAA;AAAA,MAC5E,YAAA,EAAc,MAAA;AAAA,MACd,OAAA,EAAS;AAAA;AACX,GACF;AACF","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-gemini — AIP-45 adapter for Google's Gemini CLI in ACP\n * mode (`gemini --experimental-acp`).\n *\n * The Gemini CLI is an open-source terminal agent that speaks the Agent Client\n * Protocol when launched with `--experimental-acp` (aliased to `--acp` on\n * current builds; the experimental spelling still works and matches the wider\n * ACP catalog). Install it with `npm i -g @google/gemini-cli`, then:\n *\n * import { gemini, geminiRuntime } from \"@agentproto/adapter-gemini\"\n * const session = await geminiRuntime().start({\n * env: { GEMINI_API_KEY: \"...\" },\n * })\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n *\n * The headline feature over the generic `gemini-cli` ACP catalog entry is\n * billing-auth: a native `provider` + a FILE-BASED (external) subscription so\n * \"use my existing Gemini login\" is a verified, observable, money-safe opt-in.\n */\n\nimport { join } from \"node:path\"\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\nimport type { AuthStore, CapabilityStrategy, CredSource } from \"@agentproto/provider-kit\"\n\nexport const gemini: AgentCliHandle = defineAgentCli({\n name: \"gemini\",\n id: \"gemini\",\n description:\n \"Google's Gemini CLI in ACP mode (`gemini --experimental-acp`) — an open-source terminal agent driving Gemini models over the Agent Client Protocol via stdio JSON-RPC. Native adapter (over the generic `gemini-cli` catalog entry) so subscription billing-auth — \\\"use my existing Gemini login\\\" — is a verified, money-safe opt-in.\",\n version: \"0.1.0\",\n bin: \"gemini\",\n // `--experimental-acp` starts ACP mode. Current Gemini CLI (0.45.x) prefers\n // the shorter `--acp`, but keeps `--experimental-acp` as a working alias, and\n // it's the spelling the rest of the ACP catalog uses — so keep it for parity.\n bin_args: [\"--experimental-acp\"],\n install: [\n {\n method: \"npm\",\n package: \"@google/gemini-cli\",\n global: true,\n },\n ],\n version_check: {\n cmd: \"gemini --version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=0.1.0\",\n timeout_ms: 15_000,\n },\n auth: {\n ref: \"./SECRETS.md\",\n // Every api-key rail the Gemini CLI honors — all three are scrubbed under a\n // file-based subscription so a stray key can't flip billing (see below).\n state: {\n env: [\"GEMINI_API_KEY\", \"GOOGLE_API_KEY\", \"GOOGLE_GENERATIVE_AI_API_KEY\"],\n },\n },\n // Billing-auth (opt-in — no authEnforce, so unconfigured spawns stay\n // ambient). Single-provider adapter: api-key mode SETS providerEnvVar\n // (\"google\") = GOOGLE_GENERATIVE_AI_API_KEY, derived from the catalog.\n provider: \"google\",\n // \"Use my existing Gemini login\" — a FILE-BASED (external) subscription. The\n // Gemini CLI's OAuth login lives in `~/.gemini/oauth_creds.json`\n // (`access_token`), which the CLI reads ITSELF; it has no env-bearer channel\n // like claude-code's CLAUDE_CODE_OAUTH_TOKEN. So `external: true`: subscription\n // mode injects NOTHING (no setEnv) — the host verifies the login is present\n // (fail-loud, via the `gemini` provision recipe) and the driver only SCRUBS\n // the api-key vars so a leftover key can't silently flip the spawn to per-token\n // API billing under a \"subscription\" label.\n //\n // GOOGLE_GENERATIVE_AI_API_KEY is scrubbed automatically (it's the provider's\n // api-key var). GEMINI_API_KEY and GOOGLE_API_KEY are the two SIBLING keys the\n // Gemini CLI also honors — and, critically, an env API key OVERRIDES the OAuth\n // login in Google's auth precedence, so BOTH must be scrubbed for the login to\n // win (they're listed as conflictEnv). Money-safe by construction: no OAuth\n // bearer is ever written into an api-key env var, because no bearer is injected\n // at all. An unconfigured gemini spawn stays ambient — the CLI uses its own\n // oauth_creds.json precedence — so this only ADDS an explicit, verified,\n // billing-guaranteed, observable opt-in on top of that.\n authSubscription: {\n external: true,\n conflictEnv: [\"GEMINI_API_KEY\", \"GOOGLE_API_KEY\"],\n },\n sandbox: \"./SANDBOX.md\",\n protocol: \"acp\",\n acp: \"./gemini-acp.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n models: {\n default: \"gemini-2.5-pro\",\n // Sourced from the model catalog's curated Google (vendor \"google\") text\n // models — NOT hand-invented ids (see packages/model-catalog/src/llm/\n // catalog.ts). Kept to the stable + current preview lines the CLI serves.\n allowed: [\n \"gemini-2.5-pro\",\n \"gemini-2.5-flash\",\n \"gemini-2.5-flash-lite\",\n \"gemini-3.5-flash\",\n \"gemini-3.1-pro-preview\",\n \"gemini-3-flash-preview\",\n \"gemini-3.1-flash-lite\",\n ],\n env: {\n google: \"GOOGLE_GENERATIVE_AI_API_KEY\",\n gemini: \"GEMINI_API_KEY\",\n },\n // The Gemini CLI takes its model as the documented global `-m/--model`\n // flag, composed into argv at spawn time (confirmed present on 0.45.2 via\n // `gemini --help`). It's a global flag, so it applies alongside\n // `--experimental-acp`; worst case a future ACP build ignores it and the\n // session falls back to the CLI's default model — never a mis-bill.\n apply: \"arg\",\n bin_args_template: [\"-m\", \"{model}\"],\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: false,\n file_io: true,\n // Gemini models are natively multimodal; the CLI forwards ACP image content\n // blocks into the Gemini vision pipeline.\n multimodal: true,\n // The Gemini CLI implements ACP session lifecycle (newSession / loadSession).\n resumable: true,\n bidirectional: true,\n },\n options: [\n {\n id: \"model\",\n type: \"enum\",\n enum: [\n \"gemini-2.5-pro\",\n \"gemini-2.5-flash\",\n \"gemini-2.5-flash-lite\",\n \"gemini-3.5-flash\",\n \"gemini-3.1-pro-preview\",\n \"gemini-3-flash-preview\",\n \"gemini-3.1-flash-lite\",\n ],\n description: \"Override the default model for this operator binding.\",\n // Real composition happens via `models.apply: \"arg\"` above; this option\n // exists so `config.options.model` validates.\n },\n ],\n continuation: {\n default: \"native-resume\",\n supported: [\"native-resume\", \"pinned-session\", \"transcript\", \"none\"],\n pinned_session: {\n idle_timeout_ms: 1_800_000,\n key_scope: [\"conversation\", \"operator\"],\n },\n },\n tags: [\"gemini\", \"google\", \"acp\", \"agent-runtime\", \"coding\"],\n})\n\nexport function geminiRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(gemini)\n}\n\ninterface GeminiSettingsFile {\n security?: { auth?: { selectedType?: unknown } }\n}\n\n/**\n * Best-effort capability discovery for gemini: parses the Gemini CLI's own\n * `~/.gemini/settings.json` (`security.auth.selectedType`) plus the\n * presence of `~/.gemini/oauth_creds.json` to report whether the \"use my\n * existing Gemini login\" file-based subscription is actually live on this\n * host, alongside the api-key fallback path. Never throws — a malformed\n * settings.json just leaves `selectedType` undetermined rather than\n * blanking the whole result.\n */\nexport const geminiCapabilities: CapabilityStrategy = async (def, ctx) => {\n const settingsPath = join(ctx.homeDir, \".gemini\", \"settings.json\")\n const oauthPath = join(ctx.homeDir, \".gemini\", \"oauth_creds.json\")\n\n let selectedType: string | undefined\n const settingsRaw = await ctx.readFile(settingsPath)\n if (settingsRaw !== null) {\n try {\n const parsed = JSON.parse(settingsRaw) as GeminiSettingsFile\n if (typeof parsed.security?.auth?.selectedType === \"string\") {\n selectedType = parsed.security.auth.selectedType\n }\n } catch (err) {\n ctx.warn(\n `gemini capability discovery: could not parse ~/.gemini/settings.json: ` +\n `${err instanceof Error ? err.message : String(err)}`,\n )\n }\n }\n\n const oauthLoginPresent = (await ctx.readFile(oauthPath)) !== null\n const oauthSelected = selectedType !== undefined && selectedType.toLowerCase().includes(\"oauth\")\n\n // Same var the manifest itself declares for google (models.env.google) —\n // never a hardcoded/guessed name.\n const apiKeyEnvVar = def.models?.env?.google ?? \"GOOGLE_GENERATIVE_AI_API_KEY\"\n const apiKeyPresent = !!ctx.env[apiKeyEnvVar]\n\n const oauthPresent = oauthSelected && oauthLoginPresent\n const source: CredSource = oauthPresent\n ? { kind: \"oauth-file\", path: \"~/.gemini/oauth_creds.json\" }\n : { kind: \"env\", var: apiKeyEnvVar }\n\n const authStores: AuthStore[] = [\n { kind: \"oauth-file\", path: \"~/.gemini/oauth_creds.json\", format: \"json\", providerKeyed: false },\n { kind: \"env\", providerKeyed: false },\n ]\n\n const modelApply = def.models?.apply\n return {\n adapter: def.id,\n source: \"discovered\",\n discoverable: \"parse\",\n authStores,\n providers: [\n {\n id: \"google\",\n billingEndpoint: \"google\",\n cred: { present: oauthPresent || apiKeyPresent, source },\n },\n ],\n models: { mechanism: \"catalog\" },\n endpointCompat: {},\n application: {\n modelApply: modelApply === \"command\" || modelApply === \"arg\" ? modelApply : \"config\",\n postureApply: \"none\",\n coupled: false,\n },\n }\n}\n\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/adapter-gemini",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "@agentproto/adapter-gemini — AIP-45 AGENT-CLI adapter for Google's Gemini CLI in ACP mode (`gemini --experimental-acp`). Native billing-auth: \"use my existing Gemini login\".",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"aip-45",
|
|
8
|
+
"gemini",
|
|
9
|
+
"google",
|
|
10
|
+
"acp",
|
|
11
|
+
"agent-cli",
|
|
12
|
+
"adapter"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://agentproto.sh/docs/aip-45",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/agentproto/ts",
|
|
18
|
+
"directory": "adapters/gemini"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "dist/index.mjs",
|
|
23
|
+
"module": "dist/index.mjs",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.mjs",
|
|
29
|
+
"default": "./dist/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./GEMINI.md": "./GEMINI.md",
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"GEMINI.md",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@agentproto/driver-agent-cli": "2.1.0",
|
|
45
|
+
"@agentproto/provider-kit": "0.4.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^25.6.2",
|
|
49
|
+
"tsup": "^8.5.1",
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"vitest": "^3.2.4",
|
|
52
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"dev": "tsup --watch",
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"clean": "rm -rf dist",
|
|
58
|
+
"check-types": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run --passWithNoTests",
|
|
60
|
+
"test:watch": "vitest"
|
|
61
|
+
}
|
|
62
|
+
}
|