managed-deepagents 0.0.3-dev.26 → 0.0.3-dev.31

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.
Files changed (61) hide show
  1. package/dist/connectors/langsmith.d.ts +133 -0
  2. package/dist/connectors/langsmith.d.ts.map +1 -0
  3. package/dist/connectors/langsmith.js +262 -0
  4. package/dist/connectors/langsmith.js.map +1 -0
  5. package/dist/connectors.d.ts +7 -2
  6. package/dist/connectors.d.ts.map +1 -1
  7. package/dist/connectors.js +18 -1
  8. package/dist/connectors.js.map +1 -1
  9. package/dist/identity.d.ts +273 -0
  10. package/dist/identity.d.ts.map +1 -0
  11. package/dist/identity.js +358 -0
  12. package/dist/identity.js.map +1 -0
  13. package/dist/index.d.ts +5 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/runtime/auth.d.ts +54 -0
  18. package/dist/runtime/auth.d.ts.map +1 -0
  19. package/dist/runtime/auth.js +191 -0
  20. package/dist/runtime/auth.js.map +1 -0
  21. package/dist/runtime/connector.d.ts +138 -0
  22. package/dist/runtime/connector.d.ts.map +1 -0
  23. package/dist/runtime/connector.js +82 -0
  24. package/dist/runtime/connector.js.map +1 -0
  25. package/dist/runtime/credentials.d.ts +60 -0
  26. package/dist/runtime/credentials.d.ts.map +1 -0
  27. package/dist/runtime/credentials.js +189 -0
  28. package/dist/runtime/credentials.js.map +1 -0
  29. package/dist/runtime/identity-http.d.ts +27 -0
  30. package/dist/runtime/identity-http.d.ts.map +1 -0
  31. package/dist/runtime/identity-http.js +150 -0
  32. package/dist/runtime/identity-http.js.map +1 -0
  33. package/dist/runtime/identity-runtime.d.ts +54 -0
  34. package/dist/runtime/identity-runtime.d.ts.map +1 -0
  35. package/dist/runtime/identity-runtime.js +151 -0
  36. package/dist/runtime/identity-runtime.js.map +1 -0
  37. package/dist/runtime/index.d.ts +13 -0
  38. package/dist/runtime/index.d.ts.map +1 -1
  39. package/dist/runtime/index.js +39 -12
  40. package/dist/runtime/index.js.map +1 -1
  41. package/dist/runtime/langsmith-connector.d.ts +113 -0
  42. package/dist/runtime/langsmith-connector.d.ts.map +1 -0
  43. package/dist/runtime/langsmith-connector.js +410 -0
  44. package/dist/runtime/langsmith-connector.js.map +1 -0
  45. package/dist/runtime/managed-middleware.d.ts +25 -0
  46. package/dist/runtime/managed-middleware.d.ts.map +1 -0
  47. package/dist/runtime/managed-middleware.js +76 -0
  48. package/dist/runtime/managed-middleware.js.map +1 -0
  49. package/dist/runtime/managed-tools.d.ts +61 -0
  50. package/dist/runtime/managed-tools.d.ts.map +1 -0
  51. package/dist/runtime/managed-tools.js +102 -0
  52. package/dist/runtime/managed-tools.js.map +1 -0
  53. package/dist/runtime/types.d.ts +23 -7
  54. package/dist/runtime/types.d.ts.map +1 -1
  55. package/dist/runtime/validated-token.d.ts +25 -0
  56. package/dist/runtime/validated-token.d.ts.map +1 -0
  57. package/dist/runtime/validated-token.js +260 -0
  58. package/dist/runtime/validated-token.js.map +1 -0
  59. package/dist/types.d.ts +9 -0
  60. package/dist/types.d.ts.map +1 -1
  61. package/package.json +12 -8
