Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 77 additions & 26 deletions examples/axios/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/axios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@sapiom/axios": "latest",
"axios": "^1.7.9",
"axios": "^1.21.0",
"dotenv": "^16.4.5"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions examples/langchain-classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*
* Run: npm start
*/
import "./node18-crypto";

import { SapiomClient } from "@sapiom/langchain-classic";
import dotenv from "dotenv";

Expand Down
4 changes: 4 additions & 0 deletions examples/langchain-classic/node18-crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// langsmith 0.6+ reads the global `crypto`, which Node 18 does not define.
import { webcrypto } from "node:crypto";

globalThis.crypto ??= webcrypto as typeof globalThis.crypto;
57 changes: 57 additions & 0 deletions examples/langchain-classic/node18.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { once } from "node:events";
import { createServer } from "node:http";
import { test } from "node:test";
import { promisify } from "node:util";

const anthropicReply = JSON.stringify({
id: "msg_test",
type: "message",
role: "assistant",
model: "claude-haiku-4-5",
content: [{ type: "text", text: "ok" }],
stop_reason: "end_turn",
stop_sequence: null,
usage: { input_tokens: 1, output_tokens: 1 },
});

test("npm start completes without the global crypto, as on Node 18", async () => {
// Answers the model calls. Sapiom calls get a 404, and the SDK then runs
// the agent without tracking.
const server = createServer((req, res) => {
req.resume();
if (req.url !== "/v1/messages") return res.writeHead(404).end();
res.writeHead(200, { "content-type": "application/json" });
res.end(anthropicReply);
}).listen(0, "127.0.0.1");
await once(server, "listening");
const url = `http://127.0.0.1:${server.address().port}`;

try {
const { stdout } = await promisify(execFile)("npm", ["start"], {
cwd: new URL(".", import.meta.url),
timeout: 60_000,
env: {
// Drops any LangSmith tracing set in the caller's shell, so every
// request stays on the local stub.
...Object.fromEntries(
Object.entries(process.env).filter(
([key]) => !/^LANG(CHAIN|SMITH)_/.test(key),
),
),
// Node 20+ defines the global `crypto`, so delete it before anything
// loads. On Node 18 this changes nothing.
NODE_OPTIONS:
"--import data:text/javascript,delete%20globalThis.crypto",
SAPIOM_API_KEY: "test",
SAPIOM_API_URL: url,
ANTHROPIC_API_KEY: "test",
ANTHROPIC_BASE_URL: url,
},
});
assert.match(stdout, /Demo Complete/);
} finally {
server.close();
}
});
Loading
Loading