@zmdb/ai-langchain 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ @zmdb/ai-langchain is free software licensed under the GNU General Public
5
+ License, version 3 or (at your option) any later version.
6
+
7
+ The complete license text is published by the Free Software Foundation at:
8
+ https://www.gnu.org/licenses/gpl-3.0.txt
9
+
10
+ SPDX-License-Identifier: GPL-3.0-or-later
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @zmdb/ai-langchain
2
+
3
+ `@zmdb/ai-langchain` adapts provider-neutral zmdb tool documents to the structural fields accepted by LangChain's `DynamicStructuredTool`. It passes the generated JSON Schema directly to LangChain,
4
+ runs a caller-owned validator before the handler, and serializes tool results without introducing Zod or another runtime schema producer.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ yarn add @zmdb/ai@1.0.0-beta.1 @zmdb/ai-langchain@1.0.0-beta.1 @langchain/core@^1.2.9
10
+ ```
11
+
12
+ > **Prerelease** (`1.0.0-beta.1`). Requires **Node.js 26+** and is **ESM-only**. `@langchain/core` is an optional peer used by applications that construct a real LangChain tool.
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { DynamicStructuredTool } from '@langchain/core/tools';
18
+ import { langchainTool } from '@zmdb/ai-langchain';
19
+
20
+ const createUser = new DynamicStructuredTool(
21
+ langchainTool('create_user', users, {
22
+ description: 'Create a user',
23
+ validate: input => assert<CreateDTO<User>>(input),
24
+ execute: dto => userRepo.create(dto),
25
+ }),
26
+ );
27
+ ```
28
+
29
+ The validator belongs in application code so the AOT transform can resolve its concrete type. The adapter passes zmdb's JSON Schema document through byte-for-byte; do not convert it through Zod.
30
+
31
+ The shipped adapter is physically owned by this package and depends at runtime only on `@zmdb/ai`; schema-core has no LangChain compatibility export.
32
+
33
+ ## Documentation
34
+
35
+ Full docs: **https://ambasta.github.io/zmdb/docs/llm-langchain.html**
36
+
37
+ ## License
38
+
39
+ GNU General Public License v3.0 or later (GPL-3.0-or-later) — see [LICENSE](./LICENSE).
@@ -0,0 +1,18 @@
1
+ import { type ToolSchema, type ToolSpec } from '@zmdb/ai';
2
+ import { type ToolAdapterOptions } from '@zmdb/ai/tool-runtime';
3
+ /**
4
+ * The fields accepted by `new DynamicStructuredTool(...)`.
5
+ *
6
+ * Kept structural so this optional subpath does not import LangChain or its
7
+ * runtime schema dependencies. The real-package consumer fixture checks this
8
+ * shape against the tested peer version.
9
+ */
10
+ export interface LangChainToolFields {
11
+ readonly name: string;
12
+ readonly description: string;
13
+ readonly schema: ToolSpec['parameters'];
14
+ readonly func: (input: unknown) => Promise<string>;
15
+ }
16
+ export declare function langchainTool<T, Output>(name: string, schema: ToolSchema, options: ToolAdapterOptions<T, Output>): LangChainToolFields;
17
+ export type { ToolAdapterOptions } from '@zmdb/ai/tool-runtime';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAA2C,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEzG;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACpD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,GACrC,mBAAmB,CASrB;AAED,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { toolFromSchema } from '@zmdb/ai';
2
+ import { executeToolAdapter, serialiseToolResult } from '@zmdb/ai/tool-runtime';
3
+ export function langchainTool(name, schema, options) {
4
+ return {
5
+ name,
6
+ description: options.description,
7
+ schema: toolFromSchema(name, schema).parameters,
8
+ async func(input) {
9
+ return serialiseToolResult(await executeToolAdapter(name, input, options));
10
+ },
11
+ };
12
+ }
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAkC,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAA2B,MAAM,uBAAuB,CAAC;AAgBzG,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,MAAkB,EAClB,OAAsC;IAEtC,OAAO;QACL,IAAI;QACJ,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,MAAM,EAAE,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU;QAC/C,KAAK,CAAC,IAAI,CAAC,KAAK;YACd,OAAO,mBAAmB,CAAC,MAAM,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@zmdb/ai-langchain",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Optional LangChain structured-tool adapter for provider-neutral zmdb AI tool documents.",
5
+ "keywords": [
6
+ "ai",
7
+ "json-schema",
8
+ "langchain",
9
+ "llm",
10
+ "typescript",
11
+ "zmdb"
12
+ ],
13
+ "homepage": "https://github.com/ambasta/zmdb#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/ambasta/zmdb/issues"
16
+ },
17
+ "license": "GPL-3.0-or-later",
18
+ "author": "zmdb contributors",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ambasta/zmdb.git",
22
+ "directory": "packages/ai-langchain"
23
+ },
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ }
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "tag": "beta"
35
+ },
36
+ "scripts": {
37
+ "build": "node ../../scripts/build-package.mjs",
38
+ "test": "vitest run"
39
+ },
40
+ "dependencies": {
41
+ "@zmdb/ai": "1.0.0-beta.1"
42
+ },
43
+ "peerDependencies": {
44
+ "@langchain/core": "^1.2.9"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@langchain/core": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "engines": {
52
+ "node": ">=26"
53
+ },
54
+ "main": "./dist/index.js",
55
+ "types": "./dist/index.d.ts"
56
+ }
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { toolFromSchema, type ToolSchema, type ToolSpec } from '@zmdb/ai';
2
+ import { executeToolAdapter, serialiseToolResult, type ToolAdapterOptions } from '@zmdb/ai/tool-runtime';
3
+
4
+ /**
5
+ * The fields accepted by `new DynamicStructuredTool(...)`.
6
+ *
7
+ * Kept structural so this optional subpath does not import LangChain or its
8
+ * runtime schema dependencies. The real-package consumer fixture checks this
9
+ * shape against the tested peer version.
10
+ */
11
+ export interface LangChainToolFields {
12
+ readonly name: string;
13
+ readonly description: string;
14
+ readonly schema: ToolSpec['parameters'];
15
+ readonly func: (input: unknown) => Promise<string>;
16
+ }
17
+
18
+ export function langchainTool<T, Output>(
19
+ name: string,
20
+ schema: ToolSchema,
21
+ options: ToolAdapterOptions<T, Output>,
22
+ ): LangChainToolFields {
23
+ return {
24
+ name,
25
+ description: options.description,
26
+ schema: toolFromSchema(name, schema).parameters,
27
+ async func(input) {
28
+ return serialiseToolResult(await executeToolAdapter(name, input, options));
29
+ },
30
+ };
31
+ }
32
+
33
+ export type { ToolAdapterOptions } from '@zmdb/ai/tool-runtime';