managed-deepagents 0.6.2-dev.11 → 0.6.2-dev.13
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/dist/agent-auth.d.ts +104 -0
- package/dist/agent-auth.d.ts.map +1 -0
- package/dist/agent-auth.js +224 -0
- package/dist/agent-auth.js.map +1 -0
- package/dist/connectors/mcp/index.d.ts +29 -89
- package/dist/connectors/mcp/index.d.ts.map +1 -1
- package/dist/connectors/mcp/index.js +228 -50
- package/dist/connectors/mcp/index.js.map +1 -1
- package/dist/connectors/mcp/schema.d.ts +12 -0
- package/dist/connectors/mcp/schema.d.ts.map +1 -0
- package/dist/connectors/mcp/schema.js +55 -0
- package/dist/connectors/mcp/schema.js.map +1 -0
- package/dist/connectors/mcp/types.d.ts +62 -0
- package/dist/connectors/mcp/types.d.ts.map +1 -0
- package/dist/connectors/mcp/types.js +2 -0
- package/dist/connectors/mcp/types.js.map +1 -0
- package/dist/connectors/tool-selection.d.ts +9 -18
- package/dist/connectors/tool-selection.d.ts.map +1 -1
- package/dist/connectors/tool-selection.js +32 -58
- package/dist/connectors/tool-selection.js.map +1 -1
- package/dist/credential-gate.d.ts +39 -0
- package/dist/credential-gate.d.ts.map +1 -0
- package/dist/credential-gate.js +209 -0
- package/dist/credential-gate.js.map +1 -0
- package/dist/credentials.d.ts +88 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +246 -0
- package/dist/credentials.js.map +1 -0
- package/dist/identity/index.d.ts +1 -1
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/types.d.ts +79 -5
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/auth.d.ts +9 -4
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js.map +1 -1
- package/dist/runtime/http.d.ts +1 -1
- package/dist/runtime/http.d.ts.map +1 -1
- package/dist/runtime/http.js.map +1 -1
- package/dist/runtime/identity-runtime.d.ts +65 -5
- package/dist/runtime/identity-runtime.d.ts.map +1 -1
- package/dist/runtime/identity-runtime.js +148 -0
- package/dist/runtime/identity-runtime.js.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +12 -7
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/managed-middleware.d.ts +2 -2
- package/dist/runtime/managed-middleware.js +6 -6
- package/dist/runtime/managed-tools.d.ts +19 -15
- package/dist/runtime/managed-tools.d.ts.map +1 -1
- package/dist/runtime/managed-tools.js +14 -13
- package/dist/runtime/managed-tools.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -2
- package/package.json +7 -7
- package/dist/connectors/mcp/load.d.ts +0 -12
- package/dist/connectors/mcp/load.d.ts.map +0 -1
- package/dist/connectors/mcp/load.js +0 -122
- package/dist/connectors/mcp/load.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-selection.js","sourceRoot":"","sources":["../../src/connectors/tool-selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-selection.js","sourceRoot":"","sources":["../../src/connectors/tool-selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB,4DAA4D;AAC5D,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC;KACxC,KAAK,CACJ,CAAC;KACE,MAAM,CAAC,sCAAsC,CAAC;KAC9C,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAChC,sCAAsC,CACvC,CACJ;KACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACb,MAAM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GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CACvE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,wBAAwB,CAC/B,OAAe,EACf,SAAsB,EACtB,YAAuB,EACvB,YAAuB;IAEvB,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,cAAc,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC;IACpE,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,8BAA8B,KAAK,IAAI;QAC/C,oBAAoB,cAAc,GAAG,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-run gate for declarations that need a user-owned credential.
|
|
3
|
+
*
|
|
4
|
+
* Before the first model turn the gate reads the caller's OAuth grants from
|
|
5
|
+
* Agent Auth. Missing grants raise one LangGraph interrupt listing connect
|
|
6
|
+
* URLs; the tools a grant unlocks are loaded on first use and cached per
|
|
7
|
+
* caller.
|
|
8
|
+
*/
|
|
9
|
+
import { createMiddleware } from "langchain";
|
|
10
|
+
import { type CredentialReference } from "./credentials.js";
|
|
11
|
+
export declare const CREDENTIAL_GATE_MIDDLEWARE_NAME = "mda-credential-gate";
|
|
12
|
+
export interface PendingCredential {
|
|
13
|
+
slug: string;
|
|
14
|
+
connect_url: string;
|
|
15
|
+
auth_id: string;
|
|
16
|
+
}
|
|
17
|
+
/** Interrupt payload when the caller has not granted one or more credentials. */
|
|
18
|
+
export interface CredentialAuthorizationRequiredInterrupt {
|
|
19
|
+
type: "credential_authorization_required";
|
|
20
|
+
message: string;
|
|
21
|
+
credentials: PendingCredential[];
|
|
22
|
+
}
|
|
23
|
+
/** Tools a declaration contributes for one caller, plus their transport. */
|
|
24
|
+
export interface LoadedCredentialTools {
|
|
25
|
+
tools: unknown[];
|
|
26
|
+
close: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** A declaration whose tools are unlocked by user-owned credentials. */
|
|
29
|
+
export interface CredentialConsumer {
|
|
30
|
+
/** The declaration itself, used to key the per-caller tool cache. */
|
|
31
|
+
declaration: object;
|
|
32
|
+
/** User-owned credential references the declaration needs. */
|
|
33
|
+
credentials: readonly CredentialReference[];
|
|
34
|
+
load: (accessTokens: ReadonlyMap<string, string>) => Promise<LoadedCredentialTools>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createCredentialGateMiddleware(consumers: readonly CredentialConsumer[]): ReturnType<typeof createMiddleware> | undefined;
|
|
37
|
+
/** Drop every cached caller entry and close its transports. Test-only. */
|
|
38
|
+
export declare function clearCredentialToolCacheForTests(): Promise<void>;
|
|
39
|
+
//# sourceMappingURL=credential-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-gate.d.ts","sourceRoot":"","sources":["../src/credential-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAQ7C,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAY1B,eAAO,MAAM,+BAA+B,wBAAwB,CAAC;AAUrE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,iFAAiF;AACjF,MAAM,WAAW,wCAAwC;IACvD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,iBAAiB,EAAE,CAAC;CAClC;AAED,4EAA4E;AAC5E,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,qEAAqE;IACrE,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC5C,IAAI,EAAE,CACJ,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,KACtC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrC;AAuCD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,SAAS,kBAAkB,EAAE,GACvC,UAAU,CAAC,OAAO,gBAAgB,CAAC,GAAG,SAAS,CAuCjD;AA+KD,0EAA0E;AAC1E,wBAAsB,gCAAgC,IAAI,OAAO,CAAC,IAAI,CAAC,CAStE"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-run gate for declarations that need a user-owned credential.
|
|
3
|
+
*
|
|
4
|
+
* Before the first model turn the gate reads the caller's OAuth grants from
|
|
5
|
+
* Agent Auth. Missing grants raise one LangGraph interrupt listing connect
|
|
6
|
+
* URLs; the tools a grant unlocks are loaded on first use and cached per
|
|
7
|
+
* caller.
|
|
8
|
+
*/
|
|
9
|
+
import { createMiddleware } from "langchain";
|
|
10
|
+
import { interrupt } from "@langchain/langgraph";
|
|
11
|
+
import { AgentAuth, CredentialAuthorizationRequiredError, } from "./agent-auth.js";
|
|
12
|
+
import { resolveAgentAuthContext, resolveOwnerId, } from "./credentials.js";
|
|
13
|
+
import { buildRuntimeIdentity, resolveRuntimeConfigurable, } from "./runtime/identity-runtime.js";
|
|
14
|
+
import { wrapToolsWithManagedRuntime, } from "./runtime/managed-tools.js";
|
|
15
|
+
export const CREDENTIAL_GATE_MIDDLEWARE_NAME = "mda-credential-gate";
|
|
16
|
+
/**
|
|
17
|
+
* How long a caller's loaded tools stay cached.
|
|
18
|
+
*
|
|
19
|
+
* The access token is bound into the transport when the tools are built, so the
|
|
20
|
+
* entry has to lapse well before the token does.
|
|
21
|
+
*/
|
|
22
|
+
const TOOL_CACHE_TTL_MS = 5 * 60_000;
|
|
23
|
+
/**
|
|
24
|
+
* Loaded tools by declaration and caller.
|
|
25
|
+
*
|
|
26
|
+
* Module scope, not middleware scope: a resumed run re-enters through a fresh
|
|
27
|
+
* graph factory, so a cache owned by the middleware would be empty for every
|
|
28
|
+
* turn after an interrupt. It is only ever a latency optimization — a resume
|
|
29
|
+
* can also land on another replica, so every read path rebuilds on a miss.
|
|
30
|
+
*/
|
|
31
|
+
const toolCache = new Map();
|
|
32
|
+
const declarationIds = new WeakMap();
|
|
33
|
+
let nextDeclarationId = 0;
|
|
34
|
+
class UnauthenticatedCallerError extends Error {
|
|
35
|
+
constructor() {
|
|
36
|
+
super("credentials with a user owner require an authenticated caller. " +
|
|
37
|
+
"Anonymous or agent-only runs cannot complete the credential gate.");
|
|
38
|
+
this.name = "UnauthenticatedCallerError";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function createCredentialGateMiddleware(consumers) {
|
|
42
|
+
if (consumers.length === 0) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return createMiddleware({
|
|
46
|
+
name: CREDENTIAL_GATE_MIDDLEWARE_NAME,
|
|
47
|
+
async beforeAgent(_state, runtime) {
|
|
48
|
+
const caller = authContext(runtime);
|
|
49
|
+
if (!caller) {
|
|
50
|
+
throw new UnauthenticatedCallerError();
|
|
51
|
+
}
|
|
52
|
+
await ensureGrants(consumers, caller);
|
|
53
|
+
await toolsForContext(consumers, caller.context);
|
|
54
|
+
},
|
|
55
|
+
async wrapModelCall(request, handler) {
|
|
56
|
+
const extra = await toolsForRuntime(consumers, request.runtime);
|
|
57
|
+
if (extra.length === 0) {
|
|
58
|
+
return handler(request);
|
|
59
|
+
}
|
|
60
|
+
const existing = Array.isArray(request.tools) ? request.tools : [];
|
|
61
|
+
return handler({ ...request, tools: [...existing, ...extra] });
|
|
62
|
+
},
|
|
63
|
+
async wrapToolCall(request, handler) {
|
|
64
|
+
const name = request.toolCall?.name;
|
|
65
|
+
if (request.tool != null || typeof name !== "string") {
|
|
66
|
+
return handler(request);
|
|
67
|
+
}
|
|
68
|
+
const tools = await toolsForRuntime(consumers, request.runtime);
|
|
69
|
+
const tool = tools.find((candidate) => candidate.name === name);
|
|
70
|
+
return tool ? handler({ ...request, tool }) : handler(request);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Interrupt once when the caller is missing a grant.
|
|
76
|
+
*
|
|
77
|
+
* Reads never mint, so the probe is safe to repeat on every replay of this
|
|
78
|
+
* node. Sessions are minted once, immediately before the interrupt that shows
|
|
79
|
+
* their URLs.
|
|
80
|
+
*/
|
|
81
|
+
async function ensureGrants(consumers, caller) {
|
|
82
|
+
const agentAuth = new AgentAuth(caller.context);
|
|
83
|
+
const granted = await Promise.all(consumerCredentials(consumers, caller).map(async ({ slug }) => ({
|
|
84
|
+
slug,
|
|
85
|
+
token: await agentAuth.readUserAccessToken(slug),
|
|
86
|
+
})));
|
|
87
|
+
const missing = granted.filter((row) => !row.token).map((row) => row.slug);
|
|
88
|
+
if (missing.length === 0) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const pending = await Promise.all(missing.map((slug) => agentAuth.startAuthorizationSession(slug)));
|
|
92
|
+
const payload = {
|
|
93
|
+
type: "credential_authorization_required",
|
|
94
|
+
message: "Connect the following integrations to continue.",
|
|
95
|
+
credentials: pending.map((session) => ({
|
|
96
|
+
slug: session.slug,
|
|
97
|
+
connect_url: session.connectUrl,
|
|
98
|
+
auth_id: session.authId,
|
|
99
|
+
})),
|
|
100
|
+
};
|
|
101
|
+
// `interrupt` throws while no resume value is pending and returns once one
|
|
102
|
+
// is, so reaching the line below means the run resumed with a grant still
|
|
103
|
+
// missing.
|
|
104
|
+
interrupt(payload);
|
|
105
|
+
throw new CredentialAuthorizationRequiredError(missing);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Declared credentials, one per slug.
|
|
109
|
+
*
|
|
110
|
+
* Every reference is resolved through {@link resolveOwnerId}, the same check
|
|
111
|
+
* `credentials.get` applies when a tool awaits a handle, so a declaration that
|
|
112
|
+
* names another user is rejected here rather than quietly run as the caller.
|
|
113
|
+
*/
|
|
114
|
+
function consumerCredentials(consumers, caller) {
|
|
115
|
+
const bySlug = new Map();
|
|
116
|
+
for (const consumer of consumers) {
|
|
117
|
+
for (const credential of consumer.credentials) {
|
|
118
|
+
resolveOwnerId(credential.owner, caller.identity, caller.context.agentId);
|
|
119
|
+
bySlug.set(credential.slug, credential);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return [...bySlug.values()];
|
|
123
|
+
}
|
|
124
|
+
async function toolsForRuntime(consumers, runtime) {
|
|
125
|
+
const caller = authContext(runtime);
|
|
126
|
+
return caller ? await toolsForContext(consumers, caller.context) : [];
|
|
127
|
+
}
|
|
128
|
+
async function toolsForContext(consumers, context) {
|
|
129
|
+
const loaded = await Promise.all(consumers.map((consumer) => cachedTools(consumer, context)));
|
|
130
|
+
return loaded.flat();
|
|
131
|
+
}
|
|
132
|
+
async function cachedTools(consumer, context) {
|
|
133
|
+
const key = `${declarationId(consumer.declaration)} ${context.principalId}`;
|
|
134
|
+
for (;;) {
|
|
135
|
+
const cached = toolCache.get(key);
|
|
136
|
+
if (!cached) {
|
|
137
|
+
return refresh(key, consumer, context, undefined);
|
|
138
|
+
}
|
|
139
|
+
const entry = await cached.catch(() => undefined);
|
|
140
|
+
if (entry && entry.expiresAt > Date.now()) {
|
|
141
|
+
return entry.tools;
|
|
142
|
+
}
|
|
143
|
+
// Nothing suspends between this read and the write inside `refresh`, so a
|
|
144
|
+
// lapsed entry is retired by exactly one caller. The rest see the
|
|
145
|
+
// replacement on the next pass and join it.
|
|
146
|
+
if (toolCache.get(key) === cached) {
|
|
147
|
+
return refresh(key, consumer, context, entry);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Publish the load before awaiting it, so concurrent callers share one transport. */
|
|
152
|
+
async function refresh(key, consumer, context, lapsed) {
|
|
153
|
+
const loading = loadTools(consumer, context);
|
|
154
|
+
toolCache.set(key, loading);
|
|
155
|
+
lapsed?.close().catch(() => undefined);
|
|
156
|
+
try {
|
|
157
|
+
return (await loading).tools;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (toolCache.get(key) === loading) {
|
|
161
|
+
toolCache.delete(key);
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function loadTools(consumer, context) {
|
|
167
|
+
const agentAuth = new AgentAuth(context);
|
|
168
|
+
const resolved = await Promise.all(consumer.credentials.map(async ({ slug }) => ({
|
|
169
|
+
slug,
|
|
170
|
+
token: await agentAuth.readUserAccessToken(slug),
|
|
171
|
+
})));
|
|
172
|
+
const missing = resolved.filter((row) => !row.token).map((row) => row.slug);
|
|
173
|
+
if (missing.length > 0) {
|
|
174
|
+
throw new CredentialAuthorizationRequiredError(missing);
|
|
175
|
+
}
|
|
176
|
+
const accessTokens = new Map(resolved.map((row) => [row.slug, row.token]));
|
|
177
|
+
const loaded = await consumer.load(accessTokens);
|
|
178
|
+
return {
|
|
179
|
+
tools: wrapToolsWithManagedRuntime(loaded.tools),
|
|
180
|
+
close: loaded.close,
|
|
181
|
+
expiresAt: Date.now() + TOOL_CACHE_TTL_MS,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function declarationId(declaration) {
|
|
185
|
+
const existing = declarationIds.get(declaration);
|
|
186
|
+
if (existing)
|
|
187
|
+
return existing;
|
|
188
|
+
nextDeclarationId += 1;
|
|
189
|
+
const id = String(nextDeclarationId);
|
|
190
|
+
declarationIds.set(declaration, id);
|
|
191
|
+
return id;
|
|
192
|
+
}
|
|
193
|
+
function authContext(runtime) {
|
|
194
|
+
const identity = buildRuntimeIdentity(resolveRuntimeConfigurable(runtime));
|
|
195
|
+
if (!identity?.user.id) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
return { context: resolveAgentAuthContext(identity), identity };
|
|
199
|
+
}
|
|
200
|
+
/** Drop every cached caller entry and close its transports. Test-only. */
|
|
201
|
+
export async function clearCredentialToolCacheForTests() {
|
|
202
|
+
const entries = [...toolCache.values()];
|
|
203
|
+
toolCache.clear();
|
|
204
|
+
await Promise.all(entries.map(async (entry) => {
|
|
205
|
+
const resolved = await entry.catch(() => undefined);
|
|
206
|
+
await resolved?.close().catch(() => undefined);
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=credential-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-gate.js","sourceRoot":"","sources":["../src/credential-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EACL,SAAS,EACT,oCAAoC,GAErC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,uBAAuB,EACvB,cAAc,GAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAE3B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL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,IAAI,CAAC,EAAE,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,uBAAuB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;AAClE,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,gCAAgC;IACpD,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACxC,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC1B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `credentials.get(...)` — read a managed credential from a tool.
|
|
3
|
+
*
|
|
4
|
+
* `owner` is the scope the credential resolves under, and names the same axis as
|
|
5
|
+
* Agent Auth's `owner_type` / `owner_id`. `{ type: "agent" }` is the deployment,
|
|
6
|
+
* so every caller resolves the same static secret. `{ type: "user" }` is the
|
|
7
|
+
* current caller, always backed by an OAuth grant. Resolution reads Agent Auth
|
|
8
|
+
* on every await and never caches.
|
|
9
|
+
*/
|
|
10
|
+
import type { RuntimeIdentity } from "./identity/index.js";
|
|
11
|
+
import { type AgentAuthContext } from "./agent-auth.js";
|
|
12
|
+
export { AGENT_AUTH_TIMEOUT_MS, AgentAuthUnknownProviderError, CredentialAuthorizationRequiredError, CredentialStoreError, } from "./agent-auth.js";
|
|
13
|
+
export type { AgentAuthContext, PendingAuthorization } from "./agent-auth.js";
|
|
14
|
+
export type AgentCredentialOwner = {
|
|
15
|
+
type: "agent";
|
|
16
|
+
};
|
|
17
|
+
export type UserCredentialOwner = {
|
|
18
|
+
type: "user";
|
|
19
|
+
id?: string;
|
|
20
|
+
};
|
|
21
|
+
export type CredentialOwner = AgentCredentialOwner | UserCredentialOwner;
|
|
22
|
+
export interface CredentialRequest {
|
|
23
|
+
slug: string;
|
|
24
|
+
owner: CredentialOwner;
|
|
25
|
+
identity?: RuntimeIdentity;
|
|
26
|
+
}
|
|
27
|
+
declare const CREDENTIAL_REFERENCE: unique symbol;
|
|
28
|
+
export declare class CredentialNotFoundError extends Error {
|
|
29
|
+
readonly slug: string;
|
|
30
|
+
readonly ownerType: CredentialOwner["type"];
|
|
31
|
+
constructor(slug: string, ownerType: CredentialOwner["type"]);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A declarative credential handle. Connector declarations inspect its owner;
|
|
35
|
+
* awaiting the same handle inside a tool resolves fresh material every time.
|
|
36
|
+
*/
|
|
37
|
+
export declare class CredentialReference implements PromiseLike<string> {
|
|
38
|
+
readonly slug: string;
|
|
39
|
+
readonly owner: CredentialOwner;
|
|
40
|
+
private readonly accessor;
|
|
41
|
+
readonly [CREDENTIAL_REFERENCE] = true;
|
|
42
|
+
constructor(slug: string, owner: CredentialOwner, accessor: Credentials);
|
|
43
|
+
then<TResult1 = string, TResult2 = never>(onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
44
|
+
}
|
|
45
|
+
export declare function isCredentialReference(value: unknown): value is CredentialReference;
|
|
46
|
+
export declare class AgentAuthCredentialStore {
|
|
47
|
+
private readonly env;
|
|
48
|
+
private readonly fetchImpl;
|
|
49
|
+
private readonly timeoutMs;
|
|
50
|
+
constructor(env?: NodeJS.ProcessEnv, fetchImpl?: typeof fetch, timeoutMs?: number);
|
|
51
|
+
fetch(request: CredentialRequest): Promise<string | undefined>;
|
|
52
|
+
}
|
|
53
|
+
export declare class Credentials {
|
|
54
|
+
private readonly store;
|
|
55
|
+
constructor(store?: AgentAuthCredentialStore);
|
|
56
|
+
get(slug: string, owner: CredentialOwner): CredentialReference;
|
|
57
|
+
resolve(slug: string, owner: CredentialOwner): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Read an agent-owned secret outside a run.
|
|
60
|
+
*
|
|
61
|
+
* Connector declarations are loaded once per deployment, before any caller
|
|
62
|
+
* exists. An agent-owned secret is deployment-scoped, so it is the one lookup
|
|
63
|
+
* that carries no caller and can be resolved there.
|
|
64
|
+
*/
|
|
65
|
+
resolveDeploymentSecret(slug: string): Promise<string>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The `owner_id` a lookup is keyed by: the caller for a user, else the
|
|
69
|
+
* deployment. Shared with the credential gate so a declared owner is checked
|
|
70
|
+
* the same way wherever it is resolved.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveOwnerId(owner: CredentialOwner, identity: RuntimeIdentity | undefined, deploymentId: string | undefined): string;
|
|
73
|
+
/**
|
|
74
|
+
* The Agent Auth binding for one caller.
|
|
75
|
+
*
|
|
76
|
+
* `credentials.get` and the pre-run credential gate both resolve their owner id
|
|
77
|
+
* here, so a slug addresses the same Agent Auth row on either path.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveAgentAuthContext(identity: RuntimeIdentity | undefined, env?: NodeJS.ProcessEnv): AgentAuthContext;
|
|
80
|
+
/**
|
|
81
|
+
* Agent Auth is served by the LangSmith API.
|
|
82
|
+
*
|
|
83
|
+
* Rejects a URL that carries a path, query, or userinfo, so a misconfigured
|
|
84
|
+
* endpoint cannot send the API key at a different service.
|
|
85
|
+
*/
|
|
86
|
+
export declare function resolveAgentAuthBaseUrl(env?: NodeJS.ProcessEnv): string;
|
|
87
|
+
export declare const credentials: Credentials;
|
|
88
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AA+CD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,eAAe,GAAG,SAAS,EACrC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,CAqBR;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,eAAe,GAAG,SAAS,EACrC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,gBAAgB,CAkBlB;AAiBD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,CAoBR;AAED,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `credentials.get(...)` — read a managed credential from a tool.
|
|
3
|
+
*
|
|
4
|
+
* `owner` is the scope the credential resolves under, and names the same axis as
|
|
5
|
+
* Agent Auth's `owner_type` / `owner_id`. `{ type: "agent" }` is the deployment,
|
|
6
|
+
* so every caller resolves the same static secret. `{ type: "user" }` is the
|
|
7
|
+
* current caller, always backed by an OAuth grant. Resolution reads Agent Auth
|
|
8
|
+
* on every await and never caches.
|
|
9
|
+
*/
|
|
10
|
+
import { AGENT_AUTH_TIMEOUT_MS, AgentAuth, CredentialAuthorizationRequiredError, CredentialStoreError, } from "./agent-auth.js";
|
|
11
|
+
import { buildRuntimeIdentity, resolveRuntimeConfigurable, } from "./runtime/identity-runtime.js";
|
|
12
|
+
export { AGENT_AUTH_TIMEOUT_MS, AgentAuthUnknownProviderError, CredentialAuthorizationRequiredError, CredentialStoreError, } from "./agent-auth.js";
|
|
13
|
+
const CREDENTIAL_REFERENCE = Symbol("managed-deepagents.credential");
|
|
14
|
+
const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
15
|
+
const MAX_SLUG_LENGTH = 64;
|
|
16
|
+
const DEFAULT_LANGSMITH_ENDPOINT = "https://api.smith.langchain.com";
|
|
17
|
+
/** Agent Auth credential kinds, one per owner type. */
|
|
18
|
+
const CREDENTIAL_KIND = { agent: "secret", user: "oauth2" };
|
|
19
|
+
export class CredentialNotFoundError extends Error {
|
|
20
|
+
slug;
|
|
21
|
+
ownerType;
|
|
22
|
+
constructor(slug, ownerType) {
|
|
23
|
+
super(`no ${ownerType} credential is set for slug ${JSON.stringify(slug)}`);
|
|
24
|
+
this.name = "CredentialNotFoundError";
|
|
25
|
+
this.slug = slug;
|
|
26
|
+
this.ownerType = ownerType;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A declarative credential handle. Connector declarations inspect its owner;
|
|
31
|
+
* awaiting the same handle inside a tool resolves fresh material every time.
|
|
32
|
+
*/
|
|
33
|
+
export class CredentialReference {
|
|
34
|
+
slug;
|
|
35
|
+
owner;
|
|
36
|
+
accessor;
|
|
37
|
+
[CREDENTIAL_REFERENCE] = true;
|
|
38
|
+
constructor(slug, owner, accessor) {
|
|
39
|
+
this.slug = slug;
|
|
40
|
+
this.owner = owner;
|
|
41
|
+
this.accessor = accessor;
|
|
42
|
+
}
|
|
43
|
+
then(onfulfilled, onrejected) {
|
|
44
|
+
return this.accessor
|
|
45
|
+
.resolve(this.slug, this.owner)
|
|
46
|
+
.then(onfulfilled, onrejected);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function isCredentialReference(value) {
|
|
50
|
+
return (value instanceof CredentialReference ||
|
|
51
|
+
(typeof value === "object" &&
|
|
52
|
+
value !== null &&
|
|
53
|
+
CREDENTIAL_REFERENCE in value));
|
|
54
|
+
}
|
|
55
|
+
export class AgentAuthCredentialStore {
|
|
56
|
+
env;
|
|
57
|
+
fetchImpl;
|
|
58
|
+
timeoutMs;
|
|
59
|
+
constructor(env = process.env, fetchImpl = fetch, timeoutMs = AGENT_AUTH_TIMEOUT_MS) {
|
|
60
|
+
this.env = env;
|
|
61
|
+
this.fetchImpl = fetchImpl;
|
|
62
|
+
this.timeoutMs = timeoutMs;
|
|
63
|
+
}
|
|
64
|
+
async fetch(request) {
|
|
65
|
+
const config = resolveAgentAuthConfig(this.env);
|
|
66
|
+
const ownerId = resolveOwnerId(request.owner, request.identity, config.deploymentId);
|
|
67
|
+
const client = new AgentAuth({
|
|
68
|
+
baseUrl: config.baseUrl,
|
|
69
|
+
agentId: config.deploymentId ?? ownerId,
|
|
70
|
+
principalId: ownerId,
|
|
71
|
+
apiKey: config.apiKey,
|
|
72
|
+
workspaceId: config.workspaceId,
|
|
73
|
+
}, this.fetchImpl, this.timeoutMs);
|
|
74
|
+
if (request.owner.type === "user") {
|
|
75
|
+
return await client.readUserAccessToken(request.slug);
|
|
76
|
+
}
|
|
77
|
+
const credentialId = await client.findCredentialId({
|
|
78
|
+
ownerType: "agent",
|
|
79
|
+
ownerId,
|
|
80
|
+
kind: CREDENTIAL_KIND.agent,
|
|
81
|
+
slug: request.slug,
|
|
82
|
+
});
|
|
83
|
+
if (!credentialId)
|
|
84
|
+
return undefined;
|
|
85
|
+
return await client.readSecret(credentialId);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export class Credentials {
|
|
89
|
+
store;
|
|
90
|
+
constructor(store = new AgentAuthCredentialStore()) {
|
|
91
|
+
this.store = store;
|
|
92
|
+
}
|
|
93
|
+
get(slug, owner) {
|
|
94
|
+
return new CredentialReference(normalizeSlug(slug), normalizeOwner(owner), this);
|
|
95
|
+
}
|
|
96
|
+
async resolve(slug, owner) {
|
|
97
|
+
const configurable = resolveRuntimeConfigurable(undefined);
|
|
98
|
+
if (!configurable) {
|
|
99
|
+
throw new Error("credentials.get(...) must be awaited inside a run: resolve a credential in a tool or middleware, not at import time");
|
|
100
|
+
}
|
|
101
|
+
const value = await this.store.fetch({
|
|
102
|
+
slug,
|
|
103
|
+
owner,
|
|
104
|
+
identity: buildRuntimeIdentity(configurable),
|
|
105
|
+
});
|
|
106
|
+
if (value === undefined) {
|
|
107
|
+
throw owner.type === "user"
|
|
108
|
+
? new CredentialAuthorizationRequiredError([slug])
|
|
109
|
+
: new CredentialNotFoundError(slug, owner.type);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Read an agent-owned secret outside a run.
|
|
115
|
+
*
|
|
116
|
+
* Connector declarations are loaded once per deployment, before any caller
|
|
117
|
+
* exists. An agent-owned secret is deployment-scoped, so it is the one lookup
|
|
118
|
+
* that carries no caller and can be resolved there.
|
|
119
|
+
*/
|
|
120
|
+
async resolveDeploymentSecret(slug) {
|
|
121
|
+
const value = await this.store.fetch({
|
|
122
|
+
slug,
|
|
123
|
+
owner: { type: "agent" },
|
|
124
|
+
});
|
|
125
|
+
if (value === undefined) {
|
|
126
|
+
throw new CredentialNotFoundError(slug, "agent");
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function normalizeSlug(slug) {
|
|
132
|
+
if (typeof slug !== "string") {
|
|
133
|
+
throw new TypeError("credential slug must be a string");
|
|
134
|
+
}
|
|
135
|
+
const canonical = slug.trim();
|
|
136
|
+
if (!canonical ||
|
|
137
|
+
canonical.length > MAX_SLUG_LENGTH ||
|
|
138
|
+
!SLUG_PATTERN.test(canonical)) {
|
|
139
|
+
throw new TypeError(`credential slug ${JSON.stringify(slug)} is invalid: use lowercase letters, digits, and single hyphens, at most ${MAX_SLUG_LENGTH} characters`);
|
|
140
|
+
}
|
|
141
|
+
return canonical;
|
|
142
|
+
}
|
|
143
|
+
function normalizeOwner(owner) {
|
|
144
|
+
if (!owner || typeof owner !== "object") {
|
|
145
|
+
throw new TypeError('credential owner is required: pass { type: "agent" } or { type: "user" }');
|
|
146
|
+
}
|
|
147
|
+
const keys = Object.keys(owner);
|
|
148
|
+
if (keys.some((key) => key !== "type" && key !== "id")) {
|
|
149
|
+
throw new TypeError("credential owner has an unknown key");
|
|
150
|
+
}
|
|
151
|
+
if (owner.type === "agent") {
|
|
152
|
+
if ("id" in owner) {
|
|
153
|
+
throw new TypeError('credential owner "id" is not accepted for { type: "agent" }');
|
|
154
|
+
}
|
|
155
|
+
return { type: "agent" };
|
|
156
|
+
}
|
|
157
|
+
if (owner.type === "user") {
|
|
158
|
+
if (owner.id === undefined)
|
|
159
|
+
return { type: "user" };
|
|
160
|
+
if (typeof owner.id !== "string" || !owner.id.trim()) {
|
|
161
|
+
throw new TypeError('credential owner "id" must be a non-empty string');
|
|
162
|
+
}
|
|
163
|
+
return { type: "user", id: owner.id.trim() };
|
|
164
|
+
}
|
|
165
|
+
throw new TypeError("credential owner type is not supported");
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The `owner_id` a lookup is keyed by: the caller for a user, else the
|
|
169
|
+
* deployment. Shared with the credential gate so a declared owner is checked
|
|
170
|
+
* the same way wherever it is resolved.
|
|
171
|
+
*/
|
|
172
|
+
export function resolveOwnerId(owner, identity, deploymentId) {
|
|
173
|
+
if (owner.type === "user") {
|
|
174
|
+
const authenticated = identity?.user.id;
|
|
175
|
+
if (!authenticated) {
|
|
176
|
+
throw new CredentialStoreError("user credentials require an authenticated user principal");
|
|
177
|
+
}
|
|
178
|
+
if (owner.id !== undefined && owner.id !== authenticated) {
|
|
179
|
+
throw new CredentialStoreError("user credential owner id must match the authenticated principal");
|
|
180
|
+
}
|
|
181
|
+
return authenticated;
|
|
182
|
+
}
|
|
183
|
+
if (!deploymentId) {
|
|
184
|
+
throw new CredentialStoreError("credentials are not configured: LANGSMITH_HOST_PROJECT_ID is not set");
|
|
185
|
+
}
|
|
186
|
+
return deploymentId;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The Agent Auth binding for one caller.
|
|
190
|
+
*
|
|
191
|
+
* `credentials.get` and the pre-run credential gate both resolve their owner id
|
|
192
|
+
* here, so a slug addresses the same Agent Auth row on either path.
|
|
193
|
+
*/
|
|
194
|
+
export function resolveAgentAuthContext(identity, env = process.env) {
|
|
195
|
+
const config = resolveAgentAuthConfig(env);
|
|
196
|
+
if (!config.deploymentId) {
|
|
197
|
+
throw new CredentialStoreError("credentials are not configured: LANGSMITH_HOST_PROJECT_ID is not set");
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
baseUrl: config.baseUrl,
|
|
201
|
+
agentId: config.deploymentId,
|
|
202
|
+
principalId: resolveOwnerId({ type: "user" }, identity, config.deploymentId),
|
|
203
|
+
apiKey: config.apiKey,
|
|
204
|
+
workspaceId: config.workspaceId,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function resolveAgentAuthConfig(env) {
|
|
208
|
+
const apiKey = env.LANGSMITH_API_KEY?.trim();
|
|
209
|
+
if (!apiKey) {
|
|
210
|
+
throw new CredentialStoreError("credentials are not configured: LANGSMITH_API_KEY is not set");
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
baseUrl: resolveAgentAuthBaseUrl(env),
|
|
214
|
+
apiKey,
|
|
215
|
+
deploymentId: env.LANGSMITH_HOST_PROJECT_ID?.trim() || undefined,
|
|
216
|
+
workspaceId: env.LANGSMITH_WORKSPACE_ID?.trim() || undefined,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Agent Auth is served by the LangSmith API.
|
|
221
|
+
*
|
|
222
|
+
* Rejects a URL that carries a path, query, or userinfo, so a misconfigured
|
|
223
|
+
* endpoint cannot send the API key at a different service.
|
|
224
|
+
*/
|
|
225
|
+
export function resolveAgentAuthBaseUrl(env = process.env) {
|
|
226
|
+
const raw = env.LANGSMITH_ENDPOINT?.trim() || DEFAULT_LANGSMITH_ENDPOINT;
|
|
227
|
+
let parsed;
|
|
228
|
+
try {
|
|
229
|
+
parsed = new URL(raw);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
throw new CredentialStoreError("LANGSMITH_ENDPOINT is not a valid URL");
|
|
233
|
+
}
|
|
234
|
+
if (!["http:", "https:"].includes(parsed.protocol) ||
|
|
235
|
+
!parsed.hostname ||
|
|
236
|
+
parsed.username ||
|
|
237
|
+
parsed.password ||
|
|
238
|
+
(parsed.pathname !== "/" && parsed.pathname !== "") ||
|
|
239
|
+
parsed.search ||
|
|
240
|
+
parsed.hash) {
|
|
241
|
+
throw new CredentialStoreError("LANGSMITH_ENDPOINT is not a valid URL");
|
|
242
|
+
}
|
|
243
|
+
return parsed.origin;
|
|
244
|
+
}
|
|
245
|
+
export const credentials = new Credentials();
|
|
246
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,oCAAoC,EACpC,oBAAoB,GAErB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,oCAAoC,EACpC,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAazB,MAAM,oBAAoB,GAAG,MAAM,CAAC,+BAA+B,CAAC,CAAC;AACrE,MAAM,YAAY,GAAG,4BAA4B,CAAC;AAClD,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,0BAA0B,GAAG,iCAAiC,CAAC;AAErE,uDAAuD;AACvD,MAAM,eAAe,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAW,CAAC;AAErE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACvC,IAAI,CAAS;IACb,SAAS,CAA0B;IAE5C,YAAY,IAAY,EAAE,SAAkC;QAC1D,KAAK,CAAC,MAAM,SAAS,+BAA+B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,C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,GAAG,CAAC,yBAAyB,EAAE,IAAI,EAAE,IAAI,SAAS;QAChE,WAAW,EAAE,GAAG,CAAC,sBAAsB,EAAE,IAAI,EAAE,IAAI,SAAS;KAC7D,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAG,GAAsB,OAAO,CAAC,GAAG;IAEpC,MAAM,GAAG,GAAG,GAAG,CAAC,kBAAkB,EAAE,IAAI,EAAE,IAAI,0BAA0B,CAAC;IACzE,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,oBAAoB,CAAC,uCAAuC,CAAC,CAAC;IAC1E,CAAC;IACD,IACE,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC9C,CAAC,MAAM,CAAC,QAAQ;QAChB,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,QAAQ;QACf,CAAC,MAAM,CAAC,QAAQ,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,KAAK,EAAE,CAAC;QACnD,MAAM,CAAC,MAAM;QACb,MAAM,CAAC,IAAI,EACX,CAAC;QACD,MAAM,IAAI,oBAAoB,CAAC,uCAAuC,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
package/dist/identity/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { IdentityConfig, IdentityDefinition, LangSmithApiKeyIngress, Valida
|
|
|
14
14
|
export { normalizeGroups, userClaimName } from "./claims.js";
|
|
15
15
|
export { normalizeIdentity } from "./options.js";
|
|
16
16
|
export type { IdentityAuth, IdentityOptions } from "./options.js";
|
|
17
|
-
export type { ClaimMapping, CredentialScope, HttpIngress, IdentityConfig, IdentityDefinition, LangSmithApiKeyIngress, RuntimeIdentity, ValidatedTokenIngress, ValidatedTokenProvider, } from "./types.js";
|
|
17
|
+
export type { ClaimMapping, CredentialScope, HttpIngress, IdentityConfig, IdentityDefinition, IdentitySource, LangSmithApiKeyIngress, Link, LinkStatus, Principal, PrincipalClaims, PrincipalEnvelope, PrincipalKind, RuntimeIdentity, Subject, SubjectAuthority, ValidatedTokenIngress, ValidatedTokenProvider, } from "./types.js";
|
|
18
18
|
/**
|
|
19
19
|
* Declare the identity contract for the deployment.
|
|
20
20
|
*
|