@namzu/google 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/CHANGELOG.md +9 -0
- package/LICENSE.md +110 -0
- package/README.md +25 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +308 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/wire.d.ts +31 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +183 -0
- package/dist/wire.js.map +1 -0
- package/package.json +69 -0
- package/src/client.ts +349 -0
- package/src/index.ts +17 -0
- package/src/types.ts +12 -0
- package/src/wire.ts +194 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @namzu/google
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7785cb4: Add Google model access with a native SDK provider and CLI model selection. Reuse an existing Gemini CLI Google sign-in from this device, including the paired Windows home under WSL, without requiring a new API key. Explicit Gemini or Google API keys remain an alternative and take precedence when configured. Borrowed sign-ins are refreshed in memory without rewriting their owner file; Google account access retains the Code Assist route rather than being sent to the API-key endpoint.
|
|
8
|
+
|
|
9
|
+
Initial native Gemini API and existing Gemini CLI OAuth transport.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 Cogitave
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @namzu/google
|
|
2
|
+
|
|
3
|
+
Native Google Gemini GenerateContent provider for the Namzu SDK. Supports Gemini API keys and an existing Gemini CLI OAuth account through Code Assist. This package owns transport, not login or credential storage.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { GoogleProvider } from '@namzu/google'
|
|
7
|
+
|
|
8
|
+
const provider = new GoogleProvider({ apiKey: process.env.GEMINI_API_KEY })
|
|
9
|
+
for await (const chunk of provider.chatStream({
|
|
10
|
+
model: 'gemini-2.5-flash',
|
|
11
|
+
messages: [{ role: 'user', content: 'Hello', timestamp: Date.now() }],
|
|
12
|
+
})) {
|
|
13
|
+
if (chunk.delta.content) process.stdout.write(chunk.delta.content)
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For Gemini CLI accounts, supply `getAccessToken(signal)` instead of `apiKey`. The host callback must refresh expired tokens and honor cancellation. Optional `projectId` selects an already configured Code Assist project; otherwise `loadCodeAssist` discovers the current account's managed project. Uninitialized accounts must complete setup in Gemini CLI: Namzu never automatically enrolls an account or selects a billing tier.
|
|
18
|
+
|
|
19
|
+
Configuration also accepts `timeoutMs` (120 seconds by default), a `fetch` implementation, and a host-level `model` hint. Each `chatStream` request's model is authoritative. API keys go to Google's Generative Language API; OAuth tokens only go to Google's Code Assist endpoint. HTTP error bodies are not exposed because they may contain account information.
|
|
20
|
+
|
|
21
|
+
The driver streams text, thinking summaries and function calls; retains signed native response parts for unchanged, same-route tool history; maps inline image/document inputs and tool results; and maps native JSON Schema output. Unsupported explicit controls fail before transport. Gemini 2.5 accepts manual thinking budgets, not a fabricated low/high effort menu. Known Gemini 3 Flash and Pro families expose their documented thinking levels. Unknown models have no inferred menu.
|
|
22
|
+
|
|
23
|
+
API-key model listing uses Google's live generation-model catalogue. Code Assist has no equivalent public catalogue: its conservative menu (Gemini 2.5 Flash and Pro) is a set of candidates, not proof of account entitlement. Additional explicit model IDs can be sent directly to `chatStream`. Prices are standard text/image [API reference prices](https://ai.google.dev/gemini-api/docs/pricing), in USD per million tokens, not subscription billing; Pro's reference is for prompts up to 200k tokens. For live models without established prices, numeric price fields use the SDK's existing zero sentinel for unknown; this is not a free-tier claim and must not be treated as a billing estimate. Credential probing is separate from listing. Authentication and a particular model's entitlement still require a successful server request.
|
|
24
|
+
|
|
25
|
+
Transport contracts follow [Google's thought-signature guidance](https://ai.google.dev/gemini-api/docs/generate-content/thought-signatures), [thinking controls](https://ai.google.dev/gemini-api/docs/generate-content/thinking), and the [Gemini CLI Code Assist source](https://github.com/google-gemini/gemini-cli/tree/main/packages/core/src/code_assist). Runtime-neutral history from another provider cannot preserve Google's native signatures.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChatCompletionParams, LLMProvider, ModelInfo, ProviderCapabilities, StreamChunk } from '@namzu/sdk';
|
|
2
|
+
import type { GoogleConfig } from './types.js';
|
|
3
|
+
export declare const DEFAULT_GEMINI_MODEL = "gemini-2.5-flash";
|
|
4
|
+
export declare const GOOGLE_CAPABILITIES: ProviderCapabilities;
|
|
5
|
+
/** Native GenerateContent transport; credential ownership remains with the host. */
|
|
6
|
+
export declare class GoogleProvider implements LLMProvider {
|
|
7
|
+
private readonly config;
|
|
8
|
+
readonly id = "google";
|
|
9
|
+
readonly name = "Google Gemini";
|
|
10
|
+
readonly capabilities: ProviderCapabilities;
|
|
11
|
+
private readonly fetcher;
|
|
12
|
+
private readonly projectId?;
|
|
13
|
+
constructor(config: GoogleConfig);
|
|
14
|
+
reasoningEffortLevelsFor(model: string): readonly import("@namzu/sdk").ReasoningEffort[] | undefined;
|
|
15
|
+
private signal;
|
|
16
|
+
private request;
|
|
17
|
+
private project;
|
|
18
|
+
probeCredential(signal?: AbortSignal): Promise<void>;
|
|
19
|
+
listModels(signal?: AbortSignal): Promise<ModelInfo[]>;
|
|
20
|
+
chatStream(p: ChatCompletionParams): AsyncIterable<StreamChunk>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,oBAAoB,EACpB,WAAW,EAEX,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,oBAAoB,qBAAqB,CAAA;AAMtD,eAAO,MAAM,mBAAmB,EAAE,oBASjC,CAAA;AAeD,oFAAoF;AACpF,qBAAa,cAAe,YAAW,WAAW;IAMrC,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC,QAAQ,CAAC,EAAE,YAAW;IACtB,QAAQ,CAAC,IAAI,mBAAkB;IAC/B,QAAQ,CAAC,YAAY,uBAAsB;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAQ;gBACN,MAAM,EAAE,YAAY;IAWjD,wBAAwB,CAAC,KAAK,EAAE,MAAM;IAGtC,OAAO,CAAC,MAAM;YAIA,OAAO;YAgCP,OAAO;IAiCf,eAAe,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAKpD,UAAU,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAiDrD,UAAU,CAAC,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;CAkKtE"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { attributionHeaders, providerHttpError } from '@namzu/sdk';
|
|
3
|
+
import { buildRequest, effortLevels, partDigest, routeFor } from './wire.js';
|
|
4
|
+
export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-flash';
|
|
5
|
+
// Standard text/image API reference prices, USD per million; not subscription billing.
|
|
6
|
+
const PRICES = {
|
|
7
|
+
'gemini-2.5-flash': [0.3, 2.5],
|
|
8
|
+
'gemini-2.5-pro': [1.25, 10],
|
|
9
|
+
};
|
|
10
|
+
export const GOOGLE_CAPABILITIES = {
|
|
11
|
+
supportsTools: true,
|
|
12
|
+
supportsStreaming: true,
|
|
13
|
+
supportsFunctionCalling: true,
|
|
14
|
+
supportsVision: true,
|
|
15
|
+
supportsDocuments: true,
|
|
16
|
+
supportsToolResultImages: true,
|
|
17
|
+
supportsToolResultDocuments: true,
|
|
18
|
+
supportsNativeStructuredOutput: true,
|
|
19
|
+
};
|
|
20
|
+
const API = 'https://generativelanguage.googleapis.com/v1beta';
|
|
21
|
+
const ASSIST = 'https://cloudcode-pa.googleapis.com/v1internal';
|
|
22
|
+
/** Native GenerateContent transport; credential ownership remains with the host. */
|
|
23
|
+
export class GoogleProvider {
|
|
24
|
+
config;
|
|
25
|
+
id = 'google';
|
|
26
|
+
name = 'Google Gemini';
|
|
27
|
+
capabilities = GOOGLE_CAPABILITIES;
|
|
28
|
+
fetcher;
|
|
29
|
+
projectId;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.config = config;
|
|
32
|
+
if (Boolean(config.apiKey) === Boolean(config.getAccessToken))
|
|
33
|
+
throw new Error('Configure exactly one of Gemini apiKey or getAccessToken.');
|
|
34
|
+
if (config.timeoutMs !== undefined &&
|
|
35
|
+
(!Number.isFinite(config.timeoutMs) || config.timeoutMs <= 0))
|
|
36
|
+
throw new Error('Gemini timeoutMs must be positive.');
|
|
37
|
+
this.fetcher = config.fetch ?? globalThis.fetch;
|
|
38
|
+
this.projectId = config.projectId;
|
|
39
|
+
}
|
|
40
|
+
reasoningEffortLevelsFor(model) {
|
|
41
|
+
return effortLevels(model);
|
|
42
|
+
}
|
|
43
|
+
signal(signal) {
|
|
44
|
+
const timeout = AbortSignal.timeout(this.config.timeoutMs ?? 120_000);
|
|
45
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
46
|
+
}
|
|
47
|
+
async request(url, signal, body, accessToken) {
|
|
48
|
+
signal.throwIfAborted();
|
|
49
|
+
const headers = {
|
|
50
|
+
...attributionHeaders(),
|
|
51
|
+
'Content-Type': 'application/json',
|
|
52
|
+
};
|
|
53
|
+
if (this.config.getAccessToken)
|
|
54
|
+
headers.Authorization = `Bearer ${accessToken ?? (await this.config.getAccessToken(signal))}`;
|
|
55
|
+
else
|
|
56
|
+
headers['x-goog-api-key'] = this.config.apiKey;
|
|
57
|
+
signal.throwIfAborted();
|
|
58
|
+
const res = await this.fetcher(url, {
|
|
59
|
+
redirect: 'error',
|
|
60
|
+
method: body === undefined ? 'GET' : 'POST',
|
|
61
|
+
headers,
|
|
62
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
63
|
+
signal,
|
|
64
|
+
});
|
|
65
|
+
if (!res.ok) {
|
|
66
|
+
await res.body?.cancel();
|
|
67
|
+
throw providerHttpError({
|
|
68
|
+
providerId: this.id,
|
|
69
|
+
status: res.status,
|
|
70
|
+
retryAfter: res.headers.get('retry-after'),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
async project(signal, verify = false, accessToken) {
|
|
76
|
+
if (this.projectId && !verify)
|
|
77
|
+
return this.projectId;
|
|
78
|
+
const res = await this.request(`${ASSIST}:loadCodeAssist`, signal, {
|
|
79
|
+
cloudaicompanionProject: this.projectId,
|
|
80
|
+
metadata: {
|
|
81
|
+
ideType: 'IDE_UNSPECIFIED',
|
|
82
|
+
platform: 'PLATFORM_UNSPECIFIED',
|
|
83
|
+
pluginType: 'GEMINI',
|
|
84
|
+
},
|
|
85
|
+
}, accessToken);
|
|
86
|
+
const data = (await res.json());
|
|
87
|
+
const project = typeof data.cloudaicompanionProject === 'string'
|
|
88
|
+
? data.cloudaicompanionProject
|
|
89
|
+
: (data.cloudaicompanionProject?.id ?? this.projectId);
|
|
90
|
+
if (!data.currentTier || !project)
|
|
91
|
+
throw new Error('Complete Gemini CLI login and Code Assist setup before using this account in Namzu; automatic onboarding is not performed.');
|
|
92
|
+
return project;
|
|
93
|
+
}
|
|
94
|
+
async probeCredential(signal) {
|
|
95
|
+
const bounded = this.signal(signal);
|
|
96
|
+
if (this.config.getAccessToken)
|
|
97
|
+
await this.project(bounded, true);
|
|
98
|
+
else
|
|
99
|
+
await this.request(`${API}/models?pageSize=1`, bounded).then((r) => r.body?.cancel());
|
|
100
|
+
}
|
|
101
|
+
async listModels(signal) {
|
|
102
|
+
signal?.throwIfAborted();
|
|
103
|
+
if (this.config.getAccessToken)
|
|
104
|
+
return Object.keys(PRICES).map((id) => ({
|
|
105
|
+
id,
|
|
106
|
+
name: id,
|
|
107
|
+
inputPrice: PRICES[id]?.[0] ?? 0,
|
|
108
|
+
outputPrice: PRICES[id]?.[1] ?? 0,
|
|
109
|
+
supportsToolUse: true,
|
|
110
|
+
supportsStreaming: true,
|
|
111
|
+
reasoningEffortLevels: effortLevels(id),
|
|
112
|
+
}));
|
|
113
|
+
const models = [];
|
|
114
|
+
let pageToken;
|
|
115
|
+
const bounded = this.signal(signal);
|
|
116
|
+
do {
|
|
117
|
+
const res = await this.request(`${API}/models?pageSize=100${pageToken ? `&pageToken=${encodeURIComponent(pageToken)}` : ''}`, bounded);
|
|
118
|
+
const data = (await res.json());
|
|
119
|
+
for (const m of data.models ?? [])
|
|
120
|
+
if (m.supportedGenerationMethods?.includes('generateContent')) {
|
|
121
|
+
const id = m.name.replace(/^models\//, '');
|
|
122
|
+
models.push({
|
|
123
|
+
id,
|
|
124
|
+
name: m.displayName ?? id,
|
|
125
|
+
contextWindow: m.inputTokenLimit,
|
|
126
|
+
maxOutputTokens: m.outputTokenLimit,
|
|
127
|
+
inputPrice: PRICES[id]?.[0] ?? 0,
|
|
128
|
+
outputPrice: PRICES[id]?.[1] ?? 0,
|
|
129
|
+
supportsToolUse: true,
|
|
130
|
+
supportsStreaming: true,
|
|
131
|
+
reasoningEffortLevels: effortLevels(id),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
pageToken = data.nextPageToken;
|
|
135
|
+
} while (pageToken);
|
|
136
|
+
return models;
|
|
137
|
+
}
|
|
138
|
+
async *chatStream(p) {
|
|
139
|
+
const scope = this.config.getAccessToken ? 'code-assist' : 'api-key';
|
|
140
|
+
const body = buildRequest(p, scope);
|
|
141
|
+
const signal = this.signal(p.signal);
|
|
142
|
+
const id = randomUUID();
|
|
143
|
+
const oauth = Boolean(this.config.getAccessToken);
|
|
144
|
+
const accessToken = await this.config.getAccessToken?.(signal);
|
|
145
|
+
const url = oauth
|
|
146
|
+
? `${ASSIST}:streamGenerateContent?alt=sse`
|
|
147
|
+
: `${API}/models/${encodeURIComponent(p.model)}:streamGenerateContent?alt=sse`;
|
|
148
|
+
const payload = oauth
|
|
149
|
+
? {
|
|
150
|
+
model: p.model,
|
|
151
|
+
project: await this.project(signal, false, accessToken),
|
|
152
|
+
user_prompt_id: id,
|
|
153
|
+
request: body,
|
|
154
|
+
}
|
|
155
|
+
: body;
|
|
156
|
+
const res = await this.request(url, signal, payload, accessToken);
|
|
157
|
+
if (!res.body)
|
|
158
|
+
throw new Error('Gemini returned an empty streaming body.');
|
|
159
|
+
const reader = res.body.getReader();
|
|
160
|
+
const decoder = new TextDecoder();
|
|
161
|
+
let buffer = '';
|
|
162
|
+
let terminal = false;
|
|
163
|
+
let text = '';
|
|
164
|
+
let toolIndex = 0;
|
|
165
|
+
let reasoningIndex = 0;
|
|
166
|
+
const parts = [];
|
|
167
|
+
const calls = [];
|
|
168
|
+
let usage;
|
|
169
|
+
let finish;
|
|
170
|
+
const parse = (event) => {
|
|
171
|
+
const data = event
|
|
172
|
+
.split('\n')
|
|
173
|
+
.filter((l) => l.startsWith('data:'))
|
|
174
|
+
.map((l) => l.slice(5).trimStart())
|
|
175
|
+
.join('\n');
|
|
176
|
+
return data && data !== '[DONE]' ? JSON.parse(data) : undefined;
|
|
177
|
+
};
|
|
178
|
+
try {
|
|
179
|
+
while (true) {
|
|
180
|
+
signal.throwIfAborted();
|
|
181
|
+
const next = await reader.read();
|
|
182
|
+
buffer += decoder.decode(next.value, { stream: !next.done });
|
|
183
|
+
buffer = buffer.replace(/\r\n/g, '\n');
|
|
184
|
+
if (buffer.length > 16 * 1024 * 1024)
|
|
185
|
+
throw new Error('Gemini SSE event exceeds 16 MiB.');
|
|
186
|
+
let boundary = buffer.indexOf('\n\n');
|
|
187
|
+
while (boundary >= 0 || (next.done && buffer.trim())) {
|
|
188
|
+
const event = boundary >= 0 ? buffer.slice(0, boundary) : buffer;
|
|
189
|
+
buffer = boundary >= 0 ? buffer.slice(boundary + 2) : '';
|
|
190
|
+
boundary = buffer.indexOf('\n\n');
|
|
191
|
+
const envelope = parse(event);
|
|
192
|
+
if (!envelope)
|
|
193
|
+
continue;
|
|
194
|
+
const chunk = envelope.response ?? envelope;
|
|
195
|
+
if (chunk.promptFeedback?.blockReason) {
|
|
196
|
+
terminal = true;
|
|
197
|
+
finish = 'content_filter';
|
|
198
|
+
}
|
|
199
|
+
const candidate = chunk.candidates?.[0];
|
|
200
|
+
for (const part of candidate?.content?.parts ?? []) {
|
|
201
|
+
parts.push(part);
|
|
202
|
+
if (part.functionCall) {
|
|
203
|
+
const f = part.functionCall;
|
|
204
|
+
const callId = f.id ?? randomUUID();
|
|
205
|
+
const args = JSON.stringify(f.args ?? {});
|
|
206
|
+
calls.push({
|
|
207
|
+
id: callId,
|
|
208
|
+
type: 'function',
|
|
209
|
+
function: { name: f.name, arguments: args },
|
|
210
|
+
});
|
|
211
|
+
yield {
|
|
212
|
+
id,
|
|
213
|
+
delta: {
|
|
214
|
+
toolCalls: [
|
|
215
|
+
{
|
|
216
|
+
index: toolIndex,
|
|
217
|
+
id: callId,
|
|
218
|
+
type: 'function',
|
|
219
|
+
function: { name: f.name, arguments: args },
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
yield {
|
|
225
|
+
id,
|
|
226
|
+
delta: { toolCallEnd: { index: toolIndex++, id: callId } },
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
else if (part.thought) {
|
|
230
|
+
yield {
|
|
231
|
+
id,
|
|
232
|
+
delta: {
|
|
233
|
+
reasoning: {
|
|
234
|
+
index: reasoningIndex++,
|
|
235
|
+
type: 'thinking',
|
|
236
|
+
text: part.text ?? '',
|
|
237
|
+
signature: part.thoughtSignature,
|
|
238
|
+
done: true,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
else if (part.text) {
|
|
244
|
+
text += part.text;
|
|
245
|
+
yield { id, delta: { content: part.text } };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (candidate?.finishReason) {
|
|
249
|
+
terminal = true;
|
|
250
|
+
if (candidate.finishReason === 'MAX_TOKENS')
|
|
251
|
+
finish = 'length';
|
|
252
|
+
else if (candidate.finishReason === 'STOP')
|
|
253
|
+
finish = calls.length ? 'tool_calls' : 'stop';
|
|
254
|
+
else if ([
|
|
255
|
+
'SAFETY',
|
|
256
|
+
'RECITATION',
|
|
257
|
+
'BLOCKLIST',
|
|
258
|
+
'PROHIBITED_CONTENT',
|
|
259
|
+
'SPII',
|
|
260
|
+
'IMAGE_SAFETY',
|
|
261
|
+
].includes(candidate.finishReason))
|
|
262
|
+
finish = 'content_filter';
|
|
263
|
+
else
|
|
264
|
+
throw new Error(`Gemini generation stopped with ${candidate.finishReason}.`);
|
|
265
|
+
}
|
|
266
|
+
const u = chunk.usageMetadata;
|
|
267
|
+
if (u)
|
|
268
|
+
usage = {
|
|
269
|
+
cachedTokens: u.cachedContentTokenCount ?? 0,
|
|
270
|
+
cacheWriteTokens: 0,
|
|
271
|
+
reasoningTokens: u.thoughtsTokenCount,
|
|
272
|
+
promptTokens: u.promptTokenCount ?? 0,
|
|
273
|
+
completionTokens: (u.candidatesTokenCount ?? 0) + (u.thoughtsTokenCount ?? 0),
|
|
274
|
+
totalTokens: u.totalTokenCount ??
|
|
275
|
+
(u.promptTokenCount ?? 0) +
|
|
276
|
+
(u.candidatesTokenCount ?? 0) +
|
|
277
|
+
(u.thoughtsTokenCount ?? 0),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (next.done)
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
if (!terminal)
|
|
284
|
+
throw new Error('Gemini stream ended without a terminal finish reason.');
|
|
285
|
+
yield {
|
|
286
|
+
id,
|
|
287
|
+
delta: {},
|
|
288
|
+
finishReason: finish,
|
|
289
|
+
usage,
|
|
290
|
+
replayState: {
|
|
291
|
+
kind: 'namzu-google',
|
|
292
|
+
version: 1,
|
|
293
|
+
scope,
|
|
294
|
+
digest: partDigest(parts),
|
|
295
|
+
route: routeFor(p),
|
|
296
|
+
parts,
|
|
297
|
+
text,
|
|
298
|
+
calls,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
finally {
|
|
303
|
+
await reader.cancel().catch(() => { });
|
|
304
|
+
reader.releaseLock();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAUlE,OAAO,EAAa,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACvF,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AACtD,uFAAuF;AACvF,MAAM,MAAM,GAA8C;IACzD,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IAC9B,gBAAgB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;CAC5B,CAAA;AACD,MAAM,CAAC,MAAM,mBAAmB,GAAyB;IACxD,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,uBAAuB,EAAE,IAAI;IAC7B,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,IAAI;IACvB,wBAAwB,EAAE,IAAI;IAC9B,2BAA2B,EAAE,IAAI;IACjC,8BAA8B,EAAE,IAAI;CACpC,CAAA;AACD,MAAM,GAAG,GAAG,kDAAkD,CAAA;AAC9D,MAAM,MAAM,GAAG,gDAAgD,CAAA;AAa/D,oFAAoF;AACpF,MAAM,OAAO,cAAc;IAMG;IALpB,EAAE,GAAG,QAAQ,CAAA;IACb,IAAI,GAAG,eAAe,CAAA;IACtB,YAAY,GAAG,mBAAmB,CAAA;IAC1B,OAAO,CAAyB;IAChC,SAAS,CAAS;IACnC,YAA6B,MAAoB;Q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AC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;YACvF,MAAM;gBACL,EAAE;gBACF,KAAK,EAAE,EAAE;gBACT,YAAY,EAAE,MAAM;gBACpB,KAAK;gBACL,WAAW,EAAE;oBACZ,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,CAAC;oBACV,KAAK;oBACL,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC;oBACzB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;oBAClB,KAAK;oBACL,IAAI;oBACJ,KAAK;iBACL;aACD,CAAA;QACF,CAAC;gBAAS,CAAC;YACV,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YACrC,MAAM,CAAC,WAAW,EAAE,CAAA;QACrB,CAAC;IACF,CAAC;CACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RegisterOptions } from '@namzu/sdk';
|
|
2
|
+
import type { GoogleProviderConfig } from './types.js';
|
|
3
|
+
declare module '@namzu/sdk' {
|
|
4
|
+
interface ProviderConfigRegistry {
|
|
5
|
+
google: GoogleProviderConfig;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare function registerGoogle(options?: RegisterOptions): void;
|
|
9
|
+
export { GoogleProvider, GOOGLE_CAPABILITIES, DEFAULT_GEMINI_MODEL, } from './client.js';
|
|
10
|
+
export type { GoogleConfig, GoogleProviderConfig } from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAEnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,QAAQ,YAAY,CAAC;IAC3B,UAAU,sBAAsB;QAC/B,MAAM,EAAE,oBAAoB,CAAA;KAC5B;CACD;AACD,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAE9D;AACD,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProviderRegistry } from '@namzu/sdk';
|
|
2
|
+
import { GOOGLE_CAPABILITIES, GoogleProvider } from './client.js';
|
|
3
|
+
export function registerGoogle(options) {
|
|
4
|
+
ProviderRegistry.register('google', GoogleProvider, GOOGLE_CAPABILITIES, options);
|
|
5
|
+
}
|
|
6
|
+
export { GoogleProvider, GOOGLE_CAPABILITIES, DEFAULT_GEMINI_MODEL, } from './client.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOjE,MAAM,UAAU,cAAc,CAAC,OAAyB;IACvD,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAA;AAClF,CAAC;AACD,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACpB,MAAM,aAAa,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Gemini API credentials or a host-owned Gemini CLI OAuth token refresher. */
|
|
2
|
+
export interface GoogleConfig {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
getAccessToken?: (signal?: AbortSignal) => Promise<string>;
|
|
5
|
+
projectId?: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
fetch?: typeof globalThis.fetch;
|
|
9
|
+
}
|
|
10
|
+
export interface GoogleProviderConfig extends GoogleConfig {
|
|
11
|
+
type: 'google';
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAC/B;AACD,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACzD,IAAI,EAAE,QAAQ,CAAA;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ChatCompletionParams, ReasoningEffort } from '@namzu/sdk';
|
|
2
|
+
export interface Part {
|
|
3
|
+
text?: string;
|
|
4
|
+
thought?: boolean;
|
|
5
|
+
thoughtSignature?: string;
|
|
6
|
+
functionCall?: {
|
|
7
|
+
name: string;
|
|
8
|
+
args?: Record<string, unknown>;
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface Content {
|
|
14
|
+
role: string;
|
|
15
|
+
parts: Part[];
|
|
16
|
+
}
|
|
17
|
+
export interface Replay {
|
|
18
|
+
kind: 'namzu-google';
|
|
19
|
+
version: 1;
|
|
20
|
+
scope: string;
|
|
21
|
+
digest: string;
|
|
22
|
+
route: unknown;
|
|
23
|
+
parts: Part[];
|
|
24
|
+
text: string;
|
|
25
|
+
calls: unknown;
|
|
26
|
+
}
|
|
27
|
+
export declare function effortLevels(model: string): readonly ReasoningEffort[] | undefined;
|
|
28
|
+
export declare function routeFor(p: ChatCompletionParams): import("@namzu/sdk").ProviderRoute;
|
|
29
|
+
export declare function partDigest(parts: Part[]): string;
|
|
30
|
+
export declare function buildRequest(p: ChatCompletionParams, scope?: string): Record<string, unknown>;
|
|
31
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEvE,MAAM,WAAW,IAAI;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,YAAY,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5E,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB;AACD,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,IAAI,EAAE,CAAA;CACb;AACD,MAAM,WAAW,MAAM;IACtB,IAAI,EAAE,cAAc,CAAA;IACpB,OAAO,EAAE,CAAC,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CA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