repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
onchainkit | github_2023 | coinbase | typescript | vwToPx | const vwToPx = (vw: number) => (vw / 100) * window.innerWidth; | // Convert viewport units to pixels | https://github.com/coinbase/onchainkit/blob/afcc29e362654e2fd7bc60908a0cc122b0d281c4/src/internal/utils/getWindowDimensions.ts#L23-L23 | afcc29e362654e2fd7bc60908a0cc122b0d281c4 |
onchainkit | github_2023 | coinbase | typescript | onError | function onError(e: ErrorEvent) {
e.preventDefault();
} | // disable error output | https://github.com/coinbase/onchainkit/blob/afcc29e362654e2fd7bc60908a0cc122b0d281c4/src/nft/components/NFTErrorBoundary.test.tsx#L7-L9 | afcc29e362654e2fd7bc60908a0cc122b0d281c4 |
onchainkit | github_2023 | coinbase | typescript | mockWindow | const mockWindow = (innerWidth: number, innerHeight: number) => {
vi.stubGlobal('window', {
innerWidth,
innerHeight,
});
}; | // Mock window dimensions | https://github.com/coinbase/onchainkit/blob/afcc29e362654e2fd7bc60908a0cc122b0d281c4/src/wallet/utils/getWalletSubComponentPosition.test.ts#L10-L15 | afcc29e362654e2fd7bc60908a0cc122b0d281c4 |
enterprise-commerce | github_2023 | Blazity | typescript | handleClick | const handleClick = async () => {
if (!combination?.id) return
setIsPending(true)
setTimeout(() => {
setProduct({ product, combination })
setIsPending(false)
}, 300)
setTimeout(() => clean(), 4500)
setCheckoutReady(false)
const res = await addCartItem(null, combination.id, pr... | // Mimic delay and display optimistic UI due to shopify API being slow | https://github.com/Blazity/enterprise-commerce/blob/d34a5d9e8e580f3db9d763955455d0a66669c5a2/starters/shopify-algolia/app/product/_components/add-to-cart-button.tsx#L33-L52 | d34a5d9e8e580f3db9d763955455d0a66669c5a2 |
enterprise-commerce | github_2023 | Blazity | typescript | getAllResults | const getAllResults = async <T extends Record<string, any>>(client: ReturnType<typeof algoliaClient>, args: BrowseProps) => {
const allHits: T[] = []
let totalPages: number
let currentPage = 0
do {
const { hits, nbPages } = await client.browse<T>({
...args,
browseParams: {
...args.brows... | // agregator as temp fix for now | https://github.com/Blazity/enterprise-commerce/blob/d34a5d9e8e580f3db9d763955455d0a66669c5a2/starters/shopify-algolia/lib/algolia/client.ts#L44-L64 | d34a5d9e8e580f3db9d763955455d0a66669c5a2 |
enterprise-commerce | github_2023 | Blazity | typescript | normalizeProduct | function normalizeProduct(product: PlatformProduct, originalId: string): PlatformProduct {
return {
...product,
id: originalId,
}
} | /* Extract into utils */ | https://github.com/Blazity/enterprise-commerce/blob/d34a5d9e8e580f3db9d763955455d0a66669c5a2/starters/shopify-meilisearch/app/api/feed/sync/route.ts#L106-L111 | d34a5d9e8e580f3db9d763955455d0a66669c5a2 |
enterprise-commerce | github_2023 | Blazity | typescript | handleClick | const handleClick = async () => {
if (!combination?.id) return
setIsPending(true)
setTimeout(() => {
setProduct({ product, combination })
setIsPending(false)
}, 300)
setTimeout(() => clean(), 4500)
setCheckoutReady(false)
const res = await addCartItem(null, combination.id, pr... | // Mimic delay and display optimistic UI due to shopify API being slow | https://github.com/Blazity/enterprise-commerce/blob/d34a5d9e8e580f3db9d763955455d0a66669c5a2/starters/shopify-meilisearch/app/product/_components/add-to-cart-button.tsx#L33-L52 | d34a5d9e8e580f3db9d763955455d0a66669c5a2 |
hydration-overlay | github_2023 | BuilderIO | typescript | getEntryPoint | const getEntryPoint = <T extends keyof EntryObject>(
entryPoint: EntryObject[T]
): string[] | null => {
if (typeof entryPoint === "string") {
return [entryPoint];
} else if (Array.isArray(entryPoint)) {
return entryPoint;
} else if (typeof entryPoint === "object" && "import" in entryPoint) {
const e... | // `entryPoint` can be a string, array of strings, or object whose `import` property is one of those two | https://github.com/BuilderIO/hydration-overlay/blob/c8e1a27d6e2011ebdc9f3a7788df01d82eb84444/packages/lib/src/webpack.ts#L6-L23 | c8e1a27d6e2011ebdc9f3a7788df01d82eb84444 |
GPTRouter | github_2023 | Writesonic | typescript | main | async function main() {
const server = await buildServer();
try {
await server.listen({
port: 8000,
host: "0.0.0.0",
});
["SIGINT", "SIGTERM"].forEach(signal => {
process.on(signal, async () => {
server.log.info("Shutting down server...");
await server.close();
... | /**
* The entry point for initializing and starting the Fastify server.
* It loads the server configuration, starts listening on a given port and sets up
* signal handlers for a graceful shutdown.
*
* @async
* @function main
* @returns {Promise<void>} A promise that resolves when the server is successfully start... | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/index.ts#L12-L31 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | buildServer | async function buildServer() {
// Create a new Fastify server instance with pretty print logging enabled.
const server = Fastify({
logger: {
transport: {
target: "pino-pretty",
},
},
}).withTypeProvider<TypeBoxTypeProvider>();
try {
// Connect to the database using the TypeORM p... | /**
* Initializes and configures the Fastify server, including database connection,
* authentication, CORS settings, cron jobs, error handling, and routes.
*
* @returns {Promise<FastifyInstance>} A promise that resolves to the configured Fastify server instance.
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/server.ts#L49-L200 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | generationRouter | async function generationRouter(server: FastifyInstance) {
await server.register(import("@fastify/rate-limit"), {
max: 10,
timeWindow: "1440 minute",
keyGenerator: request => {
return request.headers["ws-secret"]?.toString() || "";
},
allowList: request => {
return request.headers["ws-... | /**
* Attach generation routes to the Fastify server.
* @param {FastifyInstance} server - The Fastify server instance.
* @returns {Promise<void>} - A promise that resolves after attaching the generation routes.
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/generation.route.ts#L22-L50 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | healthCheckRouter | async function healthCheckRouter(server: FastifyInstance) {
server.post("", { schema: HealthCheckSchema, onRequest: [server.authenticate] }, triggerHealthCheck);
server.get("", { schema: GetHealthCheckDataSchema, onRequest: [server.authenticate] }, getHealthCheckData);
} | /**
* Define routes for health check endpoint
* @param {FastifyInstance} server - The Fastify server instance
* @returns {Promise<void>} - A Promise that resolves once the routes are defined
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/healthCheck.route.ts#L11-L14 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | modelRouter | async function modelRouter(server: FastifyInstance) {
server.get("/all", { schema: GetAllModelsSchema, onRequest: [server.authenticate] }, getAllModels);
server.get("/:id", { schema: GetModelByIdSchema, onRequest: [server.authenticate] }, getModelById);
} | /**
* Attach model routes to the Fastify server instance
* @param {FastifyInstance} server - The Fastify server instance
* @returns {Promise<void>}
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/model.route.ts#L11-L14 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | modelUsageRouter | async function modelUsageRouter(server: FastifyInstance) {
server.get("/model", { schema: GetAllUsageByModelSchema, onRequest: [server.authenticate] }, getUsageDataByModel);
} | /**
* Adds route for getting usage data by model
*
* @param {FastifyInstance} server - The Fastify server instance
* @returns {Promise<void>} - A promise that resolves after adding the route
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/modelUsage.route.ts#L12-L14 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | promptRouter | async function promptRouter(server: FastifyInstance) {
server.get("/all", { schema: GetAllPromptsSchema, onRequest: [server.authenticate] }, getAllPrompts);
server.get("/:id", { schema: GetPromptByIdSchema, onRequest: [server.authenticate] }, getPromptById);
server.post("", { schema: CreatePromptSchema, onRequest... | /**
* Registers prompt related routes and their corresponding handlers.
* @param {FastifyInstance} server - The Fastify server instance.
* @returns {void}
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/prompt.route.ts#L18-L25 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | providerRouter | async function providerRouter(server: FastifyInstance) {
server.get("/all", { schema: GetAllProvidersSchema, onRequest: [server.authenticate] }, getActiveProviders);
} | /**
* Define routes for handling provider related operations.
*
* @param {FastifyInstance} server - The Fastify server instance
* @returns {Promise<void>} - A promise that resolves when the route is successfully registered
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/provider.route.ts#L12-L14 | 00601732f62a271e063a1341aa1237b37907c5a4 |
GPTRouter | github_2023 | Writesonic | typescript | userRouter | async function userRouter(server: FastifyInstance) {
server.post("/login", { schema: LoginSchema }, verifyUser);
} | /**
* Handles the user routes for login
* @param {FastifyInstance} server - The Fastify server instance
* @returns {Promise<void>} - A Promise that resolves when the route handling is complete
*/ | https://github.com/Writesonic/GPTRouter/blob/00601732f62a271e063a1341aa1237b37907c5a4/src/routes/user.route.ts#L11-L13 | 00601732f62a271e063a1341aa1237b37907c5a4 |
daisy-components | github_2023 | willpinha | typescript | format | function format(name: string) {
return name.toLowerCase().replace(/\s+/g, ""); // Case and whitespace insensitive
} | // Format tag and filter before comparison | https://github.com/willpinha/daisy-components/blob/7ad7e38e78eecdf8f464a1daab5b408c0a73245d/src/utils/filter.ts#L4-L6 | 7ad7e38e78eecdf8f464a1daab5b408c0a73245d |
glish | github_2023 | paralogical | typescript | hashForVariants | function hashForVariants(variants: {
[key in AlternativeCategory]?: unknown;
}): VariantHash {
return (
(variants.plural ? "1" : "0") +
(variants.past ? "1" : "0") +
(variants.gerund ? "1" : "0") +
(variants.actor ? "1" : "0")
);
} | // 0010 | https://github.com/paralogical/glish/blob/3d4578f9fd51421537ca64540c6d8e928c479f18/main.ts#L506-L515 | 3d4578f9fd51421537ca64540c6d8e928c479f18 |
glish | github_2023 | paralogical | typescript | findVariants | function findVariants(
wordSet: Map<string, Array<Array<string>>>,
word: Array<Array<string>>
): { [key in AlternativeCategory]?: Array<Array<string>> } {
const result: { [key in AlternativeCategory]?: Array<Array<string>> } = {};
const checkAndSet = (which: AlternativeCategory, end: string) => {
const comb... | /**
* Given a split IPA word, find all variants in original english, in split IPA
*/ | https://github.com/paralogical/glish/blob/3d4578f9fd51421537ca64540c6d8e928c479f18/main.ts#L520-L543 | 3d4578f9fd51421537ca64540c6d8e928c479f18 |
glish | github_2023 | paralogical | typescript | updateGraphPart | function updateGraphPart(
which: "onset" | "nucleus" | "coda",
graphPart: SonorityGraphPart,
letters: Array<string>,
// first phone of next part
nextPart: string | null
) {
// initial part of graph
if (which === "onset") {
incGraphPart(graphPart, null, letters?.[0] ?? nextPart);
}
if (letters == n... | // Given an input syllable, go through letters and update graph part | https://github.com/paralogical/glish/blob/3d4578f9fd51421537ca64540c6d8e928c479f18/sonorityGraph.ts#L125-L145 | 3d4578f9fd51421537ca64540c6d8e928c479f18 |
glish | github_2023 | paralogical | typescript | randomTilInPalete | const randomTilInPalete = (from: Array<[string | null, number]>) => {
const filteredFrom = from.filter(
([l]) => l == null || pallete.includes(l!)
);
if (filteredFrom.length === 0) {
return null;
}
return weightedRandomChoice(filteredFrom);
}; | // TODO: remove from palette as you usefrom a graph, | https://github.com/paralogical/glish/blob/3d4578f9fd51421537ca64540c6d8e928c479f18/sonorityGraph.ts#L302-L310 | 3d4578f9fd51421537ca64540c6d8e928c479f18 |
glish | github_2023 | paralogical | typescript | log | const log: typeof console.log = () => undefined; | // const log: typeof console.log = console.log; | https://github.com/paralogical/glish/blob/3d4578f9fd51421537ca64540c6d8e928c479f18/syllablize.ts#L351-L351 | 3d4578f9fd51421537ca64540c6d8e928c479f18 |
breadboard | github_2023 | breadboard-ai | typescript | describeSpecialist | function describeSpecialist(inputs: unknown) {
const { $inputSchema, $outputSchema, persona, task } =
inputs as SpecialistDescriberInputs;
const inputSchema: Schema = {
type: "object",
additionalProperties: false,
properties: {
...$inputSchema.properties,
in: {
title: "Context i... | /**
* The describer for the "Specialist" v2 component.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/agent-kit/src/templating.ts#L55-L206 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | content | function content(starInputs: unknown) {
const { template, role, context, ...inputs } = starInputs as ContentInputs;
const params = mergeParams(findParams(template));
const values = collectValues(params, inputs);
if (role) {
template.role = role;
}
return {
context: prependContext(context, subConte... | /**
* The guts of the "Content" component.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/agent-kit/src/templating.ts#L211-L439 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | splitToTemplateParts | function splitToTemplateParts(content: LlmContent): TemplatePart[] {
const parts = [];
for (const part of content.parts) {
if (!("text" in part)) {
parts.push(part);
continue;
}
const matches = part.text.matchAll(
/{{\s*(?<name>[\w-]+)(?:\s*\|\s*(?<op>[\w-]*)(?::\s*"(?<... | /**
* Takes an LLM Content and splits it further into parts where
* each {{param}} substitution is a separate part.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/agent-kit/src/templating.ts#L376-L401 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | isLLMContent | function isLLMContent(nodeValue: unknown): nodeValue is LlmContent {
if (typeof nodeValue !== "object" || !nodeValue) return false;
if (nodeValue === null || nodeValue === undefined) return false;
if ("role" in nodeValue && nodeValue.role === "$metadata") {
return true;
}
return "parts" in n... | /**
* Copied from @google-labs/breadboard
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/agent-kit/src/templating.ts#L423-L432 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | describeContent | function describeContent(inputs: unknown) {
const { template } = inputs as DescribeContentInputs;
const params = unique([...collectParams(textFromLLMContent(template))]);
const props = Object.fromEntries(
params.map((param) => [
toId(param),
{
title: toTitle(param),
description: `... | /**
* The describer for the "Content" component.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/agent-kit/src/templating.ts#L444-L569 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | splitToTemplateParts | function splitToTemplateParts(content: LlmContent): TemplatePart[] {
const parts: TemplatePart[] = [];
for (const part of content.parts) {
if (!("text" in part)) {
parts.push(part);
continue;
}
const matches = part.text.matchAll(
/{{\s*(?<name>[\w-]+)(?:\s*\|\s*(?<op>[\w-]*)(?::\s*"(?<... | /**
* Takes an LLM Content and splits it further into parts where
* each {{param}} substitution is a separate part.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/agent-kit/src/js-components/substitute.ts#L191-L218 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Conversation.availableTools | get availableTools() {
return this.#availableToolsComputed.value;
} | // pattern? | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/bbrt/src/llm/conversation.ts#L65-L67 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | ReactiveSessionState.rollback | rollback(index: number) {
this.events.splice(index);
} | /**
* Delete all events including and after the given index.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/bbrt/src/state/session.ts#L55-L57 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | ReactiveTurnState.partialText | get partialText(): string {
while (this.#textStartIndex < this.chunks.length) {
const event = this.chunks[this.#textStartIndex]!;
if (event.kind === "text") {
this.#textAccumulator += event.text;
}
this.#textStartIndex++;
}
return this.#textAccumulator;
} | /**
* The text we have accumulated so far (signal-reactive).
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/bbrt/src/state/turn.ts#L69-L78 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | ReactiveTurnState.partialFunctionCalls | get partialFunctionCalls(): ReadonlyArray<ReactiveFunctionCallState> {
const length = this.chunks.length;
for (let i = this.#functionCallsNextStartIndex; i < length; i++) {
const event = this.chunks[i]!;
if (event.kind === "function-call") {
this.#functionCallsAccumulator.push(event.call);
... | /**
* The function calls we have accumulated so far (signal-reactive).
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/bbrt/src/state/turn.ts#L85-L95 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | ReactiveTurnState.partialErrors | get partialErrors(): ReadonlyArray<TurnChunkError> {
const length = this.chunks.length;
for (let i = this.#errorsNextStartIndex; i < length; i++) {
const event = this.chunks[i]!;
if (event.kind === "error") {
this.#errorsAccumulator.push(event);
}
}
this.#errorsNextStartIndex =... | /**
* The errors we have accumulated so far (signal-reactive).
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/bbrt/src/state/turn.ts#L102-L112 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | VisitorStateManager.getOrCreateInvite | async getOrCreateInvite(): Promise<CreateInviteResponse> {
const invites = await this.listInvites();
if (invites.success && invites.invites.length > 0) {
return { success: true, invite: invites.invites[0] as string };
}
return this.createInvite();
} | /**
* Same as createInvite, but if an invite already exists, it will return that
* instead of creating a new one.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/board-server/src/app/utils/visitor-state-manager.ts#L249-L255 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | proxy | const proxy = async (_req: Request, _res: Response): Promise<void> => {
throw new Error("Not implemented");
// if (!getUserKey(req)) {
// res.status(401).json({
// error: "Need a valid server key to access the node proxy.",
// timestamp: timestamp(),
// });
// return;
// }
// const serv... | // class ResponseAdapter implements ProxyServerResponse { | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/board-server/src/express/proxy/proxy.ts#L32-L62 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.constructor | constructor(
{ url, title, description, version, $schema }: GraphInlineMetadata = {
$schema: breadboardSchema.$id,
}
) {
Object.assign(this, {
$schema: $schema ?? breadboardSchema.$id,
url,
title,
description,
version,
});
} | /**
*
* @param metadata - optional metadata for the board. Use this parameter
* to provide title, description, version, and URL for the board.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/board.ts#L60-L72 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.input | input<In = InputValues, Out = OutputValues>(
config: OptionalIdConfiguration = {}
): BreadboardNode<In, Out> {
const { $id, ...rest } = config;
return new Node(this, undefined, "input", { ...rest }, $id);
} | /**
* Places an `input` node on the board.
*
* An `input` node is a node that asks for inputs from the user.
*
* See [`input` node reference](https://github.com/breadboard-ai/breadboard/blob/main/packages/breadboard/docs/nodes.md#input) for more information.
*
* @param config - optional configurati... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/board.ts#L93-L98 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.output | output<In = InputValues, Out = OutputValues>(
config: OptionalIdConfiguration = {}
): BreadboardNode<In, Out> {
const { $id, ...rest } = config;
return new Node(this, undefined, "output", { ...rest }, $id);
} | /**
* Places an `output` node on the board.
*
* An `output` node is a node that provides outputs to the user.
*
* See [`output` node reference](https://github.com/breadboard-ai/breadboard/blob/main/packages/breadboard/docs/nodes.md#output) for more information.
*
* @param config - optional configur... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/board.ts#L110-L115 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.addKit | addKit<T extends Kit>(ctr: KitConstructor<T>): T {
const kit = asComposeTimeKit(ctr, this);
return kit as T;
} | /**
* Adds a new kit to the board.
*
* Kits are collections of nodes that are bundled together for a specific
* purpose. For example, the [Core Kit](https://github.com/breadboard-ai/breadboard/tree/main/packages/core) provides a nodes that
* are useful for making boards.
*
* Typically, kits are dis... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/board.ts#L147-L150 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.currentBoardToAddTo | currentBoardToAddTo(): Breadboard {
const closureStack = this.#topClosure
? this.#topClosure.#closureStack
: this.#closureStack;
if (closureStack.length === 0) return this;
else return closureStack[closureStack.length - 1];
} | /**
* Used in the context of board.lambda(): Returns the board that is currently
* being constructed, according to the nesting level of board.lambda() calls
* with JS functions.
*
* Only called by Node constructor, when adding nodes.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/board.ts#L159-L165 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Board.addEdgeAcrossBoards | addEdgeAcrossBoards(edge: Edge, from: Board, to: Board) {
if (edge.out === "*")
throw new Error("Across board wires: * wires not supported");
if (!edge.constant)
throw new Error("Across board wires: Must be constant for now");
if (to !== this)
throw new Error("Across board wires: Must be... | /**
*
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/board.ts#L170-L187 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | filterEmptyValues | function filterEmptyValues<T extends Record<string, unknown>>(obj: T): T {
return Object.fromEntries(
Object.entries(obj).filter(([, value]) => !!value)
) as T;
} | /**
* A utility function to filter out empty (null or undefined) values from
* an object.
*
* @param obj -- The object to filter.
* @returns -- The object with empty values removed.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/graph-based-node-handler.ts#L170-L174 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | filterEmptyValues | function filterEmptyValues<T extends Record<string, unknown>>(obj: T): T {
return Object.fromEntries(
Object.entries(obj).filter(([, value]) => !!value)
) as T;
} | /**
* A utility function to filter out empty (null or undefined) values from
* an object.
*
* @param obj -- The object to filter.
* @returns -- The object with empty values removed.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/sandboxed-run-module.ts#L424-L428 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | findStreams | const findStreams = (value: NodeValue, foundStreams: ReadableStream[]) => {
if (Array.isArray(value)) {
value.forEach((item: NodeValue) => {
findStreams(item, foundStreams);
});
} else if (typeof value === "object") {
if (value === null || value === undefined) return;
const maybeCapability = v... | // TODO: Remove this once MessageController is gone. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/stream.ts#L44-L60 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | computeSelection | function computeSelection(
graph: InspectableGraph,
nodes: NodeIdentifier[]
): EditableGraphSelectionResult {
// First, let's make sure that all nodes are present in graph.
const allPresent = nodes.every((id) => graph.nodeById(id));
if (!allPresent) {
return {
success: false,
error: "Can't cre... | /**
* Creates a selection: a list of nodes and edges that will are associated
* with the given list of node identifiers within the graph.
* The selection is transient in that it only applies to the current version
* of the graph and becomes invalid as soon as the graph mutates.
*
* @param nodes -- nodes to includ... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/editor/selection.ts#L21-L54 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | LocalRunner.constructor | constructor(config: RunConfig) {
super();
this.#config = config;
} | /**
* Initialize the runner.
* This does not start the runner.
*
* @param config -- configuration for the run
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/harness/local-runner.ts#L51-L54 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | secretHandlersFromKits | const secretHandlersFromKits = (kits: Kit[]): NodeHandler[] => {
const secretHandlers = [];
for (const kit of kits) {
for (const [key, handler] of Object.entries(kit.handlers)) {
if (key === "secrets") {
secretHandlers.push(handler);
}
}
}
return secretHandlers;
}; | /**
* Get all secret handlers from the given kits.
* This is used to create a fallback list for secret asking.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/harness/secrets.ts#L24-L34 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | makeTerribleOptions | function makeTerribleOptions(
options: InspectableGraphOptions = {}
): Required<InspectableGraphOptions> {
return {
kits: options.kits || [],
sandbox: options.sandbox || {
runModule() {
throw new Error("Non-existent sandbox: Terrible Options were used.");
},
},
loader: createLoad... | // TODO: Deprecate and remove. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/inspector/graph-store.ts#L59-L71 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | filterEmptyValues | function filterEmptyValues<T extends Record<string, unknown>>(obj: T): T {
return Object.fromEntries(
Object.entries(obj).filter(([, value]) => !!value)
) as T;
} | /**
* A utility function to filter out empty (null or undefined) values from
* an object.
*
* @param obj -- The object to filter.
* @returns -- The object with empty values removed.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/inspector/graph-store.ts#L535-L539 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | filterEmptyValues | function filterEmptyValues<T extends Record<string, unknown>>(obj: T): T {
return Object.fromEntries(
Object.entries(obj).filter(([, value]) => {
if (!value) return false;
if (typeof value === "object") {
return Object.keys(value).length > 0;
}
return true;
})
) as T;
} | /**
* A utility function to filter out empty (null or undefined) values from
* an object.
*
* @param obj -- The object to filter.
* @returns -- The object with empty values removed.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/inspector/graph/describer-manager.ts#L495-L505 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Entry.addError | addError(event: InspectableRunErrorEvent) {
const entry = this.create([this.#children.length]);
entry.event = event as unknown as InspectableRunNodeEvent;
} | /**
* We handle error specially, because unlike sidecars, errors result
* in stopping the run, and we need to display them at the end of the run.
* @param event -- The error event to add.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/inspector/run/path-registry.ts#L94-L97 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | getLastNodeEVent | const getLastNodeEVent = () => {
const events = this.#events.events;
for (let i = events.length - 1; i >= 0; i--) {
const maybeNodeEvent = events[i];
if (maybeNodeEvent.type === "node" && !maybeNodeEvent.bubbled)
return maybeNodeEvent;
}
return null;
}; | // TODO: Implement full stack. For now, just return the top-level item. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/inspector/run/run.ts#L305-L313 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Snapshot.update | async update(_manual: boolean = false): Promise<void> {
// Use inifite loop with dequeueing instead of a typical forEach,
// because the middle of the loop has awaits and they can introduce
// new items into the pending queue.
for (;;) {
const pending = this.#pending.shift();
if (!pending) {... | /**
*
* @param manual -- if `true`, the updates will stop once the
* update queue is empty, and when the new items arrive, this
* method will have to be called again.
* If `false` (default), will continue updating as soon as new
* items arrive into the update queue.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/inspector/snapshot/snapshot.ts#L81-L122 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | KitBuilder.wrap | static wrap<F extends Record<string, Function>>(
params: KitBuilderOptions,
functions: F
): KitConstructor<
GenericKit<{ [x in keyof FunctionsOnly<F>]: NodeHandler }>
> {
const createHandler = (
previous: NodeHandlers,
// eslint-disable-next-line @typescript-eslint/ban-types
curren... | // eslint-disable-next-line @typescript-eslint/ban-types | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/kits/builder.ts#L113-L201 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | getConfigWithLambda | const getConfigWithLambda = (
board: Breadboard,
config: ConfigOrGraph
): OptionalIdConfiguration => {
// Did we get a graph?
const gotGraph =
(config as GraphDescriptor).nodes !== undefined &&
(config as GraphDescriptor).edges !== undefined &&
(config as GraphDescriptor).kits !== undefined;
// L... | /**
* Syntactic sugar for node factories that accept lambdas. This allows passing
* either
* - A JS function that is a lambda function defining the board
* - A board capability, i.e. the result of calling lambda()
* - A board node, which should be a node with a `board` output
* or
* - A regular config, with ... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/kits/ctors.ts#L68-L93 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | registerKitGraphs | function registerKitGraphs(
legacyKitGraphs: GraphDescriptor[],
graphStore: MutableGraphStore
): void {
for (const project of legacyKitGraphs) {
if (!project.graphs) continue;
for (const [key, graph] of Object.entries(project.graphs)) {
graphStore.addByDescriptor({
...graph,
url: `${... | /**
* A helper function for registering old-style graph kits that are
* created using `kitFromGraphDescriptor`.
*
* Call it to ensure that the graphs, representing the node handlers
* for these kits are in the graph store, so that the graph store doesn't
* attempt to load them (their URLs are just URIs).
*
* @p... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/kits/load.ts#L186-L199 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | lambdaFactory | function lambdaFactory(
options: {
input?: Schema;
output?: Schema;
graph?: GraphDeclarationFunction;
invoke?: NodeProxyHandlerFunction;
describe?: NodeDescriberFunction;
name?: string;
} & GraphCombinedMetadata
): Lambda {
if (!options.invoke && !options.graph)
throw new Error("Missin... | /**
* Actual implementation of all the above
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/board.ts#L73-L372 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | getLambdaNode | function getLambdaNode() {
if (lambdaNode) return lambdaNode;
const serialized = factory.serialize();
// HACK: Since node creation is synchronous, we put a promise for the board
// capability here. BuilderNode.serializeNode() awaits that then.
lambdaNode = new BuilderNode("lambda", lexicalScope, {... | // ClosureNodeInterface: | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/board.ts#L298-L329 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | serializeFunction | const serializeFunction = (name: string, handlerFn: Function) => {
let code = handlerFn.toString();
const arrowFunctionRegex = /(?:async\s*)?(\w+|\([^)]*\))\s*=>\s*/;
const traditionalFunctionRegex =
/(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*\{/;
if (arrowFunctionRegex.test(code)) {
code = `const... | // eslint-disable-next-line @typescript-eslint/ban-types | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L40-L55 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderNode.addInputsFromNode | addInputsFromNode(
from: AbstractNode,
keymap: KeyMap = { "*": "" },
constant?: boolean,
schema?: Schema
) {
const keyPairs = Object.entries(keymap);
if (keyPairs.length === 0) {
// Add an empty edge: Just control flow, no data moving.
this.addIncomingEdge(from, "", "", constant);
... | // Add inputs from another node as edges | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L161-L189 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderNode.serializeNode | async serializeNode(): Promise<[NodeDescriptor, GraphDescriptor?]> {
// HACK: See board.getClosureNode() and
// board.getBoardCapabilityAsValue() for why this is needed. There we
// create a node that has a board capability as input, but serializing the
// graph is async, while node creation isn't. So w... | // here. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L314-L383 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderNode.asProxy | asProxy(): NodeProxy<I, O> {
return new Proxy(this, {
get(target, prop, receiver) {
if (typeof prop === "string") {
const value = new Value(
target as unknown as BuilderNode<InputValues, OutputValues>,
target.#scope as BuilderScope,
prop
);
... | // TODO: Hack keys() to make spread work | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L419-L459 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderNode.unProxy | unProxy() {
return this;
} | /**
* Retrieve underlying node from a NodeProxy. Use like this:
*
* if (thing instanceof BuilderNode) { const node = thing.unProxy(); }
*
* @returns A BuilderNode that is not a proxy, but the original BuilderNode.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L468-L470 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderNode.then | then<TResult1 = O, TResult2 = never>(
onfulfilled?: ((value: O) => TResult1 | PromiseLike<TResult1>) | null,
onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
): PromiseLike<TResult1 | TResult2> {
if (this.#scope.serializing())
throw new Error(
`Can't \`await\` on $... | /**
* Makes the node (and its proxy) act as a Promise, which returns the output
* of the node. This trigger the execution of the graph built up so far.
*
* this.#promise is a Promise that gets resolved with the (first and only the
* first) invoke() call of the node. It is resolved with the outputs.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L483-L510 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderNode.in | in(
inputs:
| NodeProxy<InputValues, Partial<I>>
| InputsMaybeAsValues<I>
| AbstractValue<NodeValue>
) {
if (inputs instanceof BaseNode) {
this.addInputsFromNode(inputs);
} else if (isValue(inputs)) {
this.addInputsFromNode(...inputs.asNodeInput());
} else {
this.ad... | // return a proxy object typed with the input types. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/node.ts#L547-L561 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderScope.constructor | constructor(
config: ScopeConfig & {
serialize?: boolean;
parentLambda?: BuilderNode;
} = {}
) {
super(config);
this.#isSerializing = config.serialize ?? false;
this.parentLambdaNode = config.parentLambda;
} | // TODO:BASE, config of subclasses can have more fields | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/scope.ts#L29-L38 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BuilderScope.asScopeFor | asScopeFor<T extends (...args: any[]) => any>(fn: T): T {
return ((...args: unknown[]) => {
const oldScope = swapCurrentContextScope(this);
try {
return fn(...args);
} finally {
swapCurrentContextScope(oldScope);
}
}) as T;
} | // eslint-disable-next-line @typescript-eslint/no-explicit-any | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/scope.ts#L57-L66 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Value.in | in(
inputs:
| BuilderNodeInterface<InputValues, OutputValues>
| AbstractValue<NodeValue>
| InputsMaybeAsValues<InputValues>
) {
let invertedMap = Object.fromEntries(
Object.entries(this.#keymap).map(([fromKey, toKey]) => [toKey, fromKey])
);
if (isValue(inputs)) {
invert... | // node input values type through the chain of values and .as() statements. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/value.ts#L148-L171 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Value.invoke | invoke(config?: BuilderNodeConfig): NodeProxy {
return new BuilderNode("invoke", this.#scope, {
...config,
$board: this,
}).asProxy();
} | // do it and let the runtime throw an error if this wasn't one. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/value.ts#L199-L204 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Value.isUnknown | isUnknown(): AbstractValue<unknown> {
delete this.#schema.type;
return this as unknown as AbstractValue<unknown>;
} | /**
* The following are type-casting methods that are useful when a node type
* returns generic types but we want to narrow the types to what we know they
* are, e.g. a parser node returning the result as raw wires.
*
* This is also a way to define the schema of a board, e.g. by casting input
* wires ... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/grammar/value.ts#L218-L221 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | BaseNode.invoke | async invoke(inputs: I, dynamicScope?: Scope): Promise<O> {
const scope = dynamicScope ?? (this.#scope as Scope);
const handler: NodeHandler | undefined =
this.#handler ?? scope.getHandler(this.type);
let result;
const handlerFn =
handler && "invoke" in handler && handler.invoke
?... | // deserialized nodes that require the Builder environment. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/runner/node.ts#L117-L146 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | State.missingInputs | missingInputs(node: AbstractNode): string[] | false {
if (node.incoming.length === 0 && this.haveRun.has(node)) return [];
const requiredKeys = new Set(node.incoming.map((edge) => edge.in));
const presentKeys = new Set([
...Object.keys(node.configuration),
...Object.keys(this.constants.get(nod... | /**
* Compute required inputs from edges and compare with present inputs
*
* Required inputs are
* - for all named incoming edges, the presence of any data, irrespective of
* which node they come from
* - at least one of the incoming empty or * wires, if present (TODO: Is that
* correct?)
... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/new/runner/state.ts#L53-L70 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | getCompleteChunks | const getCompleteChunks = (pending: string, chunk: string) => {
const asString = `${pending}${chunk}`;
return asString.split("\n\n");
}; | /**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/remote/chunk-repair.ts#L7-L10 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | toReanimationState | function toReanimationState(
root: LifecyclePathRegistryEntry<RunStackEntry>,
visits: VisitTracker
): ReanimationState {
function pathToString(path: number[]): string {
return path.join("-");
}
function descend(
entry: LifecyclePathRegistryEntry<RunStackEntry>,
path: number[],
result: Reanima... | // TODO: Support stream serialization somehow. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/run/lifecycle.ts#L30-L56 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Registry.constructor | constructor(root: LifecyclePathRegistryEntry<Data> = emptyEntry()) {
this.root = root;
} | // parent: LifecyclePathRegistryEntry | null; | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/run/registry.ts#L20-L22 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Traversal.computeMissingInputs | static computeMissingInputs(
heads: Edge[],
inputs: InputValues,
current: NodeDescriptor,
start?: NodeIdentifier
): string[] {
const isStartNode = current.id === start;
const requiredInputs: string[] = isStartNode
? []
: requiredInputsFromEdges(heads);
const inputsWithConfigura... | /**
* Computes the missing inputs for a node. A missing input is an input that is
* required by the node, but is not (yet) available in the current state.
* @param heads All the edges that point to the node.
* @param inputs The input values that will be passed to the node
* @param current The node that i... | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/traversal/index.ts#L32-L52 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | MachineResult.skip | get skip(): boolean {
return this.missingInputs.length > 0;
} | /**
* `true` if the machine decided that the node should be skipped, rather than
* visited.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/traversal/result.ts#L52-L54 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | MachineEdgeState.wireOutputs | wireOutputs(opportunites: Edge[], outputs: OutputValues): void {
// Verify that all edges are from the same node.
if (
opportunites.filter(
(opportunity) => opportunity.from != opportunites[0].from
).length !== 0
)
throw new Error("All opportunities must be from the same node");
... | /**
* Processes outputs by wiring them to the destinations according
* to the supplied edges. Assumes that the outputs were generated by
* the from node.
*
* @param opportunites {Edge[]} Edges to process
* @param outputs {OutputValues} Outputs to wire
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/traversal/state.ts#L48-L75 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | MachineEdgeState.getAvailableInputs | getAvailableInputs(nodeId: NodeIdentifier): InputValues {
const result: InputValues = {};
for (const queuesMap of [
this.constants.get(nodeId), // Constants are overwritten by state.
this.state.get(nodeId),
]) {
if (!queuesMap) continue;
for (const [key, queue] of queuesMap.entries(... | /**
* Returns the available inputs for a given node.
*
* @param nodeId {NodeIdentifier} The node to get the inputs for.
* @returns {InputValues} The available inputs.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/traversal/state.ts#L83-L97 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | MachineEdgeState.useInputs | useInputs(nodeId: NodeIdentifier, inputs: InputValues): void {
const queuesMap = this.state.get(nodeId);
if (!queuesMap) return;
for (const key in inputs) {
const queue = queuesMap.get(key);
if (!queue) continue;
queue.shift();
}
} | /**
* Shifts inputs from the queues. Leaves constants as is.
*
* @param nodeId {NodeIdentifier} The node to shift the inputs for.
* @param inputs {InputValues} The inputs that are used.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/traversal/state.ts#L105-L113 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | hashString | function hashString(str: string) {
let hash = 5381;
let i = str.length;
while (i) {
hash = (hash * 33) ^ str.charCodeAt(--i);
}
return hash >>> 0;
} | /**
* Computes a hash for a string using the DJB2 algorithm.
* @param str
* @returns
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/src/utils/hash.ts#L63-L72 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | echo | const echo = (input: string) => input; | // A normal function that will be wrapped. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/tests/kits.ts#L8-L8 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | echo | const echo = (echo_this: string) => echo_this; | // A normal function that will be wrapped. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/tests/kits.ts#L27-L27 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | echo | const echo = (echo_this: string) => {
return { out: echo_this, other: "stuff" };
}; | // A normal function that will be wrapped. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/tests/kits.ts#L59-L61 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | add | const add = (a: number, b: number) => {
return a + b;
}; | // A normal function that will be wrapped. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/tests/kits.ts#L93-L95 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | buildTestGraph | function buildTestGraph(scope: Scope) {
const input = new BaseNode("input", scope);
const noop = new BaseNode("noop", scope);
const output = new BaseNode("output", scope);
noop.addIncomingEdge(input, "foo", "foo");
output.addIncomingEdge(noop, "foo", "bar");
scope.pin(output);
} | // Builds a test graph just using the primitives. | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/tests/new/runner/pinning-scopes.ts#L15-L23 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | neverResolves | async function neverResolves(
promise: Promise<unknown>,
timeout = 100
): Promise<void> {
const timeoutPromise = new Promise<"timeout">((resolve) =>
setTimeout(() => resolve("timeout"), timeout)
);
const result = await Promise.race([promise, timeoutPromise]);
ok(result === "timeout");
} | // Helper function to test that a promise never resolves | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/breadboard/tests/node/file-system/streams.ts#L21-L31 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | simplifyRefNames | function simplifyRefNames(root: JSONSchema7) {
if (root.definitions === undefined) {
return;
}
const aliases = new Map<string, string>();
let nextId = 0;
for (const [oldName, def] of Object.entries(root.definitions)) {
const newName = `def-${nextId++}`;
aliases.set(DEFINITIONS_PREFIX + oldName, ... | /**
* Replace all $refs with a simple unique name.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build-code/src/generate.ts#L218-L254 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | cleanUpDefinitions | function cleanUpDefinitions(root: JSONSchema7) {
if (root.definitions === undefined) {
return;
}
const usedRefs = new Set<string>();
const visit = (schema: JSONSchema7) => {
if (Array.isArray(schema)) {
for (const item of schema) {
visit(item);
}
} else if (typeof schema === "obj... | /**
* Remove any `definitions` that aren't referenced in the schema, and then if
* there are none left, remove `definitions` all together.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build-code/src/generate.ts#L260-L288 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | bindComponentToKit | function bindComponentToKit<
T extends GenericDiscreteComponent | BoardDefinition,
>(definition: T, kitBinding: KitBinding): T {
return new Proxy(definition, {
apply(target, thisArg, args) {
// The instantiate functions for both discrete and board components have
// an optional final argument called... | /**
* Returns a proxy of a component instance which binds it to a kit.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/internal/kit.ts#L164-L178 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | normalizeBoardInputs | function normalizeBoardInputs(inputs: BoardInit["inputs"]): InputNode[] {
if (Array.isArray(inputs)) {
return inputs;
}
if (isInputNode(inputs)) {
return [inputs];
}
return [inputNode(inputs)];
} | /**
* Normalize the 3 allowed forms for board `inputs` to just 1.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/internal/board/board.ts#L125-L133 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | normalizeBoardOutputs | function normalizeBoardOutputs(outputs: BoardInit["outputs"]): OutputNode[] {
if (Array.isArray(outputs)) {
return outputs;
}
if (isOutputNode(outputs)) {
return [outputs];
}
return [outputNode(outputs)];
} | /**
* Normalize the 3 allowed forms for board `outputs` to just 1.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/internal/board/board.ts#L138-L146 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Loopback.resolve | resolve(value: OutputPortReference<T>): void {
if (this.#value !== undefined) {
throw new Error("Loopback has already been resolved");
}
this.#value = value;
} | /**
* Set the value of this Loopback. Throws if this Loopback has already
* been resolved.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/internal/board/loopback.ts#L63-L68 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | Loopback.value | get value(): OutputPortReference<T> | undefined {
return this.#value;
} | /**
* Get the resolved value, or `undefined` if it has not yet been resolved.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/internal/board/loopback.ts#L73-L75 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | checkInput | function checkInput<T extends GenericSpecialInput>(
input: T,
expectedType: BreadboardType,
expectedExamples?: JsonSerializable[]
): T {
assert.equal(input.type, expectedType);
assert.deepEqual(input.examples, expectedExamples);
return input;
} | /* eslint-disable @typescript-eslint/ban-ts-comment */ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/test/input_test.ts#L32-L40 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | assertType | function assertType<T extends { type: BreadboardType }>(
loopback: T,
expected: BreadboardType
): T {
assert.equal(loopback.type, expected);
return loopback;
} | /* eslint-disable @typescript-eslint/ban-ts-comment */ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/build/src/test/loopback_test.ts#L15-L21 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | inferOriginFromHostname | function inferOriginFromHostname(host?: string) {
if (!host) throw new Error("Unable to infer origin: no host");
return host.startsWith("localhost") ? `http://${host}` : `https://${host}`;
} | /**
* This is a gnarly workaround. When used within Express, the origin
* request header is occasionally undefined, so we have to do something
* to get the origin again.
*
* This code naively uses hostname to infer the origin.
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/connection-server/src/api/grant.ts#L148-L151 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | stripCodeBlock | const stripCodeBlock = (code: string) =>
code.replace(/(?:```(?:js|javascript)?\n+)(.*)(?:\n+```)/gms, "$1"); | // https://regex101.com/r/PeEmEW/1 | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/core-kit/src/nodes/run-javascript.ts#L42-L43 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
breadboard | github_2023 | breadboard-ai | typescript | IDBBackend.initialize | async initialize() {
return openDB<Files>(FILES_DB, 1, {
upgrade(db) {
// 1) Initialize `files` store.
const files = db.createObjectStore("files", {
keyPath: ["graphUrl", "path"],
});
files.createIndex(`byGraph`, `graphUrl`);
// 2) Initialize `blobs` store.
... | /**
*
* @param url -- the URL of the graph associated
*/ | https://github.com/breadboard-ai/breadboard/blob/5edbb3f0175596ddf9df8ff7a804a9627aea8966/packages/data-store/src/file-system/idb-backend.ts#L75-L95 | 5edbb3f0175596ddf9df8ff7a804a9627aea8966 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.