chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 11:58:09 +08:00
commit c48e26cdd0
2909 changed files with 1591131 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { GeminiCliAgent, tool, z } from '../src/index.js';
async function main() {
const getContextTool = tool(
{
name: 'get_context',
description: 'Get information about the current session context.',
inputSchema: z.object({}),
},
async (_params, context) => {
if (!context) {
return { error: 'Context not available' };
}
console.log('Session Context Accessed:');
console.log(`- Session ID: ${context.sessionId}`);
console.log(`- CWD: ${context.cwd}`);
console.log(`- Timestamp: ${context.timestamp}`);
let fileContent = null;
try {
// Try to read a file (e.g., package.json in the CWD)
// Note: This relies on the agent running in a directory with package.json
fileContent = await context.fs.readFile('package.json');
} catch (e) {
console.log(`- Could not read package.json: ${e}`);
}
let shellOutput = null;
try {
// Try to run a simple shell command
const result = await context.shell.exec('echo "Hello from SDK Shell"');
shellOutput = result.output.trim();
} catch (e) {
console.log(`- Could not run shell command: ${e}`);
}
return {
sessionId: context.sessionId,
cwd: context.cwd,
hasFsAccess: !!context.fs,
hasShellAccess: !!context.shell,
packageJsonExists: !!fileContent,
shellEcho: shellOutput,
};
},
);
const agent = new GeminiCliAgent({
instructions:
'You are a helpful assistant. Use the get_context tool to tell me about my environment.',
tools: [getContextTool],
// Set CWD to the package root so package.json exists
cwd: process.cwd(),
});
console.log("Sending prompt: 'What is my current session context?'");
for await (const chunk of agent.sendStream(
'What is my current session context?',
)) {
if (chunk.type === 'content') {
process.stdout.write(chunk.value || '');
}
}
}
main().catch(console.error);
+38
View File
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { GeminiCliAgent, tool, z } from '../src/index.js';
async function main() {
const myTool = tool(
{
name: 'add',
description: 'Add two numbers.',
inputSchema: z.object({
a: z.number().describe('the first number'),
b: z.number().describe('the second number'),
}),
},
async ({ a, b }) => {
console.log(`Tool 'add' called with a=${a}, b=${b}`);
return { result: a + b };
},
);
const agent = new GeminiCliAgent({
instructions: 'Make sure to always talk like a pirate.',
tools: [myTool],
});
console.log("Sending prompt: 'add 5 + 6'");
for await (const chunk of agent.sendStream(
'add 5 + 6 and tell me a story involving the result',
)) {
console.log(JSON.stringify(chunk, null, 2));
}
}
main().catch(console.error);