@@ -0,0 +1,189 @@
1
+ import { SignJWT } from "jose";
2
+ /**
3
+ * Component 5 — Credentials, custom mode (`scoping.credentials: "custom"`, §7.2).
4
+ *
5
+ * The escape hatch Agent Auth can't cover: bespoke per-actor credential minting
6
+ * via an in-process resolver callback or a hosted token-exchange endpoint. It
7
+ * runs in the worker (not the shared ingress auth handler), applies the output
8
+ * to downstream calls, and caches per `(actor, tenant, target)` until the
9
+ * credential's `expiresAt`. Secrets live only in this in-memory cache keyed by
10
+ * identity — never in thread state or traces (§7.2, §8, identity-final §10).
11
+ *
12
+ * The managed modes (`agent`/`actor`) route to Agent Auth
13
+ * (`@langchain/auth`/`langchain-auth`, §7.1) and are wired separately; this
14
+ * module is only the custom path.
15
+ */
16
+ /** Env var holding the HMAC secret MDA signs the endpoint assertion with. */
17
+ export const CREDENTIAL_SIGNING_SECRET_ENV = "MDA_TOKEN_EXCHANGE_SECRET";
18
+ /** How long a signed endpoint assertion is valid, in seconds. */
19
+ const ASSERTION_TTL_SECONDS = 60;
20
+ /**
21
+ * TTL cache for resolved credentials, keyed by `(actor, tenant, target)` so
22
+ * per-repo/per-install tokens never collide. Kept out of thread state; entries
23
+ * expire at the credential's `expiresAt`.
24
+ */
25
+ export class CredentialCache {
26
+ entries = new Map();
27
+ get(key, nowMs) {
28
+ const hit = this.entries.get(key);
29
+ if (!hit) {
30
+ return undefined;
31
+ }
32
+ if (hit.expiresAtMs !== undefined && nowMs >= hit.expiresAtMs) {
33
+ this.entries.delete(key);
34
+ return undefined;
35
+ }
36
+ return hit.value;
37
+ }
38
+ set(key, value) {
39
+ let expiresAtMs;
40
+ if (value.expiresAt) {
41
+ const parsed = Date.parse(value.expiresAt);
42
+ expiresAtMs = Number.isNaN(parsed) ? undefined : parsed;
43
+ }
44
+ this.entries.set(key, { value, expiresAtMs });
45
+ }
46
+ clear() {
47
+ this.entries.clear();
48
+ }
49
+ }
50
+ /** Process-level cache shared across runs for the lifetime of the deployment. */
51
+ const defaultCache = new CredentialCache();
52
+ /** Clear the process-level credential cache. Test-only. */
53
+ export function clearCredentialCacheForTests() {
54
+ defaultCache.clear();
55
+ }
56
+ /**
57
+ * Build the `runtime.credentials` provider for a run, or `undefined` when the
58
+ * deployment isn't in custom-credentials mode. The provider is bound to the
59
+ * run's resolved identity; every `for(target)` call is scoped to that actor.
60
+ */
61
+ export function createCredentialsProvider(cfg, identity, deps, cache = defaultCache) {
62
+ if (cfg.scoping.credentials !== "custom" || !cfg.credentials) {
63
+ return undefined;
64
+ }
65
+ const resolved = {
66
+ fetch: deps?.fetch ?? fetch,
67
+ now: deps?.now ?? (() => Date.now()),
68
+ signAssertion: deps?.signAssertion ?? defaultSignAssertion,
69
+ };
70
+ return {
71
+ async for(target, options) {
72
+ if (!identity) {
73
+ throw new Error("runtime.credentials.for(...) requires a resolved identity, but none " +
74
+ "was available for this run.");
75
+ }
76
+ const key = cacheKey(identity, target);
77
+ if (!options?.forceRefresh) {
78
+ const hit = cache.get(key, resolved.now());
79
+ if (hit) {
80
+ return hit;
81
+ }
82
+ }
83
+ // Fail-closed: a resolver/endpoint error propagates and nothing is cached.
84
+ const out = await resolveCredential(cfg, identity, target, resolved);
85
+ cache.set(key, out);
86
+ return out;
87
+ },
88
+ };
89
+ }
90
+ async function resolveCredential(cfg, identity, target, deps) {
91
+ const creds = cfg.credentials;
92
+ if (!creds) {
93
+ throw new Error("No credentials resolver is configured for this deployment.");
94
+ }
95
+ if ("resolve" in creds) {
96
+ const out = await creds.resolve({ identity, target });
97
+ return normalizeResolved(out, "resolver");
98
+ }
99
+ const assertion = await deps.signAssertion(identity, target);
100
+ return callTokenExchange(creds.endpoint.url, assertion, deps);
101
+ }
102
+ async function callTokenExchange(url, assertion, deps) {
103
+ const response = await deps.fetch(url, {
104
+ method: "POST",
105
+ headers: {
106
+ "content-type": "application/json",
107
+ authorization: `Bearer ${assertion}`,
108
+ },
109
+ body: JSON.stringify({ assertion }),
110
+ });
111
+ if (!response.ok) {
112
+ throw new Error(`Credential token-exchange endpoint ${url} responded ${response.status}.`);
113
+ }
114
+ return normalizeResolved(await response.json(), `endpoint ${url}`);
115
+ }
116
+ async function defaultSignAssertion(identity, target) {
117
+ const secret = process.env[CREDENTIAL_SIGNING_SECRET_ENV];
118
+ if (!secret) {
119
+ throw new Error(`A hosted credential endpoint requires a signing secret. Set ` +
120
+ `${CREDENTIAL_SIGNING_SECRET_ENV} in the deployment environment.`);
121
+ }
122
+ const issuedAt = Math.floor(Date.now() / 1000);
123
+ return new SignJWT({
124
+ actor_id: identity.actor.id,
125
+ actor_type: identity.actor.type,
126
+ tenant_id: identity.tenant?.id,
127
+ target: { kind: target.kind, name: target.name, intent: target.intent },
128
+ })
129
+ .setProtectedHeader({ alg: "HS256" })
130
+ .setSubject(identity.actor.id)
131
+ .setIssuedAt(issuedAt)
132
+ .setExpirationTime(issuedAt + ASSERTION_TTL_SECONDS)
133
+ .sign(new TextEncoder().encode(secret));
134
+ }
135
+ /**
136
+ * The cache key that discriminates a minted credential: the actor + tenant it
137
+ * belongs to, plus the target's kind/name/intent/thread and metadata (§7.2).
138
+ */
139
+ function cacheKey(identity, target) {
140
+ return stableStringify([
141
+ identity.actor.id,
142
+ identity.tenant?.id ?? null,
143
+ target.kind,
144
+ target.name,
145
+ target.intent ?? null,
146
+ target.threadId ?? null,
147
+ target.metadata ?? null,
148
+ ]);
149
+ }
150
+ /** Deterministic JSON with object keys sorted, so the cache key is stable. */
151
+ function stableStringify(value) {
152
+ if (value === null || typeof value !== "object") {
153
+ return JSON.stringify(value) ?? "null";
154
+ }
155
+ if (Array.isArray(value)) {
156
+ return `[${value.map(stableStringify).join(",")}]`;
157
+ }
158
+ const obj = value;
159
+ return `{${Object.keys(obj)
160
+ .sort()
161
+ .map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`)
162
+ .join(",")}}`;
163
+ }
164
+ /** Validate a resolver/endpoint result into a {@link ResolvedCredential}. */
165
+ function normalizeResolved(value, sourceLabel) {
166
+ if (!value || typeof value !== "object") {
167
+ throw new Error(`Credential ${sourceLabel} returned a non-object result.`);
168
+ }
169
+ const { headers, expiresAt } = value;
170
+ if (!headers || typeof headers !== "object" || Array.isArray(headers)) {
171
+ throw new Error(`Credential ${sourceLabel} result is missing a headers object.`);
172
+ }
173
+ const normalizedHeaders = {};
174
+ for (const [name, headerValue] of Object.entries(headers)) {
175
+ if (typeof headerValue !== "string") {
176
+ throw new Error(`Credential ${sourceLabel} header "${name}" must be a string.`);
177
+ }
178
+ normalizedHeaders[name] = headerValue;
179
+ }
180
+ const result = { headers: normalizedHeaders };
181
+ if (expiresAt !== undefined) {
182
+ if (typeof expiresAt !== "string") {
183
+ throw new Error(`Credential ${sourceLabel} \`expiresAt\` must be an ISO string.`);
184
+ }
185
+ result.expiresAt = expiresAt;
186
+ }
187
+ return result;
188
+ }
189
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/runtime/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAS/B;;;;;;;;;;;;;GAaG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,2BAA2B,CAAC;AAEzE,iEAAiE;AACjE,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAwCjC;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACT,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEzD,GAAG,CAAC,GAAW,EAAE,KAAa;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,KAAK,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;YAC9D,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,GAAG,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAyB;QACxC,IAAI,WAA+B,CAAC;QACpC,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAC3C,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IAChD,CAAC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AAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,cAAc,WAAW,sCAAsC,CAChE,CAAC;IACJ,CAAC;IACD,MAAM,iBAAiB,GAA2B,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,cAAc,WAAW,YAAY,IAAI,qBAAqB,CAC/D,CAAC;QACJ,CAAC;QACD,iBAAiB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;IACxC,CAAC;IACD,MAAM,MAAM,GAAuB,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAClE,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CACb,cAAc,WAAW,uCAAuC,CACjE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { Hono } from "hono";
2
+ import type { IdentityDefinition } from "../identity.js";
3
+ import type { Connector } from "./connector.js";
4
+ /** Inputs the managed HTTP app is built from. */
5
+ export interface ManagedHttpAppInputs {
6
+ /** The declared identity, if the project opts into managed identity. */
7
+ identity?: IdentityDefinition;
8
+ /** Discovered connectors; those implementing `http` mount routes. */
9
+ connectors?: Connector[];
10
+ }
11
+ /**
12
+ * Build the single managed HTTP app mounted via `langgraph.json` `http.app`.
13
+ *
14
+ * It layers two concerns onto the built-in LangGraph routes:
15
+ * - **identity** — public guest issuance (`POST /identity/guest`) when the
16
+ * declared identity enables a guest provider;
17
+ * - **connectors** — each connector implementing `http` gets a sub-router
18
+ * namespaced under `/connectors/{kind}` and mounts its own routes.
19
+ *
20
+ * Connector routes are **secure by default**: MDA resolves and enforces the
21
+ * caller's identity before the handler runs, and a route must opt out of
22
+ * authentication explicitly (`router.public.*`). The connector HTTP surface is
23
+ * logged at construction so the (especially unauthenticated) routes are never
24
+ * invisible.
25
+ */
26
+ export declare function buildManagedHttpApp(inputs: ManagedHttpAppInputs): Hono;
27
+ //# sourceMappingURL=identity-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-http.d.ts","sourceRoot":"","sources":["../../src/runtime/identity-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,KAAK,EACV,SAAS,EAKV,MAAM,gBAAgB,CAAC;AAGxB,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,qEAAqE;IACrE,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B;AAuBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAgBtE"}
@@ -0,0 +1,150 @@
1
+ import { Hono } from "hono";
2
+ import { resolveRequestIdentity } from "./auth.js";
3
+ import { issueGuestToken } from "./validated-token.js";
4
+ /** Signals a secured route was reached but no identity is declared to resolve it. */
5
+ class IdentityNotConfiguredError extends Error {
6
+ status = 401;
7
+ constructor() {
8
+ super("secured connector route requires an identity declaration, but this " +
9
+ "deployment has none");
10
+ }
11
+ }
12
+ /**
13
+ * Build the single managed HTTP app mounted via `langgraph.json` `http.app`.
14
+ *
15
+ * It layers two concerns onto the built-in LangGraph routes:
16
+ * - **identity** — public guest issuance (`POST /identity/guest`) when the
17
+ * declared identity enables a guest provider;
18
+ * - **connectors** — each connector implementing `http` gets a sub-router
19
+ * namespaced under `/connectors/{kind}` and mounts its own routes.
20
+ *
21
+ * Connector routes are **secure by default**: MDA resolves and enforces the
22
+ * caller's identity before the handler runs, and a route must opt out of
23
+ * authentication explicitly (`router.public.*`). The connector HTTP surface is
24
+ * logged at construction so the (especially unauthenticated) routes are never
25
+ * invisible.
26
+ */
27
+ export function buildManagedHttpApp(inputs) {
28
+ const app = new Hono();
29
+ if (inputs.identity) {
30
+ mountIdentityRoutes(app, inputs.identity);
31
+ }
32
+ const mounted = [];
33
+ for (const connector of inputs.connectors ?? []) {
34
+ if (typeof connector.http === "function") {
35
+ mountConnectorRoutes(app, connector, inputs.identity?.config, mounted);
36
+ }
37
+ }
38
+ logConnectorSurface(mounted);
39
+ return app;
40
+ }
41
+ /** Mount the public identity routes (guest issuance) onto `app`. */
42
+ function mountIdentityRoutes(app, identity) {
43
+ const http = identity.config.ingress.http;
44
+ if (http === "trusted_backend") {
45
+ return;
46
+ }
47
+ const guestProvider = http.providers.find((provider) => provider.guest?.issue);
48
+ if (!guestProvider) {
49
+ return;
50
+ }
51
+ app.post("/identity/guest", async (c) => {
52
+ const token = await issueGuestToken(guestProvider);
53
+ return c.json({ token });
54
+ });
55
+ }
56
+ /**
57
+ * Mount a connector's `http` routes on a sub-router namespaced under
58
+ * `/connectors/{kind}`, so connector routes cannot collide with identity/API
59
+ * routes or with each other.
60
+ */
61
+ function mountConnectorRoutes(app, connector, cfg, mounted) {
62
+ const sub = new Hono();
63
+ const router = honoConnectorRouter(sub, connector.kind, cfg, mounted);
64
+ const ctx = {
65
+ router,
66
+ identity: cfg,
67
+ requireIdentity: (request) => {
68
+ if (!cfg) {
69
+ return Promise.reject(new Error("identity is not configured for this deployment; declare an " +
70
+ "identity to resolve caller identity on connector routes."));
71
+ }
72
+ return resolveRequestIdentity(cfg, request);
73
+ },
74
+ };
75
+ connector.http?.(ctx);
76
+ app.route(`/connectors/${connector.kind}`, sub);
77
+ }
78
+ /**
79
+ * Build the secure-by-default {@link HttpSubRouter} over a Hono sub-app. Secured
80
+ * routes resolve identity (401 on failure) before the handler runs; `public.*`
81
+ * routes skip enforcement. Every registration is recorded in `mounted`.
82
+ */
83
+ function honoConnectorRouter(sub, kind, cfg, mounted) {
84
+ const secured = (method) => (path, handler) => {
85
+ mounted.push({ connector: kind, method, path, secured: true });
86
+ sub[method](path, async (c) => {
87
+ const request = c.req.raw;
88
+ if (!cfg) {
89
+ return unauthorizedResponse(new IdentityNotConfiguredError());
90
+ }
91
+ let identity;
92
+ try {
93
+ identity = await resolveRequestIdentity(cfg, request);
94
+ }
95
+ catch (error) {
96
+ return unauthorizedResponse(error);
97
+ }
98
+ return handler(request, identity);
99
+ });
100
+ };
101
+ const publicRoute = (method) => (path, handler) => {
102
+ mounted.push({ connector: kind, method, path, secured: false });
103
+ sub[method](path, (c) => handler(c.req.raw));
104
+ };
105
+ return {
106
+ get: secured("get"),
107
+ post: secured("post"),
108
+ put: secured("put"),
109
+ delete: secured("delete"),
110
+ public: {
111
+ get: publicRoute("get"),
112
+ post: publicRoute("post"),
113
+ put: publicRoute("put"),
114
+ delete: publicRoute("delete"),
115
+ },
116
+ };
117
+ }
118
+ /** Map a resolution error to a fail-closed JSON response. */
119
+ function unauthorizedResponse(error) {
120
+ const status = typeof error.status === "number"
121
+ ? error.status
122
+ : 401;
123
+ const message = error instanceof Error && error.message ? error.message : "unauthorized";
124
+ return new Response(JSON.stringify({ error: message }), {
125
+ status,
126
+ headers: { "content-type": "application/json" },
127
+ });
128
+ }
129
+ /**
130
+ * Log the connector HTTP surface so both secured and (loudly) public routes are
131
+ * visible in deploy/dev startup logs — the routes are mounted at runtime, so
132
+ * this is where the actual surface can be enumerated.
133
+ */
134
+ function logConnectorSurface(mounted) {
135
+ if (mounted.length === 0) {
136
+ return;
137
+ }
138
+ console.info(`[mda] connector HTTP surface (${mounted.length} route(s)):`);
139
+ for (const route of mounted) {
140
+ const full = `/connectors/${route.connector}${route.path}`;
141
+ const line = `[mda] ${route.method.toUpperCase().padEnd(6)} ${full}`;
142
+ if (route.secured) {
143
+ console.info(`${line} (identity enforced)`);
144
+ }
145
+ else {
146
+ console.warn(`${line} (PUBLIC — no identity enforcement)`);
147
+ }
148
+ }
149
+ }
150
+ //# sourceMappingURL=identity-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-http.js","sourceRoot":"","sources":["../../src/runtime/identity-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAQnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAoBvD,qFAAqF;AACrF,MAAM,0BAA2B,SAAQ,KAAK;IACnC,MAAM,GAAG,GAAG,CAAC;IACtB;QACE,KAAK,CACH,qEAAqE;YACnE,qBAAqB,CACxB,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA4B;IAC9D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,OAAO,GAAmB,EAAE,CAAC;IACnC,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAChD,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACzC,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IACD,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAE7B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,oEAAoE;AACpE,SAAS,mBAAmB,CAAC,GAAS,EAAE,QAA4B;IAClE,MAAM,IAAI,GAAG,QAAQ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EAAE,CAAC;QAC3D,MAAM,IAAI,GAAG,WAAW,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QACvE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,uBAAuB,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,sCAAsC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { IdentityConfig, MemoryScope, RuntimeIdentity, Tenancy } from "../identity.js";
2
+ import type { ConfigurableCarrier } from "./types.js";
3
+ /**
4
+ * Resolve the LangGraph `configurable` bag from either a flat runtime or the
5
+ * nested `ToolRuntime` shape LangChain passes to tools (`runtime.config.configurable`).
6
+ */
7
+ export declare function resolveRuntimeConfigurable(runtime: RuntimeConfigLike | undefined): Record<string, unknown> | undefined;
8
+ /**
9
+ * Build the frozen identity envelope for the current run from the trusted
10
+ * `langgraph_auth_user` the custom-auth handler produced (§6.1). Returns
11
+ * `undefined` when the deployment has no resolvable actor (identity is opt-in).
12
+ */
13
+ export declare function buildRuntimeIdentity(configurable: Record<string, unknown> | undefined): RuntimeIdentity | undefined;
14
+ /**
15
+ * The durable Store namespace for the run, per `scoping.memory` (§6.2). A
16
+ * `deploymentId` prefix isolates deployments; identity segments follow. Returns
17
+ * `undefined` for `none` (no durable memory). Fail-closed: an `actor` scope with
18
+ * no actor already rejects at ingress, so the segments are never empty here.
19
+ */
20
+ export declare function memoryNamespace(cfg: IdentityConfig, ident: RuntimeIdentity, deploymentId: string): string[] | undefined;
21
+ /**
22
+ * The runtime the managed seam sees: the shared `configurable` carrier, plus the
23
+ * optional nested `config` (e.g. LangGraph `ToolRuntime.config`) and the frozen
24
+ * `identity` envelope the seam layers on. Single source for the tool, middleware,
25
+ * and memory-namespace helpers.
26
+ */
27
+ export interface RuntimeConfigLike extends ConfigurableCarrier {
28
+ identity?: RuntimeIdentity;
29
+ config?: {
30
+ configurable?: Record<string, unknown>;
31
+ };
32
+ }
33
+ /**
34
+ * Resolve the durable memory namespace for a run directly from the runtime the
35
+ * memory `StoreBackend` receives, per `scoping.memory` (§6.2). This is the
36
+ * plug-in point for the (deferred) Store-backed memory: a `StoreBackend`
37
+ * namespace factory becomes `(ctx) => memoryNamespaceFor(ctx.runtime, cfg, id)`.
38
+ * Returns `undefined` when the run has no durable namespace (`none`, or a
39
+ * per-actor scope with no resolved actor).
40
+ */
41
+ export declare function memoryNamespaceFor(runtime: RuntimeConfigLike | undefined, cfg: IdentityConfig, deploymentId: string): string[] | undefined;
42
+ /**
43
+ * The identity portion of the memory namespace (no deployment prefix), shared by
44
+ * the memory `StoreBackend` and the `@auth.on.store` boundary check so both agree
45
+ * on exactly which segments identify a namespace.
46
+ */
47
+ export declare function memoryIdentitySegments(scope: MemoryScope, tenancy: Tenancy, actorId: string | undefined, tenantId: string | undefined): string[];
48
+ /**
49
+ * Strip client-supplied identity keys from an incoming `configurable` so a
50
+ * request body can never spoof the actor/tenant the handler resolved (§8). The
51
+ * platform-set `langgraph_auth_user` is preserved — it is the only trusted source.
52
+ */
53
+ export declare function sanitizeConfigurable(configurable: Record<string, unknown> | undefined): Record<string, unknown>;
54
+ //# sourceMappingURL=identity-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/identity-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,eAAe,EACf,OAAO,EACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA0BtD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACrC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAErC;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAChD,eAAe,GAAG,SAAS,CAyB7B;AAaD;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,MAAM,GACnB,MAAM,EAAE,GAAG,SAAS,CAiBtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC5D,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;CACrD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,EAAE,GAAG,SAAS,CAQtB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,MAAM,EAAE,CAgBV;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Identity fields a client must never assert via `config.configurable`; only the
3
+ * custom-auth handler (`langgraph_auth_user`) is trusted (§8, tamper-proofing).
4
+ */
5
+ const RESERVED_CONFIGURABLE_KEYS = new Set([
6
+ "actor_id",
7
+ "tenant_id",
8
+ "mda_actor_id",
9
+ "mda_tenant_id",
10
+ "mda_actor_email",
11
+ "mda_claims",
12
+ "mda_actor_type",
13
+ "mda_source_thread_id",
14
+ ]);
15
+ /** Source channels a run can originate from (`runtime.identity.source.provider`). */
16
+ const SOURCE_PROVIDERS = new Set([
17
+ "http",
18
+ "slack",
19
+ "schedule",
20
+ "cli",
21
+ "studio",
22
+ ]);
23
+ /**
24
+ * Resolve the LangGraph `configurable` bag from either a flat runtime or the
25
+ * nested `ToolRuntime` shape LangChain passes to tools (`runtime.config.configurable`).
26
+ */
27
+ export function resolveRuntimeConfigurable(runtime) {
28
+ return runtime?.configurable ?? runtime?.config?.configurable;
29
+ }
30
+ /**
31
+ * Build the frozen identity envelope for the current run from the trusted
32
+ * `langgraph_auth_user` the custom-auth handler produced (§6.1). Returns
33
+ * `undefined` when the deployment has no resolvable actor (identity is opt-in).
34
+ */
35
+ export function buildRuntimeIdentity(configurable) {
36
+ const user = configurable?.langgraph_auth_user;
37
+ const actorId = user?.mda_actor_id;
38
+ if (!user || !actorId) {
39
+ return undefined;
40
+ }
41
+ const identity = {
42
+ actor: {
43
+ type: user.mda_actor_type === "service" ? "service" : "user",
44
+ id: String(actorId),
45
+ ...(user.mda_actor_email ? { email: String(user.mda_actor_email) } : {}),
46
+ },
47
+ source: {
48
+ provider: sourceProvider(configurable),
49
+ ...(threadId(configurable) ? { threadId: threadId(configurable) } : {}),
50
+ },
51
+ };
52
+ if (user.mda_tenant_id) {
53
+ identity.tenant = { id: String(user.mda_tenant_id) };
54
+ }
55
+ if (user.mda_claims && typeof user.mda_claims === "object") {
56
+ identity.claims = user.mda_claims;
57
+ }
58
+ // Immutable: tools/middleware get a read-only view they cannot tamper with (§8).
59
+ return deepFreeze(identity);
60
+ }
61
+ /** Recursively freeze an object graph so the identity envelope is read-only. */
62
+ function deepFreeze(value) {
63
+ if (value && typeof value === "object" && !Object.isFrozen(value)) {
64
+ for (const nested of Object.values(value)) {
65
+ deepFreeze(nested);
66
+ }
67
+ Object.freeze(value);
68
+ }
69
+ return value;
70
+ }
71
+ /**
72
+ * The durable Store namespace for the run, per `scoping.memory` (§6.2). A
73
+ * `deploymentId` prefix isolates deployments; identity segments follow. Returns
74
+ * `undefined` for `none` (no durable memory). Fail-closed: an `actor` scope with
75
+ * no actor already rejects at ingress, so the segments are never empty here.
76
+ */
77
+ export function memoryNamespace(cfg, ident, deploymentId) {
78
+ const scope = cfg.scoping.memory;
79
+ if (scope === "none") {
80
+ return undefined;
81
+ }
82
+ if (scope === "agent") {
83
+ return [deploymentId, "agent"];
84
+ }
85
+ return [
86
+ deploymentId,
87
+ ...memoryIdentitySegments(scope, cfg.tenancy, ident.actor.id, ident.tenant?.id),
88
+ ];
89
+ }
90
+ /**
91
+ * Resolve the durable memory namespace for a run directly from the runtime the
92
+ * memory `StoreBackend` receives, per `scoping.memory` (§6.2). This is the
93
+ * plug-in point for the (deferred) Store-backed memory: a `StoreBackend`
94
+ * namespace factory becomes `(ctx) => memoryNamespaceFor(ctx.runtime, cfg, id)`.
95
+ * Returns `undefined` when the run has no durable namespace (`none`, or a
96
+ * per-actor scope with no resolved actor).
97
+ */
98
+ export function memoryNamespaceFor(runtime, cfg, deploymentId) {
99
+ const configurable = runtime?.configurable ?? runtime?.config?.configurable;
100
+ const identity = buildRuntimeIdentity(configurable);
101
+ if (identity) {
102
+ return memoryNamespace(cfg, identity, deploymentId);
103
+ }
104
+ // No resolved actor: only the actor-independent `agent` scope has a namespace.
105
+ return cfg.scoping.memory === "agent" ? [deploymentId, "agent"] : undefined;
106
+ }
107
+ /**
108
+ * The identity portion of the memory namespace (no deployment prefix), shared by
109
+ * the memory `StoreBackend` and the `@auth.on.store` boundary check so both agree
110
+ * on exactly which segments identify a namespace.
111
+ */
112
+ export function memoryIdentitySegments(scope, tenancy, actorId, tenantId) {
113
+ if (scope === "actor") {
114
+ const segments = [];
115
+ if (tenancy === "multi" && tenantId) {
116
+ segments.push(tenantId);
117
+ }
118
+ if (actorId) {
119
+ segments.push(actorId);
120
+ }
121
+ return segments;
122
+ }
123
+ if (scope === "tenant") {
124
+ return tenantId ? [tenantId] : [];
125
+ }
126
+ // "agent" (shared) | "none" (no memory) → no per-identity restriction.
127
+ return [];
128
+ }
129
+ /**
130
+ * Strip client-supplied identity keys from an incoming `configurable` so a
131
+ * request body can never spoof the actor/tenant the handler resolved (§8). The
132
+ * platform-set `langgraph_auth_user` is preserved — it is the only trusted source.
133
+ */
134
+ export function sanitizeConfigurable(configurable) {
135
+ if (!configurable) {
136
+ return {};
137
+ }
138
+ return Object.fromEntries(Object.entries(configurable).filter(([key]) => !RESERVED_CONFIGURABLE_KEYS.has(key)));
139
+ }
140
+ function sourceProvider(configurable) {
141
+ const declared = configurable?.mda_source_provider;
142
+ if (typeof declared === "string" && SOURCE_PROVIDERS.has(declared)) {
143
+ return declared;
144
+ }
145
+ return "http";
146
+ }
147
+ function threadId(configurable) {
148
+ const value = configurable?.thread_id;
149
+ return value == null ? undefined : String(value);
150
+ }
151
+ //# sourceMappingURL=identity-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-runtime.js","sourceRoot":"","sources":["../../src/runtime/identity-runtime.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC;IACzC,UAAU;IACV,WAAW;IACX,cAAc;IACd,eAAe;IACf,iBAAiB;IACjB,YAAY;IACZ,gBAAgB;IAChB,sBAAsB;CACvB,CAAC,CAAC;AAEH,qFAAqF;AACrF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,MAAM;IACN,OAAO;IACP,UAAU;IACV,KAAK;IACL,QAAQ;CACT,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAsC;IAEtC,OAAO,OAAO,EAAE,YAAY,IAAI,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,YAAiD;IAEjD,MAAM,IAAI,GAA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MAAM,KAAK,GAAG,YAAY,EAAE,SAAS,CAAC;IACtC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC"}
@@ -1,6 +1,19 @@
1
1
  import type { DeepAgentDefinition } from "../types.js";
