forked from breadboard-ai/breadboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] Pass context to invoke functions (breadboard-ai#1518)
- Loading branch information
Showing
4 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@breadboard-ai/build": patch | ||
--- | ||
|
||
Pass NodeHandlerContext to invoke functions |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import type { NodeHandlerContext } from "@google-labs/breadboard"; | ||
import assert from "node:assert/strict"; | ||
import { test } from "node:test"; | ||
import { defineNodeType } from "../internal/define/define.js"; | ||
|
||
test("invoke receives context", async () => { | ||
const expected: NodeHandlerContext = { | ||
base: new URL("http://example.com/"), | ||
outerGraph: { nodes: [], edges: [] }, | ||
}; | ||
let actual: NodeHandlerContext | undefined; | ||
defineNodeType({ | ||
name: "foo", | ||
inputs: {}, | ||
outputs: {}, | ||
invoke: (_staticInputs, _dynamicInputs, context) => { | ||
actual = context; | ||
return {}; | ||
}, | ||
}).invoke({}, expected); | ||
assert.deepEqual(actual, expected); | ||
}); |