@dcp-ai/create-langchain 2.0.0 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcp-ai/create-langchain",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Scaffold a DCP-AI governed LangChain agent project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,33 +1,32 @@
1
1
  # DCP-AI + LangChain Template
2
2
 
3
- Get your LangChain agent digital citizenship in 3 steps.
3
+ A walkthrough of the DCP flow around a LangChain call.
4
4
 
5
- ## Quick Start
5
+ > **A walkthrough, not a signer.** The keys and signatures in `index.js` are placeholders (`«generated»`, `«sig»`): the template shows the shape of the DCP v2.0 flow, but it generates no keys, signs nothing, and its bundles do not verify. It reads nothing from `.dcp/`. For real keys and signatures, follow [docs/QUICKSTART_LANGCHAIN.md](https://github.com/dcp-ai-protocol/dcp-ai/blob/main/docs/QUICKSTART_LANGCHAIN.md).
6
6
 
7
- 1. Initialize DCP identity:
8
- ```bash
9
- npx @dcp-ai/cli init
10
- ```
7
+ The template pins LangChain.js 0.3 (`langchain` and `@langchain/openai` `^0.3.0`); the guide shows the current LangChain.js v1 API.
8
+
9
+ ## Quick Start
11
10
 
12
- 2. Install dependencies:
11
+ 1. Install dependencies:
13
12
  ```bash
14
13
  npm install
15
14
  ```
16
15
 
17
- 3. Run your agent:
16
+ 2. Run it. With `OPENAI_API_KEY` the template calls the OpenAI API (billed by OpenAI). If the call fails for any reason (no key, network, quota, model), it prints a simulated response and still records `outcome: "success"`, so the audit entry does not show that the call succeeded. Set the key in your environment:
18
17
  ```bash
19
18
  node index.js
20
19
  ```
21
20
 
22
21
  ## What this template does
23
22
 
24
- - Creates a LangChain agent with DCP digital citizenship
25
- - Every action is declared as an Intent
26
- - Every response is audited
27
- - The agent carries a verifiable Citizenship Bundle
23
+ - Wraps a LangChain call in the DCP flow
24
+ - Every action is declared as an Intent; the policy step is a stub that always returns `approve` (risk 50), so the
25
+ escalate and block branches show the flow but are not reached
26
+ - Every response gets an audit entry
27
+ - The agent's Citizenship Bundle carries placeholder signatures
28
28
 
29
29
  ## Files
30
30
 
31
- - `index.js` — LangChain agent with DCP integration
32
- - `.dcp/config.json` — DCP configuration (generated by init)
31
+ - `index.js` — LangChain call with the DCP flow
33
32
  - `package.json` — Dependencies
package/template/index.js CHANGED
@@ -180,9 +180,20 @@ console.log(`📒 Audit entry recorded: ${auditId}`);
180
180
 
181
181
  function canonicalize(obj) {
182
182
  if (obj === null || typeof obj !== "object") return JSON.stringify(obj);
183
- if (Array.isArray(obj)) return "[" + obj.map(canonicalize).join(",") + "]";
184
- const sorted = Object.keys(obj).sort();
185
- return "{" + sorted.map(k => JSON.stringify(k) + ":" + canonicalize(obj[k])).join(",") + "}";
183
+ if (Array.isArray(obj)) {
184
+ // By index: Array#map skips a hole, and join() writes nothing for it or for an undefined.
185
+ // JSON.stringify writes both as null, and so does this.
186
+ const items = [];
187
+ for (let i = 0; i < obj.length; i++) items.push(canonicalize(obj[i]) ?? "null");
188
+ return "[" + items.join(",") + "]";
189
+ }
190
+ // A member with no JSON value (an undefined, a function, a symbol) is left out, as JSON.stringify leaves it out.
191
+ const members = [];
192
+ for (const k of Object.keys(obj).sort()) {
193
+ const v = canonicalize(obj[k]);
194
+ if (v !== undefined) members.push(JSON.stringify(k) + ":" + v);
195
+ }
196
+ return "{" + members.join(",") + "}";
186
197
  }
187
198
 
188
199
  function hashPayload(payload) {