@latenode-connect/sdk-langchain 0.0.0-stage → 0.1.0
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 +18 -0
- package/README.md +98 -2
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +25 -0
- package/dist/index.mjs.map +1 -0
- package/examples/agent.mts +30 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nocode LTD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Latenode Connect for LangChain and LangGraph
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package adapts the Connect SDK's discovery toolkit into native LangChain tools. The same
|
|
4
|
+
objects work with LangChain `createAgent` and LangGraph `ToolNode`.
|
|
5
|
+
|
|
6
|
+
The runtime peer dependency is `@langchain/core` (`^1.4.1`). LangChain and LangGraph
|
|
7
|
+
are optional application choices and are only development/test dependencies here.
|
|
8
|
+
Compatibility is tested with core `1.4.1`, LangChain `1.6.6` and LangGraph `1.7.5`.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add @latenode-connect/sdk @latenode-connect/sdk-langchain @langchain/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { ConnectClient } from '@latenode-connect/sdk';
|
|
16
|
+
import { toLangChainTools } from '@latenode-connect/sdk-langchain';
|
|
17
|
+
import { createAgent } from 'langchain';
|
|
18
|
+
|
|
19
|
+
const connect = new ConnectClient({
|
|
20
|
+
apiKey: process.env.CONNECT_API_KEY!,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Both values come from your application's authenticated, persisted state.
|
|
24
|
+
const endUserId = 'your-customer-id';
|
|
25
|
+
const invocationId = 'persisted-logical-turn-id';
|
|
26
|
+
const toolkit = connect.user(endUserId).agentTools({
|
|
27
|
+
apps: ['google_sheets'],
|
|
28
|
+
});
|
|
29
|
+
const tools = toLangChainTools(toolkit, { invocationId });
|
|
30
|
+
const agent = createAgent({ model: yourChatModel, tools });
|
|
31
|
+
const result = await agent.invoke({
|
|
32
|
+
messages: [{ role: 'user', content: 'Read the requested spreadsheet row.' }],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`yourChatModel` is your configured LangChain chat model. Model credentials, model
|
|
37
|
+
selection, conversations, checkpoints and the agent loop belong to your application.
|
|
38
|
+
Keep the Connect API key on the server. The available tools discover applications and
|
|
39
|
+
actions, describe a pinned action, find permitted connections, load paginated
|
|
40
|
+
options, generate dynamic fields and execute. You do not need to preload the app
|
|
41
|
+
catalog or enumerate individual action IDs.
|
|
42
|
+
|
|
43
|
+
Filters apply throughout the shared toolkit. `apps` accepts stable app slugs from discovery. An omitted filter does not narrow access; `apps: []` hides all
|
|
44
|
+
actions and `connectionIds: []` leaves only actions without user authentication.
|
|
45
|
+
These filters limit the toolkit and do not change the underlying API key's rights.
|
|
46
|
+
|
|
47
|
+
For a custom graph, use the same tools:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { ToolNode } from '@langchain/langgraph/prebuilt';
|
|
51
|
+
|
|
52
|
+
const toolNode = new ToolNode(tools);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The adapter forwards the native tool-call ID and cancellation signal. A direct
|
|
56
|
+
`.invoke()` must receive a complete LangChain ToolCall with its original `id`.
|
|
57
|
+
Missing IDs fail closed; the adapter never generates replacement IDs. Invalid
|
|
58
|
+
arguments may be rejected by LangChain's native schema parser before the shared
|
|
59
|
+
Connect validation runs. Do not log the parser's raw input or entire error object.
|
|
60
|
+
|
|
61
|
+
## Recovery and results
|
|
62
|
+
|
|
63
|
+
Persist `invocationId` and the completed pending model tool calls **before**
|
|
64
|
+
dispatch. After recovery, reuse the same invocation identity, tool-call IDs and
|
|
65
|
+
full arguments. The shared SDK derives a deterministic idempotency key; reusing
|
|
66
|
+
that identity with a changed body is a conflict rather than a new action. New
|
|
67
|
+
logical calls need new IDs. A graph's tracing run ID is not a replacement for this
|
|
68
|
+
application-owned invocation identity.
|
|
69
|
+
|
|
70
|
+
Your application must provide durable checkpointing. `MemorySaver` alone does not
|
|
71
|
+
survive a process restart. The integration test serializes an actual graph's
|
|
72
|
+
pending tool-call state, rebuilds the graph and SDK, and verifies one operation
|
|
73
|
+
and charge after replay. It does not claim that an in-memory checkpointer is durable.
|
|
74
|
+
|
|
75
|
+
Replay retains the backend's 24-hour window and requires the same available
|
|
76
|
+
catalog definition. A retired tool/version has no SDK archive fallback. A failed
|
|
77
|
+
or unknown write result must not be retried automatically with a new identity.
|
|
78
|
+
Provider metadata is not regenerated as a prerequisite for execution replay.
|
|
79
|
+
|
|
80
|
+
Tool contents use the shared `{ ok, data | error }` result. A completed execution
|
|
81
|
+
has its own `status`: transport success does not prove that the action succeeded.
|
|
82
|
+
Large successful results may be explicitly omitted from model context while
|
|
83
|
+
retaining `runId` and bounded file references; retrieve the full result through
|
|
84
|
+
`connect.user(endUserId).runs.get(runId)`.
|
|
85
|
+
|
|
86
|
+
Without a connection ID allowlist, `create_connection_link` returns an expiring URL for an allowed app. The end user opens the URL to authorize their account. Providing any `connectionIds` list disables this tool.
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
Run commands from the repository root:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
pnpm --filter @latenode-connect/sdk-langchain... build
|
|
94
|
+
pnpm --filter @latenode-connect/sdk-langchain typecheck
|
|
95
|
+
pnpm --filter @latenode-connect/sdk-langchain test
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Tests use the real LangChain and LangGraph runtimes with local Connect and model
|
|
99
|
+
fixtures. They make no live provider or LLM requests.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import type { JSONSchema } from '@langchain/core/utils/json_schema';
|
|
3
|
+
import type { AgentResult, AgentToolkit, MetaOutputs, MetaToolName } from '@latenode-connect/sdk';
|
|
4
|
+
export interface LangChainToolOptions {
|
|
5
|
+
/** Persist this logical invocation identity with the application's checkpoint. */
|
|
6
|
+
invocationId: string;
|
|
7
|
+
}
|
|
8
|
+
export type LangChainTools = DynamicStructuredTool<JSONSchema, unknown, unknown, AgentResult<MetaOutputs[MetaToolName]>, unknown, MetaToolName>[];
|
|
9
|
+
/** Adapt the shared Connect toolkit for LangChain agents and LangGraph ToolNode. */
|
|
10
|
+
export declare function toLangChainTools(toolkit: AgentToolkit, options: LangChainToolOptions): LangChainTools;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tool, } from '@langchain/core/tools';
|
|
2
|
+
/** Adapt the shared Connect toolkit for LangChain agents and LangGraph ToolNode. */
|
|
3
|
+
export function toLangChainTools(toolkit, options) {
|
|
4
|
+
const invocationId = options?.invocationId;
|
|
5
|
+
if (typeof invocationId !== 'string' ||
|
|
6
|
+
invocationId.length === 0 ||
|
|
7
|
+
invocationId.length > 512) {
|
|
8
|
+
throw new TypeError('invocationId must be a non-empty string of at most 512 characters');
|
|
9
|
+
}
|
|
10
|
+
return toolkit.definitions.map(definition => tool(async (input, config) => {
|
|
11
|
+
// Full ToolCall invokes populate toolCall; ToolNode additionally supplies toolCallId.
|
|
12
|
+
const runtime = config;
|
|
13
|
+
const toolCallId = config.toolCall?.id ?? runtime.toolCallId ?? '';
|
|
14
|
+
return toolkit.call(definition.name, input, {
|
|
15
|
+
invocationId,
|
|
16
|
+
toolCallId,
|
|
17
|
+
...(config.signal === undefined ? {} : { signal: config.signal }),
|
|
18
|
+
});
|
|
19
|
+
}, {
|
|
20
|
+
name: definition.name,
|
|
21
|
+
description: definition.description,
|
|
22
|
+
schema: definition.inputSchema,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,GAIL,MAAM,uBAAuB,CAAC;AAwB/B,oFAAoF;AACpF,MAAM,UAAU,gBAAgB,CAC9B,OAAqB,EACrB,OAA6B;IAE7B,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC;IAC3C,IACE,OAAO,YAAY,KAAK,QAAQ;QAChC,YAAY,CAAC,MAAM,KAAK,CAAC;QACzB,YAAY,CAAC,MAAM,GAAG,GAAG,EACzB,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,mEAAmE,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAC1C,IAAI,CACF,KAAK,EAAE,KAAK,EAAE,MAA0B,EAAE,EAAE;QAC1C,sFAAsF;QACtF,MAAM,OAAO,GAAG,MAC0B,CAAC;QAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;QACnE,OAAO,OAAO,CAAC,IAAI,CACjB,UAAU,CAAC,IAAI,EACf,KAAiC,EACjC;YACE,YAAY;YACZ,UAAU;YACV,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;SAClE,CACF,CAAC;IACJ,CAAC,EACD;QACE,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,MAAM,EAAE,UAAU,CAAC,WAAyB;KAC7C,CACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createAgent } from 'langchain';
|
|
2
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
import { ToolNode } from '@langchain/langgraph/prebuilt';
|
|
4
|
+
import type { ConnectClient } from '@latenode-connect/sdk';
|
|
5
|
+
import { toLangChainTools } from '@latenode-connect/sdk-langchain';
|
|
6
|
+
|
|
7
|
+
export interface AgentOptions {
|
|
8
|
+
client: ConnectClient;
|
|
9
|
+
model: BaseChatModel;
|
|
10
|
+
endUserId: string;
|
|
11
|
+
connectionId: string;
|
|
12
|
+
/** Persist this logical turn identity with the pending model calls. */
|
|
13
|
+
invocationId: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function tools(options: AgentOptions) {
|
|
17
|
+
const toolkit = options.client.user(options.endUserId).agentTools({
|
|
18
|
+
apps: ['google_sheets'],
|
|
19
|
+
connectionIds: [options.connectionId],
|
|
20
|
+
});
|
|
21
|
+
return toLangChainTools(toolkit, { invocationId: options.invocationId });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function spreadsheetAgent(options: AgentOptions) {
|
|
25
|
+
return createAgent({ model: options.model, tools: tools(options) });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function spreadsheetToolNode(options: AgentOptions) {
|
|
29
|
+
return new ToolNode(tools(options));
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@latenode-connect/sdk-langchain",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.mts",
|
|
8
|
+
"import": "./dist/index.mjs"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"examples"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@latenode-connect/sdk": "0.1.0"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@langchain/core": "^1.4.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@langchain/core": "1.4.1",
|
|
23
|
+
"@langchain/langgraph": "1.7.5",
|
|
24
|
+
"@langchain/openai": "1.8.4",
|
|
25
|
+
"langchain": "1.6.6",
|
|
26
|
+
"tsx": "4.23.15",
|
|
27
|
+
"typescript": "5.8.3"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/latenode-com/latenode-connect-sdk.git",
|
|
33
|
+
"directory": "connect/sdk-langchain"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"registry": "https://registry.npmjs.org/"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p test/types/tsconfig.json",
|
|
42
|
+
"test": "node --import tsx --test test/*.test.mjs"
|
|
43
|
+
}
|
|
6
44
|
}
|