@lay111/dsh-plugin-google 1.0.14 → 1.0.16
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/package.json +1 -1
- package/src/api.js +74 -20
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -3,21 +3,61 @@ import { findModel } from './models.js';
|
|
|
3
3
|
|
|
4
4
|
const ANTIGRAVITY_ENDPOINTS = [
|
|
5
5
|
'https://daily-cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse',
|
|
6
|
-
'https://cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse',
|
|
6
|
+
'https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:streamGenerateContent?alt=sse',
|
|
7
7
|
];
|
|
8
8
|
|
|
9
|
+
export function cleanSchema(schema) {
|
|
10
|
+
if (!schema || typeof schema !== 'object') return schema;
|
|
11
|
+
const clone = JSON.parse(JSON.stringify(schema));
|
|
12
|
+
|
|
13
|
+
function clean(obj) {
|
|
14
|
+
if (!obj || typeof obj !== 'object') return;
|
|
15
|
+
delete obj.$schema;
|
|
16
|
+
delete obj.$id;
|
|
17
|
+
delete obj.definitions;
|
|
18
|
+
delete obj.$defs;
|
|
19
|
+
delete obj.additionalProperties;
|
|
20
|
+
|
|
21
|
+
if (obj.properties && typeof obj.properties === 'object') {
|
|
22
|
+
for (const key of Object.keys(obj.properties)) {
|
|
23
|
+
clean(obj.properties[key]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (obj.items && typeof obj.items === 'object') {
|
|
27
|
+
clean(obj.items);
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(obj.anyOf)) {
|
|
30
|
+
obj.anyOf.forEach(clean);
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(obj.oneOf)) {
|
|
33
|
+
obj.oneOf.forEach(clean);
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(obj.allOf)) {
|
|
36
|
+
obj.allOf.forEach(clean);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
clean(clone);
|
|
41
|
+
return clone;
|
|
42
|
+
}
|
|
43
|
+
|
|
9
44
|
export function formatMessagesToAntigravity(messages, modelSpec, projectId) {
|
|
10
45
|
const contents = [];
|
|
11
|
-
|
|
46
|
+
const systemParts = [];
|
|
47
|
+
const isClaude = modelSpec.id.includes('claude') || modelSpec.wireId.includes('claude');
|
|
12
48
|
|
|
13
49
|
for (const message of messages) {
|
|
14
50
|
if (message.role === 'system') {
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
let text = '';
|
|
52
|
+
if (typeof message.content === 'string') {
|
|
53
|
+
text = message.content;
|
|
54
|
+
} else if (Array.isArray(message.content)) {
|
|
55
|
+
text = message.content
|
|
56
|
+
.map((b) => (b.type === 'text' ? b.text : typeof b === 'string' ? b : ''))
|
|
57
|
+
.join('\n');
|
|
58
|
+
}
|
|
59
|
+
if (text.trim().length > 0) {
|
|
60
|
+
systemParts.push({ text: text.trim() });
|
|
21
61
|
}
|
|
22
62
|
continue;
|
|
23
63
|
}
|
|
@@ -30,24 +70,43 @@ export function formatMessagesToAntigravity(messages, modelSpec, projectId) {
|
|
|
30
70
|
} else if (Array.isArray(message.content)) {
|
|
31
71
|
for (const block of message.content) {
|
|
32
72
|
if (block.type === 'text') {
|
|
33
|
-
|
|
73
|
+
if (block.text && block.text.length > 0) {
|
|
74
|
+
parts.push({ text: block.text });
|
|
75
|
+
}
|
|
34
76
|
} else if (block.type === 'thought' || block.type === 'reasoning') {
|
|
35
77
|
parts.push({ thought: true, text: block.text || block.thought || '' });
|
|
36
78
|
} else if (block.type === 'tool-call') {
|
|
37
|
-
|
|
79
|
+
const callPart = {
|
|
38
80
|
functionCall: {
|
|
39
81
|
name: block.name,
|
|
40
82
|
args: typeof block.arguments === 'string' ? JSON.parse(block.arguments || '{}') : block.arguments || {},
|
|
41
83
|
},
|
|
42
|
-
}
|
|
84
|
+
};
|
|
85
|
+
if (!isClaude) {
|
|
86
|
+
callPart.thoughtSignature = block.thoughtSignature || 'skip_thought_signature_validator';
|
|
87
|
+
}
|
|
88
|
+
parts.push(callPart);
|
|
43
89
|
} else if (block.type === 'tool-result') {
|
|
90
|
+
let outputText = '';
|
|
91
|
+
if (typeof block.content === 'string') {
|
|
92
|
+
outputText = block.content;
|
|
93
|
+
} else if (Array.isArray(block.content)) {
|
|
94
|
+
outputText = block.content
|
|
95
|
+
.map((p) => p.text || (typeof p === 'string' ? p : JSON.stringify(p)))
|
|
96
|
+
.join('\n');
|
|
97
|
+
} else if (typeof block.content === 'object' && block.content !== null) {
|
|
98
|
+
outputText = JSON.stringify(block.content);
|
|
99
|
+
} else {
|
|
100
|
+
outputText = String(block.content || '');
|
|
101
|
+
}
|
|
102
|
+
|
|
44
103
|
contents.push({
|
|
45
104
|
role: 'user',
|
|
46
105
|
parts: [
|
|
47
106
|
{
|
|
48
107
|
functionResponse: {
|
|
49
|
-
name: block.name || 'tool',
|
|
50
|
-
response: {
|
|
108
|
+
name: block.name || block.toolName || 'tool',
|
|
109
|
+
response: { output: outputText || '(no output)' },
|
|
51
110
|
},
|
|
52
111
|
},
|
|
53
112
|
],
|
|
@@ -68,7 +127,6 @@ export function formatMessagesToAntigravity(messages, modelSpec, projectId) {
|
|
|
68
127
|
contents.push({ role: 'user', parts: [{ text: 'Hello' }] });
|
|
69
128
|
}
|
|
70
129
|
|
|
71
|
-
const isClaude = modelSpec.id.includes('claude') || modelSpec.wireId.includes('claude');
|
|
72
130
|
const payload = {
|
|
73
131
|
project: projectId || 'aicode-consumers',
|
|
74
132
|
model: modelSpec.wireId,
|
|
@@ -86,7 +144,7 @@ export function formatMessagesToAntigravity(messages, modelSpec, projectId) {
|
|
|
86
144
|
}
|
|
87
145
|
: {}),
|
|
88
146
|
},
|
|
89
|
-
...(
|
|
147
|
+
...(systemParts.length > 0 ? { systemInstruction: { parts: systemParts } } : {}),
|
|
90
148
|
labels: {
|
|
91
149
|
trajectory_id: `traj_${Date.now()}`,
|
|
92
150
|
used_claude: String(isClaude),
|
|
@@ -109,7 +167,7 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
109
167
|
functionDeclarations: options.tools.map((tool) => ({
|
|
110
168
|
name: tool.name,
|
|
111
169
|
description: tool.description || '',
|
|
112
|
-
parameters: tool.parameters || {},
|
|
170
|
+
parameters: cleanSchema(tool.parameters || {}),
|
|
113
171
|
})),
|
|
114
172
|
},
|
|
115
173
|
];
|
|
@@ -143,7 +201,6 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
143
201
|
const errText = await res.text();
|
|
144
202
|
lastError = `(HTTP ${status}) ${errText}`;
|
|
145
203
|
|
|
146
|
-
// If rate-limited (429) or temporary server overload (503), wait and retry
|
|
147
204
|
if ((status === 429 || status === 503) && attempt < maxRetries - 1) {
|
|
148
205
|
await new Promise((r) => setTimeout(r, (attempt + 1) * 1500));
|
|
149
206
|
continue;
|
|
@@ -160,9 +217,6 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
160
217
|
}
|
|
161
218
|
|
|
162
219
|
if (!response) {
|
|
163
|
-
if (lastError?.includes('429') || lastError?.includes('exhausted')) {
|
|
164
|
-
throw new Error(`Google Quota Exceeded (429): 当前模型并发或配额超限。建议在 TUI 中输入 /model 切换至 claude-sonnet-4.6、gemini-3.7-flash-medium 或 gemini-3.6-flash,或稍等 20 秒后重试。`);
|
|
165
|
-
}
|
|
166
220
|
throw new Error(`Google Antigravity Upstream Error: ${lastError}`);
|
|
167
221
|
}
|
|
168
222
|
|