@nexart/ai-execution 0.9.0 → 0.10.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/README.md +167 -3
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +95 -0
- package/dist/index.mjs.map +1 -1
- package/dist/langchain.cjs +480 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +185 -0
- package/dist/langchain.d.ts +185 -0
- package/dist/langchain.mjs +444 -0
- package/dist/langchain.mjs.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { c as CertifyDecisionParams, e as AttestOptions, b as CerAiExecutionBundle, h as AttestationReceipt } from './types-C5t12OK8.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @nexart/ai-execution — LangChain Integration
|
|
5
|
+
*
|
|
6
|
+
* Provides a minimal helper surface for certifying the final input and
|
|
7
|
+
* final output of a LangChain run as a Certified Execution Record (CER).
|
|
8
|
+
*
|
|
9
|
+
* Two helpers:
|
|
10
|
+
*
|
|
11
|
+
* createLangChainCer(input)
|
|
12
|
+
* Always synchronous. Local CER creation only — no network required.
|
|
13
|
+
* Returns LangChainCerResult.
|
|
14
|
+
*
|
|
15
|
+
* certifyLangChainRun(input)
|
|
16
|
+
* • Without nodeUrl/apiKey → identical to createLangChainCer (sync).
|
|
17
|
+
* • With nodeUrl + apiKey → sends the sealed bundle to a NexArt node
|
|
18
|
+
* for attestation via the existing certifyAndAttestDecision() path.
|
|
19
|
+
* Returns Promise<LangChainAttestedResult>.
|
|
20
|
+
*
|
|
21
|
+
* Both helpers produce bundles that are fully protocol-aligned and pass
|
|
22
|
+
* verifyCer() / verifyAiCerBundleDetailed(). No LangChain-specific schema.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Injectable attestation function type.
|
|
27
|
+
* Defaults to the real certifyAndAttestDecision(); override in tests to avoid
|
|
28
|
+
* hitting the network. Follows the same injectable pattern as
|
|
29
|
+
* certifyAndAttestRun()'s attestStep option.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
type AttestDecisionFn = (params: CertifyDecisionParams, options: AttestOptions) => Promise<{
|
|
34
|
+
bundle: CerAiExecutionBundle;
|
|
35
|
+
receipt: AttestationReceipt;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Normalized input for LangChain CER helpers.
|
|
39
|
+
*
|
|
40
|
+
* Accepts the practical final-run shape produced by LangChain chains,
|
|
41
|
+
* agents, and runnables without requiring any LangChain import.
|
|
42
|
+
*/
|
|
43
|
+
interface LangChainCertificationInput {
|
|
44
|
+
/** Optional run ID — a UUID is generated if omitted. */
|
|
45
|
+
executionId?: string;
|
|
46
|
+
/** AI provider name (e.g. "openai", "anthropic", "google"). */
|
|
47
|
+
provider: string;
|
|
48
|
+
/** Model name (e.g. "gpt-4o-mini", "claude-3-haiku-20240307"). */
|
|
49
|
+
model: string;
|
|
50
|
+
/** Model version string — null if unknown. */
|
|
51
|
+
modelVersion?: string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Final run input. Accepts any shape produced by LangChain:
|
|
54
|
+
* { messages: [...] }, a plain string, HumanMessage array, etc.
|
|
55
|
+
* Arrays are wrapped as { items: [...] }.
|
|
56
|
+
*/
|
|
57
|
+
input: unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Final run output. Accepts any shape produced by LangChain:
|
|
60
|
+
* AIMessage, { text: "..." }, a plain string, etc.
|
|
61
|
+
* Arrays are wrapped as { items: [...] }.
|
|
62
|
+
*/
|
|
63
|
+
output: unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Optional metadata from the LangChain run. Recognized keys:
|
|
66
|
+
* - prompt?: string — used as the CER prompt field
|
|
67
|
+
* - appId?: string — included in the CER snapshot
|
|
68
|
+
* - runId?: string
|
|
69
|
+
* - workflowId?: string
|
|
70
|
+
* - conversationId?: string
|
|
71
|
+
* All other keys are preserved in the CER bundle's meta.tags.
|
|
72
|
+
*/
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Optional override for the AI inference timestamp.
|
|
76
|
+
* Defaults to current time if omitted.
|
|
77
|
+
*/
|
|
78
|
+
timestamp?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Optional override for the CER bundle creation timestamp.
|
|
81
|
+
* Pin this to a fixed value to get a deterministic certificateHash.
|
|
82
|
+
* Defaults to current time if omitted.
|
|
83
|
+
*/
|
|
84
|
+
createdAt?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Optional model inference parameters.
|
|
87
|
+
* Fields not provided default to 0 / null (protocol-safe).
|
|
88
|
+
* These values are included in the certificateHash.
|
|
89
|
+
*/
|
|
90
|
+
parameters?: {
|
|
91
|
+
temperature?: number;
|
|
92
|
+
maxTokens?: number;
|
|
93
|
+
topP?: number | null;
|
|
94
|
+
seed?: number | null;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* NexArt node URL for attestation (e.g. "https://node.nexart.io").
|
|
98
|
+
* When set together with apiKey, certifyLangChainRun() will call the
|
|
99
|
+
* node to produce an AttestationReceipt alongside the local CER.
|
|
100
|
+
* Has no effect on createLangChainCer().
|
|
101
|
+
*/
|
|
102
|
+
nodeUrl?: string;
|
|
103
|
+
/**
|
|
104
|
+
* NexArt API key for node attestation.
|
|
105
|
+
* Required when nodeUrl is set.
|
|
106
|
+
*/
|
|
107
|
+
apiKey?: string;
|
|
108
|
+
}
|
|
109
|
+
/** Result returned by createLangChainCer() and certifyLangChainRun() in local mode. */
|
|
110
|
+
interface LangChainCerResult {
|
|
111
|
+
/** The sealed CER bundle. Pass to verifyCer() to verify integrity. */
|
|
112
|
+
bundle: CerAiExecutionBundle;
|
|
113
|
+
/** SHA-256 certificate hash — the tamper-evident fingerprint of this record. */
|
|
114
|
+
certificateHash: string;
|
|
115
|
+
/** The executionId embedded in the CER snapshot. */
|
|
116
|
+
executionId: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Result returned by certifyLangChainRun() when nodeUrl + apiKey are provided.
|
|
120
|
+
* Extends LangChainCerResult with the receipt from the attestation node.
|
|
121
|
+
*/
|
|
122
|
+
interface LangChainAttestedResult extends LangChainCerResult {
|
|
123
|
+
/** The attestation receipt from the NexArt node. */
|
|
124
|
+
receipt: AttestationReceipt;
|
|
125
|
+
/** Always true — distinguishes an attested result from a local result. */
|
|
126
|
+
attested: true;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create a CER bundle locally from a LangChain final run.
|
|
130
|
+
*
|
|
131
|
+
* Always synchronous — no network required. The resulting bundle is fully
|
|
132
|
+
* aligned with the CER Protocol and verifies via verifyCer() /
|
|
133
|
+
* verifyAiCerBundleDetailed().
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const { bundle, certificateHash } = createLangChainCer({
|
|
138
|
+
* provider: 'openai',
|
|
139
|
+
* model: 'gpt-4o-mini',
|
|
140
|
+
* input: { messages: [{ role: 'user', content: 'What is 2+2?' }] },
|
|
141
|
+
* output: { text: '4' },
|
|
142
|
+
* createdAt: new Date().toISOString(),
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare function createLangChainCer(input: LangChainCertificationInput): LangChainCerResult;
|
|
147
|
+
/**
|
|
148
|
+
* Attested mode: call the NexArt node to produce an AttestationReceipt
|
|
149
|
+
* alongside the local CER. Requires nodeUrl + apiKey on the input.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const { bundle, certificateHash, receipt } = await certifyLangChainRun({
|
|
154
|
+
* provider: 'openai',
|
|
155
|
+
* model: 'gpt-4o-mini',
|
|
156
|
+
* input: { messages: [...] },
|
|
157
|
+
* output: { text: '...' },
|
|
158
|
+
* nodeUrl: 'https://node.nexart.io',
|
|
159
|
+
* apiKey: 'nxa_...',
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
declare function certifyLangChainRun(input: LangChainCertificationInput & {
|
|
164
|
+
nodeUrl: string;
|
|
165
|
+
apiKey: string;
|
|
166
|
+
}, _options?: {
|
|
167
|
+
_attestFn?: AttestDecisionFn;
|
|
168
|
+
}): Promise<LangChainAttestedResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Local mode: identical to createLangChainCer() — synchronous, no network.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const { bundle, certificateHash } = certifyLangChainRun({
|
|
175
|
+
* provider: 'openai',
|
|
176
|
+
* model: 'gpt-4o-mini',
|
|
177
|
+
* input: { messages: [...] },
|
|
178
|
+
* output: { text: '...' },
|
|
179
|
+
* createdAt: new Date().toISOString(),
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function certifyLangChainRun(input: LangChainCertificationInput): LangChainCerResult;
|
|
184
|
+
|
|
185
|
+
export { type AttestDecisionFn, type LangChainAttestedResult, type LangChainCerResult, type LangChainCertificationInput, certifyLangChainRun, createLangChainCer };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { c as CertifyDecisionParams, e as AttestOptions, b as CerAiExecutionBundle, h as AttestationReceipt } from './types-C5t12OK8.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @nexart/ai-execution — LangChain Integration
|
|
5
|
+
*
|
|
6
|
+
* Provides a minimal helper surface for certifying the final input and
|
|
7
|
+
* final output of a LangChain run as a Certified Execution Record (CER).
|
|
8
|
+
*
|
|
9
|
+
* Two helpers:
|
|
10
|
+
*
|
|
11
|
+
* createLangChainCer(input)
|
|
12
|
+
* Always synchronous. Local CER creation only — no network required.
|
|
13
|
+
* Returns LangChainCerResult.
|
|
14
|
+
*
|
|
15
|
+
* certifyLangChainRun(input)
|
|
16
|
+
* • Without nodeUrl/apiKey → identical to createLangChainCer (sync).
|
|
17
|
+
* • With nodeUrl + apiKey → sends the sealed bundle to a NexArt node
|
|
18
|
+
* for attestation via the existing certifyAndAttestDecision() path.
|
|
19
|
+
* Returns Promise<LangChainAttestedResult>.
|
|
20
|
+
*
|
|
21
|
+
* Both helpers produce bundles that are fully protocol-aligned and pass
|
|
22
|
+
* verifyCer() / verifyAiCerBundleDetailed(). No LangChain-specific schema.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Injectable attestation function type.
|
|
27
|
+
* Defaults to the real certifyAndAttestDecision(); override in tests to avoid
|
|
28
|
+
* hitting the network. Follows the same injectable pattern as
|
|
29
|
+
* certifyAndAttestRun()'s attestStep option.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
type AttestDecisionFn = (params: CertifyDecisionParams, options: AttestOptions) => Promise<{
|
|
34
|
+
bundle: CerAiExecutionBundle;
|
|
35
|
+
receipt: AttestationReceipt;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Normalized input for LangChain CER helpers.
|
|
39
|
+
*
|
|
40
|
+
* Accepts the practical final-run shape produced by LangChain chains,
|
|
41
|
+
* agents, and runnables without requiring any LangChain import.
|
|
42
|
+
*/
|
|
43
|
+
interface LangChainCertificationInput {
|
|
44
|
+
/** Optional run ID — a UUID is generated if omitted. */
|
|
45
|
+
executionId?: string;
|
|
46
|
+
/** AI provider name (e.g. "openai", "anthropic", "google"). */
|
|
47
|
+
provider: string;
|
|
48
|
+
/** Model name (e.g. "gpt-4o-mini", "claude-3-haiku-20240307"). */
|
|
49
|
+
model: string;
|
|
50
|
+
/** Model version string — null if unknown. */
|
|
51
|
+
modelVersion?: string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Final run input. Accepts any shape produced by LangChain:
|
|
54
|
+
* { messages: [...] }, a plain string, HumanMessage array, etc.
|
|
55
|
+
* Arrays are wrapped as { items: [...] }.
|
|
56
|
+
*/
|
|
57
|
+
input: unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Final run output. Accepts any shape produced by LangChain:
|
|
60
|
+
* AIMessage, { text: "..." }, a plain string, etc.
|
|
61
|
+
* Arrays are wrapped as { items: [...] }.
|
|
62
|
+
*/
|
|
63
|
+
output: unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Optional metadata from the LangChain run. Recognized keys:
|
|
66
|
+
* - prompt?: string — used as the CER prompt field
|
|
67
|
+
* - appId?: string — included in the CER snapshot
|
|
68
|
+
* - runId?: string
|
|
69
|
+
* - workflowId?: string
|
|
70
|
+
* - conversationId?: string
|
|
71
|
+
* All other keys are preserved in the CER bundle's meta.tags.
|
|
72
|
+
*/
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Optional override for the AI inference timestamp.
|
|
76
|
+
* Defaults to current time if omitted.
|
|
77
|
+
*/
|
|
78
|
+
timestamp?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Optional override for the CER bundle creation timestamp.
|
|
81
|
+
* Pin this to a fixed value to get a deterministic certificateHash.
|
|
82
|
+
* Defaults to current time if omitted.
|
|
83
|
+
*/
|
|
84
|
+
createdAt?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Optional model inference parameters.
|
|
87
|
+
* Fields not provided default to 0 / null (protocol-safe).
|
|
88
|
+
* These values are included in the certificateHash.
|
|
89
|
+
*/
|
|
90
|
+
parameters?: {
|
|
91
|
+
temperature?: number;
|
|
92
|
+
maxTokens?: number;
|
|
93
|
+
topP?: number | null;
|
|
94
|
+
seed?: number | null;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* NexArt node URL for attestation (e.g. "https://node.nexart.io").
|
|
98
|
+
* When set together with apiKey, certifyLangChainRun() will call the
|
|
99
|
+
* node to produce an AttestationReceipt alongside the local CER.
|
|
100
|
+
* Has no effect on createLangChainCer().
|
|
101
|
+
*/
|
|
102
|
+
nodeUrl?: string;
|
|
103
|
+
/**
|
|
104
|
+
* NexArt API key for node attestation.
|
|
105
|
+
* Required when nodeUrl is set.
|
|
106
|
+
*/
|
|
107
|
+
apiKey?: string;
|
|
108
|
+
}
|
|
109
|
+
/** Result returned by createLangChainCer() and certifyLangChainRun() in local mode. */
|
|
110
|
+
interface LangChainCerResult {
|
|
111
|
+
/** The sealed CER bundle. Pass to verifyCer() to verify integrity. */
|
|
112
|
+
bundle: CerAiExecutionBundle;
|
|
113
|
+
/** SHA-256 certificate hash — the tamper-evident fingerprint of this record. */
|
|
114
|
+
certificateHash: string;
|
|
115
|
+
/** The executionId embedded in the CER snapshot. */
|
|
116
|
+
executionId: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Result returned by certifyLangChainRun() when nodeUrl + apiKey are provided.
|
|
120
|
+
* Extends LangChainCerResult with the receipt from the attestation node.
|
|
121
|
+
*/
|
|
122
|
+
interface LangChainAttestedResult extends LangChainCerResult {
|
|
123
|
+
/** The attestation receipt from the NexArt node. */
|
|
124
|
+
receipt: AttestationReceipt;
|
|
125
|
+
/** Always true — distinguishes an attested result from a local result. */
|
|
126
|
+
attested: true;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create a CER bundle locally from a LangChain final run.
|
|
130
|
+
*
|
|
131
|
+
* Always synchronous — no network required. The resulting bundle is fully
|
|
132
|
+
* aligned with the CER Protocol and verifies via verifyCer() /
|
|
133
|
+
* verifyAiCerBundleDetailed().
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const { bundle, certificateHash } = createLangChainCer({
|
|
138
|
+
* provider: 'openai',
|
|
139
|
+
* model: 'gpt-4o-mini',
|
|
140
|
+
* input: { messages: [{ role: 'user', content: 'What is 2+2?' }] },
|
|
141
|
+
* output: { text: '4' },
|
|
142
|
+
* createdAt: new Date().toISOString(),
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare function createLangChainCer(input: LangChainCertificationInput): LangChainCerResult;
|
|
147
|
+
/**
|
|
148
|
+
* Attested mode: call the NexArt node to produce an AttestationReceipt
|
|
149
|
+
* alongside the local CER. Requires nodeUrl + apiKey on the input.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const { bundle, certificateHash, receipt } = await certifyLangChainRun({
|
|
154
|
+
* provider: 'openai',
|
|
155
|
+
* model: 'gpt-4o-mini',
|
|
156
|
+
* input: { messages: [...] },
|
|
157
|
+
* output: { text: '...' },
|
|
158
|
+
* nodeUrl: 'https://node.nexart.io',
|
|
159
|
+
* apiKey: 'nxa_...',
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
declare function certifyLangChainRun(input: LangChainCertificationInput & {
|
|
164
|
+
nodeUrl: string;
|
|
165
|
+
apiKey: string;
|
|
166
|
+
}, _options?: {
|
|
167
|
+
_attestFn?: AttestDecisionFn;
|
|
168
|
+
}): Promise<LangChainAttestedResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Local mode: identical to createLangChainCer() — synchronous, no network.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const { bundle, certificateHash } = certifyLangChainRun({
|
|
175
|
+
* provider: 'openai',
|
|
176
|
+
* model: 'gpt-4o-mini',
|
|
177
|
+
* input: { messages: [...] },
|
|
178
|
+
* output: { text: '...' },
|
|
179
|
+
* createdAt: new Date().toISOString(),
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function certifyLangChainRun(input: LangChainCertificationInput): LangChainCerResult;
|
|
184
|
+
|
|
185
|
+
export { type AttestDecisionFn, type LangChainAttestedResult, type LangChainCerResult, type LangChainCertificationInput, certifyLangChainRun, createLangChainCer };
|