This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dotenv/config'; | |
| import { streamText } from 'ai'; | |
| import { anthropicTools } from '@ai-sdk/anthropic/internal'; | |
| const result = await streamText({ | |
| model: 'anthropic/claude-sonnet-4.5', | |
| tools: { | |
| codeExecution: anthropicTools.codeExecution_20250522(), | |
| }, | |
| messages: [{ role: 'user', content: 'Run: print(1+1)' }], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/anthropic/src/tool/code-execution_20250522.ts | |
| import { | |
| createProviderToolFactoryWithOutputSchema, | |
| lazySchema, | |
| zodSchema, | |
| } from '@ai-sdk/provider-utils'; | |
| import { z } from 'zod/v4'; | |
| export const codeExecution_20250522OutputSchema = lazySchema(() => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/anthropic/src/anthropic-tools.ts | |
| export const anthropicTools = { | |
| /** | |
| * bash 工具使 Claude 能够在持久的 bash 会话中执行 shell 命令, | |
| * 实现系统操作、脚本执行和命令行自动化。 | |
| * | |
| * 支持图像结果。 | |
| */ | |
| bash_20241022, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { streamText, jsonSchema } from 'ai'; | |
| import 'dotenv/config'; | |
| const result = await streamText({ | |
| model: 'anthropic/claude-sonnet-4.5', | |
| tools: { | |
| // 创建订单工具 - 根据 orderType 有不同的必填字段 | |
| createOrder: { | |
| description: '创建一个新订单,根据订单类型需要不同的信息', | |
| inputSchema: jsonSchema<{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getParent(snapshot) { | |
| // You can get the reference (A Firebase object) from a snapshot | |
| // using .ref(). | |
| var ref = snapshot.ref(); | |
| // Now simply find the parent and return the name. | |
| return ref.parent().name(); | |
| } | |
| var testRef = new Firebase("https://example.firebaseIO-demo.com/foo/bar"); | |
| testRef.once("value", function(snapshot) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function pushSomething(ref) { | |
| // Let's push something. push() returns a reference that you can hold onto! | |
| var justPushed = ref.push({test: "push"}); | |
| // We return a reference, but you can also return the name of the newly | |
| // created object with .name(). | |
| return justPushed; | |
| } | |
| function removeItem(ref) { | |
| // Now we can get back to that item we just pushed via .child(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function go() { | |
| var userId = prompt('Username?', 'Guest'); | |
| // Consider adding '/<unique id>' if you have multiple games. | |
| var gameRef = new Firebase(GAME_LOCATION); | |
| assignPlayerNumberAndPlayGame(userId, gameRef); | |
| }; | |
| // The maximum number of players. If there are already | |
| // NUM_PLAYERS assigned, users won't be able to join the game. | |
| var NUM_PLAYERS = 4; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function go() { | |
| var userId = prompt('Username?', 'Guest'); | |
| var userData = { name: userId }; | |
| tryCreateUser(userId, userData); | |
| } | |
| var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users'; | |
| function userCreated(userId, success) { | |
| if (!success) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Helper function to extract claims from a JWT. Does *not* verify the | |
| // validity of the token. | |
| // credits: https://github.com/firebase/angularFire/blob/master/angularFire.js#L370 | |
| // polyfill window.atob() for IE8: https://github.com/davidchambers/Base64.js | |
| // or really fast Base64 by Fred Palmer: https://code.google.com/p/javascriptbase64/ | |
| function deconstructJWT(token) { | |
| var segments = token.split("."); | |
| if (!segments instanceof Array || segments.length !== 3) { | |
| throw new Error("Invalid JWT"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // pros: does not fetch entire record set | |
| // cons: grabs the last record which needs to be ignored | |
| var first = true; | |
| var ref = new Firebase(...); | |
| ref.endAt().limit(1).on("child_added", function(snap) { | |
| if( first ) { | |
| first = false; | |
| } | |
| else { | |
| console.log('new record', snap.val()); |
NewerOlder