2
2
  import type { ManagedAgentOptions, ManagedRunConfig } from "./types.js";
3
3
  export type { ManagedAgentOptions, ManagedRunConfig } from "./types.js";
4
+ export { buildManagedAuth } from "./auth.js";
5
+ export { buildManagedHttpApp } from "./identity-http.js";
6
+ export { CONNECTOR_BRAND, collectConnectors, isConnector, loadConnectorTools, } from "./connector.js";
7
+ export type { Connector, ConnectorToolList, DiscoveredConnectorModule, HttpContext, HttpSubRouter, PublicRouteHandler, PublicSubRouter, SecuredRouteHandler, ToolContext, } from "./connector.js";
8
+ export type { ManagedUser } from "./auth.js";
9
+ export { CredentialCache, CREDENTIAL_SIGNING_SECRET_ENV, clearCredentialCacheForTests, createCredentialsProvider, } from "./credentials.js";
10
+ export type { CredentialDeps, CredentialForOptions, CredentialsProvider, } from "./credentials.js";
11
+ export { buildRuntimeIdentity, memoryIdentitySegments, memoryNamespace, memoryNamespaceFor, sanitizeConfigurable, } from "./identity-runtime.js";
12
+ export { managedRuntimeExtras, managedRuntimeOverrides, withManagedRuntime, wrapToolsWithManagedRuntime, } from "./managed-tools.js";
13
+ export type { InvokableTool, ManagedDeepAgentRuntime, ManagedRuntimeExtras, } from "./managed-tools.js";
14
+ export { withManagedMiddleware, wrapMiddlewareWithManagedRuntime, } from "./managed-middleware.js";
15
+ export type { ManagedMiddleware } from "./managed-middleware.js";
16
+ export { issueGuestToken } from "./validated-token.js";
4
17
  /**
5
18
  * Compile a {@link DeepAgentDefinition} into a runnable Deep Agent.
6
19
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,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