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
package/dist/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  export { defineDeepAgent } from "./define-deep-agent.js";
2
2
  export { defineMcpServers } from "./connectors.js";
3
+ export * as langsmith from "./connectors/langsmith.js";
4
+ export type { LangSmithCapability, LangSmithCallerSurface, LangSmithCapabilityScope, LangSmithConnector, LangSmithConnectorConfig, LangSmithResource, LangSmithResponseShape, } from "./connectors/langsmith.js";
3
5
  export { defineSchedule } from "./schedules.js";
4
6
  export { defineSandbox } from "./sandbox.js";
7
+ export { defineIdentity, providers, validateIdentity } from "./identity.js";
8
+ export type { CredentialResolver, CredentialResolverConfig, CredentialScope, CredentialTarget, DefineIdentity, HttpIngress, IdentityConfig, IdentityDefinition, IdentityPresetName, MemoryScope, ResolvedCredential, RuntimeIdentity, Tenancy, ThreadScope, ValidatedTokenIngress, ValidatedTokenProvider, } from "./identity.js";
5
9
  export type { HttpMcpServerConfig, McpServersConfig, McpServersDefinition, McpToolSelectionConfig, RemoteMcpServerBaseConfig, RemoteMcpServerConfig, SseMcpServerConfig, } from "./connectors.js";
6
10
  export type { ScheduleConfig, ScheduleDefinition, ScheduleDeliveryTarget, ScheduleThreadConfig, } from "./schedules.js";
7
11
  export type { ChannelAttachment, ChannelDestination, ChannelEvent, ChannelMessage, ChannelPostOptions, DeepAgentDefinition, DefineDeepAgentConfig, ManagedDeepAgentKey, PostedChannelMessage, Runtime, RuntimeChannel, } from "./types.js";
12
+ export type { ManagedDeepAgentRuntime, ManagedRuntimeExtras, } from "./runtime/managed-tools.js";
8
13
  export type { DefineSandboxOptions, ManagedSandboxOptionKey, SandboxDefinition, SandboxProviderClass, SandboxProviderOptions, SandboxScope, } from "./sandbox.js";
9
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,OAAO,EACP,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,GACb,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AACvD,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE5E,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,OAAO,EACP,WAAW,EACX,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,OAAO,EACP,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,GACb,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export { defineDeepAgent } from "./define-deep-agent.js";
2
2
  export { defineMcpServers } from "./connectors.js";
3
+ export * as langsmith from "./connectors/langsmith.js";
3
4
  export { defineSchedule } from "./schedules.js";
4
5
  export { defineSandbox } from "./sandbox.js";
6
+ export { defineIdentity, providers, validateIdentity } from "./identity.js";
5
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAUvD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { Auth } from "@langchain/langgraph-sdk/auth";
2
+ import type { IdentityConfig, IdentityDefinition, RuntimeIdentity } from "../identity.js";
3
+ /**
4
+ * The user object `@auth.authenticate` returns. `identity`/`permissions` satisfy
5
+ * the LangGraph base shape; the `mda_*` fields carry the identity envelope into
6
+ * `config.configurable.langgraph_auth_user` for the runtime seam.
7
+ */
8
+ export interface ManagedUser {
9
+ identity: string;
10
+ permissions: string[];
11
+ mda_actor_id: string;
12
+ mda_tenant_id?: string;
13
+ mda_actor_email?: string;
14
+ mda_claims?: Record<string, unknown>;
15
+ [key: string]: unknown;
16
+ }
17
+ /**
18
+ * Build the managed LangGraph custom-auth handler from a declared identity.
19
+ *
20
+ * Handles both ingress modes: `trusted_backend` (reserved headers behind a
21
+ * shared ingress secret) and `validated_token` (browser-direct IdP tokens
22
+ * verified via JWKS / introspection / MDA-signed guest). Also registers thread
23
+ * and store scoping with a studio bypass.
24
+ */
25
+ export declare function buildManagedAuth(identity: IdentityDefinition): Auth;
26
+ /**
27
+ * Resolve the caller's frozen {@link RuntimeIdentity} from a raw HTTP request,
28
+ * using the same ingress logic (`trusted_backend` headers / `validated_token`
29
+ * verification) as the managed auth handler. Throws an {@link HTTPException}
30
+ * (401) when the caller is unauthenticated or unresolvable.
31
+ *
32
+ * This is the resolver that backs default-secure connector HTTP routes: a
33
+ * connector route runs behind identity by default, and this is what enforces it.
34
+ */
35
+ export declare function resolveRequestIdentity(cfg: IdentityConfig, request: Request): Promise<RuntimeIdentity>;
36
+ /**
37
+ * Fail-closed (403) unless every identity segment the memory scope requires is
38
+ * present in the store `namespace`. `agent`/`none` scopes carry no per-identity
39
+ * restriction (shared or absent memory), so any namespace is allowed.
40
+ */
41
+ export declare function assertStoreAccess(cfg: IdentityConfig, user: ManagedUser, value: unknown): void;
42
+ /**
43
+ * Resolve the caller identity for `trusted_backend`: validate the shared ingress
44
+ * secret, then trust the reserved actor/tenant headers. Fail-closed (401) on a
45
+ * missing/invalid secret, a missing actor, or a missing tenant under multi.
46
+ */
47
+ export declare function resolveTrustedBackendUser(cfg: IdentityConfig, request: Request): ManagedUser;
48
+ /** Derive the owner value `@auth.on.threads` filters on, per the `threads` axis. */
49
+ export declare function threadOwnerKey(cfg: IdentityConfig, user: ManagedUser): string;
50
+ /** True when this deployment exposes guest issuance and the request targets it. */
51
+ export declare function isGuestIssuanceRequest(request: Request, cfg: IdentityConfig): boolean;
52
+ /** Placeholder identity so LangGraph auth middleware allows tokenless issuance. */
53
+ export declare function guestIssuanceBypassUser(): ManagedUser;
54
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/runtime/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAGL,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,eAAe,EAChB,MAAM,gBAAgB,CAAC;AA0BxB;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAsCnE;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CAc1B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,OAAO,GACb,IAAI,CAuBN;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,OAAO,GACf,WAAW,CAgBb;AAED,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAY7E;AAuBD,mFAAmF;AACnF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,cAAc,GAClB,OAAO,CAaT;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,IAAI,WAAW,CAMrD"}
@@ -0,0 +1,191 @@
1
+ import { Auth, HTTPException, isStudioUser, } from "@langchain/langgraph-sdk/auth";
2
+ import { buildRuntimeIdentity, memoryIdentitySegments, } from "./identity-runtime.js";
3
+ import { resolveValidatedTokenUser } from "./validated-token.js";
4
+ /**
5
+ * Reserved transport for the trusted-backend ingress mode. Actor/tenant travel
6
+ * as reserved headers (mapped into `config.configurable` by the generated
7
+ * `langgraph.json` allowlist); the ingress secret is validated here and is
8
+ * deliberately **not** allowlisted, so it never reaches `config.configurable`.
9
+ */
10
+ const ACTOR_HEADER = "x-mda-actor-id";
11
+ const TENANT_HEADER = "x-mda-tenant-id";
12
+ const INGRESS_SECRET_HEADER = "x-mda-ingress-secret";
13
+ /** Deployment env var carrying the shared secret the trusted backend presents. */
14
+ const INGRESS_SECRET_ENV = "MDA_INGRESS_SECRET";
15
+ /** Path MDA exposes for anonymous guest token issuance (must stay public). */
16
+ const GUEST_ISSUANCE_PATH = "/identity/guest";
17
+ /** Synthetic actor used only to satisfy auth middleware on the issuance route. */
18
+ const GUEST_ISSUER_ACTOR = "mda:guest-issuer";
19
+ /**
20
+ * Build the managed LangGraph custom-auth handler from a declared identity.
21
+ *
22
+ * Handles both ingress modes: `trusted_backend` (reserved headers behind a
23
+ * shared ingress secret) and `validated_token` (browser-direct IdP tokens
24
+ * verified via JWKS / introspection / MDA-signed guest). Also registers thread
25
+ * and store scoping with a studio bypass.
26
+ */
27
+ export function buildManagedAuth(identity) {
28
+ const cfg = identity.config;
29
+ const http = cfg.ingress.http;
30
+ const auth = new Auth();
31
+ auth.authenticate(async (request) => {
32
+ if (isGuestIssuanceRequest(request, cfg)) {
33
+ return guestIssuanceBypassUser();
34
+ }
35
+ if (http === "trusted_backend") {
36
+ return resolveTrustedBackendUser(cfg, request);
37
+ }
38
+ return resolveValidatedTokenUser(cfg, http, request);
39
+ });
40
+ auth.on("threads", ({ user, value }) => {
41
+ if (isStudioUser(user)) {
42
+ return true;
43
+ }
44
+ const key = threadOwnerKey(cfg, user);
45
+ if (value && typeof value === "object") {
46
+ const container = value;
47
+ container.metadata = { ...(container.metadata ?? {}), owner: key };
48
+ }
49
+ return { owner: key };
50
+ });
51
+ // Mirror the memory namespace so raw store ops can't cross the identity
52
+ // boundary a run is scoped to (§5, §6.2).
53
+ auth.on("store", ({ user, value }) => {
54
+ if (isStudioUser(user)) {
55
+ return true;
56
+ }
57
+ assertStoreAccess(cfg, user, value);
58
+ return true;
59
+ });
60
+ return auth;
61
+ }
62
+ /**
63
+ * Resolve the caller's frozen {@link RuntimeIdentity} from a raw HTTP request,
64
+ * using the same ingress logic (`trusted_backend` headers / `validated_token`
65
+ * verification) as the managed auth handler. Throws an {@link HTTPException}
66
+ * (401) when the caller is unauthenticated or unresolvable.
67
+ *
68
+ * This is the resolver that backs default-secure connector HTTP routes: a
69
+ * connector route runs behind identity by default, and this is what enforces it.
70
+ */
71
+ export async function resolveRequestIdentity(cfg, request) {
72
+ const http = cfg.ingress.http;
73
+ const user = http === "trusted_backend"
74
+ ? resolveTrustedBackendUser(cfg, request)
75
+ : await resolveValidatedTokenUser(cfg, http, request);
76
+ const identity = buildRuntimeIdentity({
77
+ langgraph_auth_user: user,
78
+ mda_source_provider: "http",
79
+ });
80
+ if (!identity) {
81
+ throw new HTTPException(401, { message: "unauthenticated" });
82
+ }
83
+ return identity;
84
+ }
85
+ /**
86
+ * Fail-closed (403) unless every identity segment the memory scope requires is
87
+ * present in the store `namespace`. `agent`/`none` scopes carry no per-identity
88
+ * restriction (shared or absent memory), so any namespace is allowed.
89
+ */
90
+ export function assertStoreAccess(cfg, user, value) {
91
+ const required = memoryIdentitySegments(cfg.scoping.memory, cfg.tenancy, user.mda_actor_id ? String(user.mda_actor_id) : undefined, user.mda_tenant_id ? String(user.mda_tenant_id) : undefined);
92
+ if (required.length === 0) {
93
+ return;
94
+ }
95
+ const namespace = value &&
96
+ typeof value === "object" &&
97
+ Array.isArray(value.namespace)
98
+ ? value.namespace.map(String)
99
+ : [];
100
+ for (const segment of required) {
101
+ if (!namespace.includes(segment)) {
102
+ throw new HTTPException(403, {
103
+ message: "store namespace is outside the caller's identity boundary",
104
+ });
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Resolve the caller identity for `trusted_backend`: validate the shared ingress
110
+ * secret, then trust the reserved actor/tenant headers. Fail-closed (401) on a
111
+ * missing/invalid secret, a missing actor, or a missing tenant under multi.
112
+ */
113
+ export function resolveTrustedBackendUser(cfg, request) {
114
+ requireIngressSecret(request);
115
+ const actor = request.headers.get(ACTOR_HEADER);
116
+ if (!actor) {
117
+ throw new HTTPException(401, { message: `missing ${ACTOR_HEADER}` });
118
+ }
119
+ const tenant = request.headers.get(TENANT_HEADER) ?? undefined;
120
+ assertTenantPresentIfMulti(cfg, tenant);
121
+ return {
122
+ identity: actor,
123
+ permissions: [],
124
+ mda_actor_id: actor,
125
+ ...(tenant ? { mda_tenant_id: tenant } : {}),
126
+ };
127
+ }
128
+ /** Derive the owner value `@auth.on.threads` filters on, per the `threads` axis. */
129
+ export function threadOwnerKey(cfg, user) {
130
+ const scope = cfg.scoping.threads ?? "actor";
131
+ const actor = String(user.mda_actor_id ?? "");
132
+ const tenant = user.mda_tenant_id ? String(user.mda_tenant_id) : undefined;
133
+ if (scope === "tenant") {
134
+ return tenant ?? actor;
135
+ }
136
+ if (scope === "channel") {
137
+ const channel = user.mda_source_thread_id;
138
+ return channel ? String(channel) : actor;
139
+ }
140
+ return actor;
141
+ }
142
+ function requireIngressSecret(request) {
143
+ const expected = process.env[INGRESS_SECRET_ENV];
144
+ const provided = request.headers.get(INGRESS_SECRET_HEADER);
145
+ if (!expected || !provided || !constantTimeEquals(expected, provided)) {
146
+ throw new HTTPException(401, {
147
+ message: "invalid or missing ingress secret",
148
+ });
149
+ }
150
+ }
151
+ function assertTenantPresentIfMulti(cfg, tenant) {
152
+ if (cfg.tenancy === "multi" && !tenant) {
153
+ throw new HTTPException(401, {
154
+ message: "missing tenant for multi-tenant deployment",
155
+ });
156
+ }
157
+ }
158
+ /** True when this deployment exposes guest issuance and the request targets it. */
159
+ export function isGuestIssuanceRequest(request, cfg) {
160
+ if (request.method !== "POST") {
161
+ return false;
162
+ }
163
+ const { pathname } = new URL(request.url);
164
+ if (pathname !== GUEST_ISSUANCE_PATH) {
165
+ return false;
166
+ }
167
+ const http = cfg.ingress.http;
168
+ if (http === "trusted_backend") {
169
+ return false;
170
+ }
171
+ return http.providers.some((provider) => provider.guest?.issue);
172
+ }
173
+ /** Placeholder identity so LangGraph auth middleware allows tokenless issuance. */
174
+ export function guestIssuanceBypassUser() {
175
+ return {
176
+ identity: GUEST_ISSUER_ACTOR,
177
+ permissions: [],
178
+ mda_actor_id: GUEST_ISSUER_ACTOR,
179
+ };
180
+ }
181
+ function constantTimeEquals(a, b) {
182
+ if (a.length !== b.length) {
183
+ return false;
184
+ }
185
+ let mismatch = 0;
186
+ for (let i = 0; i < a.length; i += 1) {
187
+ mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i);
188
+ }
189
+ return mismatch === 0;
190
+ }
191
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/runtime/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,aAAa,EACb,YAAY,GACb,MAAM,+BAA+B,CAAC;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;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,CAAS,EAAE,CAAS;IAC9C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,QAAQ,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,QAAQ,KAAK,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,138 @@
1
+ /**
2
+ * The managed connector protocol.
3
+ *
4
+ * A connector is any object carrying {@link CONNECTOR_BRAND} that knows how to
5
+ * contribute to a managed Deep Agent. MCP is one built-in implementation
6
+ * (contributes tools); the LangSmith connector is another (mounts HTTP routes).
7
+ * Third parties implement the same interface with their own `kind` — nothing
8
+ * about the built-ins is privileged.
9
+ *
10
+ * Discovery is name-agnostic: the CLI globs every module under `connectors/`,
11
+ * imports the single connector each one exposes as its default export, and hands
12
+ * them to {@link collectConnectors}, which validates the brand at build/startup.
13
+ * The two generated entrypoints each call the hook they care about — the agent
14
+ * graph calls {@link Connector.tools}, the managed HTTP app calls
15
+ * {@link Connector.http}.
16
+ */
17
+ import type { IdentityConfig, RuntimeIdentity } from "../identity.js";
18
+ /**
19
+ * Realm-global brand marking a value as a managed connector. `Symbol.for` keeps
20
+ * the identity stable across duplicate module instances (e.g. a connector built
21
+ * against one copy of the package and collected by another).
22
+ */
23
+ export declare const CONNECTOR_BRAND: unique symbol;
24
+ /**
25
+ * Build-time context handed to {@link Connector.tools} during agent-graph
26
+ * construction. Intentionally minimal for v0: a connector's tools close over
27
+ * their own configuration, and per-run identity flows through the existing
28
+ * runtime seam into each tool's `invoke`, not through here. Reserved for future
29
+ * deployment metadata.
30
+ */
31
+ export type ToolContext = Record<string, never>;
32
+ /**
33
+ * Request context handed to {@link Connector.http} when the managed HTTP app is
34
+ * built. The connector receives its own namespaced sub-router (collision-safe),
35
+ * the declared identity for its own authorization logic, and a
36
+ * {@link HttpContext.requireIdentity} helper that fails closed.
37
+ */
38
+ export interface HttpContext {
39
+ /**
40
+ * Router the connector mounts its routes on. Already namespaced under the
41
+ * connector, so routes cannot collide with identity/API routes or with other
42
+ * connectors. Routes registered here are **secure by default** — MDA resolves
43
+ * and enforces caller identity before the handler runs (see
44
+ * {@link HttpSubRouter}).
45
+ */
46
+ readonly router: HttpSubRouter;
47
+ /** The declared identity, for the connector's own authorization decisions. */
48
+ readonly identity?: IdentityConfig;
49
+ /**
50
+ * Resolve the caller identity from the raw request, reusing the same resolver
51
+ * as the managed auth handler. Throws a 401-style error when identity is
52
+ * absent or invalid. Secured routes already resolve identity for you; use this
53
+ * only inside a {@link HttpSubRouter.public} route that wants optional or
54
+ * conditional authentication.
55
+ */
56
+ requireIdentity(request: Request): Promise<RuntimeIdentity>;
57
+ }
58
+ /**
59
+ * The router a connector uses to register routes. Structural so the managed app
60
+ * can back it with Hono without leaking the framework type into the contract.
61
+ *
62
+ * Routes registered on this router are **secure by default**: MDA resolves the
63
+ * caller's identity (401 on failure) before invoking the handler, and passes the
64
+ * frozen {@link RuntimeIdentity} as the handler's second argument. Authorization
65
+ * (scopes, constraints, ownership) remains the connector's job.
66
+ *
67
+ * A route that must be reachable without authentication (webhooks, health
68
+ * checks, public callbacks) has to opt out **explicitly** via
69
+ * {@link HttpSubRouter.public} — the unauthenticated surface is never the
70
+ * accidental default.
71
+ */
72
+ export interface HttpSubRouter {
73
+ get(path: string, handler: SecuredRouteHandler): void;
74
+ post(path: string, handler: SecuredRouteHandler): void;
75
+ put(path: string, handler: SecuredRouteHandler): void;
76
+ delete(path: string, handler: SecuredRouteHandler): void;
77
+ /** Explicit opt-out: routes reachable without MDA identity enforcement. */
78
+ readonly public: PublicSubRouter;
79
+ }
80
+ /** The unauthenticated router surface, reached only via {@link HttpSubRouter.public}. */
81
+ export interface PublicSubRouter {
82
+ get(path: string, handler: PublicRouteHandler): void;
83
+ post(path: string, handler: PublicRouteHandler): void;
84
+ put(path: string, handler: PublicRouteHandler): void;
85
+ delete(path: string, handler: PublicRouteHandler): void;
86
+ }
87
+ /**
88
+ * Handler for a secured route. MDA has already resolved and enforced the
89
+ * caller's identity, which it passes as the second argument.
90
+ */
91
+ export type SecuredRouteHandler = (request: Request, identity: RuntimeIdentity) => Response | Promise<Response>;
92
+ /** Handler for an explicitly public route. No identity is resolved by MDA. */
93
+ export type PublicRouteHandler = (request: Request) => Response | Promise<Response>;
94
+ /** Tools a connector contributes to the agent. Kept structural (`unknown[]`). */
95
+ export type ConnectorToolList = unknown[];
96
+ /**
97
+ * A managed connector. Implement at least one of {@link Connector.tools} or
98
+ * {@link Connector.http}; a connector implementing neither does nothing and is
99
+ * rejected by {@link collectConnectors}.
100
+ */
101
+ export interface Connector {
102
+ readonly [CONNECTOR_BRAND]: true;
103
+ /** Diagnostic label, e.g. `"mcp_servers"` or `"langsmith"`. Not used for routing. */
104
+ readonly kind: string;
105
+ /** Contribute tools during agent-graph construction. MCP implements this. */
106
+ tools?(ctx: ToolContext): ConnectorToolList | Promise<ConnectorToolList>;
107
+ /** Mount HTTP routes during managed-app construction. LangSmith implements this. */
108
+ http?(ctx: HttpContext): void | Promise<void>;
109
+ }
110
+ /**
111
+ * Run the `tools` hook of every connector that implements it and concatenate the
112
+ * results, preserving connector order. Connectors without a `tools` hook (e.g.
113
+ * HTTP-only connectors) contribute nothing.
114
+ */
115
+ export declare function loadConnectorTools(connectors: readonly Connector[], ctx?: ToolContext): Promise<unknown[]>;
116
+ /** A discovered `connectors/` module paired with its source path for diagnostics. */
117
+ export interface DiscoveredConnectorModule {
118
+ /** Project-relative path of the module, used in error messages. */
119
+ readonly source: string;
120
+ /** The imported module namespace; its default export is the connector. */
121
+ readonly module: {
122
+ default?: unknown;
123
+ } & Record<string, unknown>;
124
+ }
125
+ /** Narrow an arbitrary value to a {@link Connector} by its brand and hooks. */
126
+ export declare function isConnector(value: unknown): value is Connector;
127
+ /**
128
+ * Validate and collect the connectors discovered under `connectors/`.
129
+ *
130
+ * Each module must expose exactly one connector as its default export. A module
131
+ * whose default export is missing or is not a branded connector is a hard build
132
+ * error — the file was placed under `connectors/` on purpose, so a silent no-op
133
+ * would be the worst outcome. A connector implementing neither hook is likewise
134
+ * rejected. Duplicate connector objects (re-exported from two modules) are
135
+ * de-duplicated by identity.
136
+ */
137
+ export declare function collectConnectors(modules: readonly DiscoveredConnectorModule[]): Connector[];
138
+ //# sourceMappingURL=connector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/runtime/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,MAAoC,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;IACnC;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC7D;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtD,IAAI,CAAC,IAAI,EAAE,MAAM,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;IACzE,oFAAoF;IACpF,IAAI,CAAC,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,GAAG,GAAE,WAAgB,GACpB,OAAO,CAAC,OAAO,EAAE,CAAC,CAQpB;AAED,qFAAqF;AACrF,MAAM,WAAW,yBAAyB;IACxC,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClE;AAED,+EAA+E;AAC/E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAM9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,yBAAyB,EAAE,GAC5C,SAAS,EAAE,CAoCb"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The managed connector protocol.
3
+ *
4
+ * A connector is any object carrying {@link CONNECTOR_BRAND} that knows how to
5
+ * contribute to a managed Deep Agent. MCP is one built-in implementation
6
+ * (contributes tools); the LangSmith connector is another (mounts HTTP routes).
7
+ * Third parties implement the same interface with their own `kind` — nothing
8
+ * about the built-ins is privileged.
9
+ *
10
+ * Discovery is name-agnostic: the CLI globs every module under `connectors/`,
11
+ * imports the single connector each one exposes as its default export, and hands
12
+ * them to {@link collectConnectors}, which validates the brand at build/startup.
13
+ * The two generated entrypoints each call the hook they care about — the agent
14
+ * graph calls {@link Connector.tools}, the managed HTTP app calls
15
+ * {@link Connector.http}.
16
+ */
17
+ /**
18
+ * Realm-global brand marking a value as a managed connector. `Symbol.for` keeps
19
+ * the identity stable across duplicate module instances (e.g. a connector built
20
+ * against one copy of the package and collected by another).
21
+ */
22
+ export const CONNECTOR_BRAND = Symbol.for("mda.connector");
23
+ /**
24
+ * Run the `tools` hook of every connector that implements it and concatenate the
25
+ * results, preserving connector order. Connectors without a `tools` hook (e.g.
26
+ * HTTP-only connectors) contribute nothing.
27
+ */
28
+ export async function loadConnectorTools(connectors, ctx = {}) {
29
+ const tools = [];
30
+ for (const connector of connectors) {
31
+ if (typeof connector.tools === "function") {
32
+ tools.push(...(await connector.tools(ctx)));
33
+ }
34
+ }
35
+ return tools;
36
+ }
37
+ /** Narrow an arbitrary value to a {@link Connector} by its brand and hooks. */
38
+ export function isConnector(value) {
39
+ if (typeof value !== "object" || value === null) {
40
+ return false;
41
+ }
42
+ const branded = value[CONNECTOR_BRAND];
43
+ return branded === true;
44
+ }
45
+ /**
46
+ * Validate and collect the connectors discovered under `connectors/`.
47
+ *
48
+ * Each module must expose exactly one connector as its default export. A module
49
+ * whose default export is missing or is not a branded connector is a hard build
50
+ * error — the file was placed under `connectors/` on purpose, so a silent no-op
51
+ * would be the worst outcome. A connector implementing neither hook is likewise
52
+ * rejected. Duplicate connector objects (re-exported from two modules) are
53
+ * de-duplicated by identity.
54
+ */
55
+ export function collectConnectors(modules) {
56
+ const collected = [];
57
+ const seen = new Set();
58
+ for (const { source, module } of modules) {
59
+ const candidate = module.default;
60
+ if (candidate === undefined) {
61
+ throw new Error(`${source} exports no default connector. A file under connectors/ must ` +
62
+ `\`export default\` exactly one connector (e.g. ` +
63
+ `\`export default defineMcpServers(...)\`). Move helpers outside connectors/.`);
64
+ }
65
+ if (!isConnector(candidate)) {
66
+ throw new Error(`${source} default export is not a managed connector. Export the result ` +
67
+ `of a connector builder such as \`defineMcpServers(...)\`.`);
68
+ }
69
+ if (typeof candidate.tools !== "function" &&
70
+ typeof candidate.http !== "function") {
71
+ throw new Error(`${source} default export (kind "${candidate.kind}") implements neither ` +
72
+ `\`tools\` nor \`http\` and would do nothing.`);
73
+ }
74
+ if (seen.has(candidate)) {
75
+ continue;
76
+ }
77
+ seen.add(candidate);
78
+ collected.push(candidate);
79
+ }
80
+ return collected;
81
+ }
82
+ //# sourceMappingURL=connector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector.js","sourceRoot":"","sources":["../../src/runtime/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAkB,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAqG1E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,UAAgC,EAChC,MAAmB,EAAE;IAErB,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;YAC1C,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAUD,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAI,KAAsC,CAAC,eAAe,CAAC,CAAC;IACzE,OAAO,OAAO,KAAK,IAAI,CAAC;AAC1B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA6C;IAE7C,MAAM,SAAS,GAAgB,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAa,CAAC;IAElC,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC;QACjC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,+DAA+D;gBACtE,iDAAiD;gBACjD,8EAA8E,CACjF,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,gEAAgE;gBACvE,2DAA2D,CAC9D,CAAC;QACJ,CAAC;QACD,IACE,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,EACpC,CAAC;YACD,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,0BAA0B,SAAS,CAAC,IAAI,wBAAwB;gBACvE,8CAA8C,CACjD,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACxB,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpB,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { CredentialTarget, IdentityConfig, ResolvedCredential, RuntimeIdentity } from "../identity.js";
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 declare const CREDENTIAL_SIGNING_SECRET_ENV = "MDA_TOKEN_EXCHANGE_SECRET";
18
+ /** Per-call options for {@link CredentialsProvider.for}. */
19
+ export interface CredentialForOptions {
20
+ /** Skip the cache and force a fresh mint (e.g. after a downstream 401). */
21
+ forceRefresh?: boolean;
22
+ }
23
+ /**
24
+ * The per-run credential surface a tool receives as `runtime.credentials`.
25
+ * Tools call `runtime.credentials.for(target)` and attach the returned headers
26
+ * to their downstream request.
27
+ */
28
+ export interface CredentialsProvider {
29
+ for(target: CredentialTarget, options?: CredentialForOptions): Promise<ResolvedCredential>;
30
+ }
31
+ /**
32
+ * Side effects the executor depends on, injectable so resolution is
33
+ * deterministic under test (no real clock, network, or signing key).
34
+ */
35
+ export interface CredentialDeps {
36
+ fetch: typeof fetch;
37
+ now: () => number;
38
+ /** Signs the assertion MDA presents to a hosted token-exchange endpoint. */
39
+ signAssertion: (identity: RuntimeIdentity, target: CredentialTarget) => Promise<string>;
40
+ }
41
+ /**
42
+ * TTL cache for resolved credentials, keyed by `(actor, tenant, target)` so
43
+ * per-repo/per-install tokens never collide. Kept out of thread state; entries
44
+ * expire at the credential's `expiresAt`.
45
+ */
46
+ export declare class CredentialCache {
47
+ private readonly entries;
48
+ get(key: string, nowMs: number): ResolvedCredential | undefined;
49
+ set(key: string, value: ResolvedCredential): void;
50
+ clear(): void;
51
+ }
52
+ /** Clear the process-level credential cache. Test-only. */
53
+ export declare function clearCredentialCacheForTests(): void;
54
+ /**
55
+ * Build the `runtime.credentials` provider for a run, or `undefined` when the
56
+ * deployment isn't in custom-credentials mode. The provider is bound to the
57
+ * run's resolved identity; every `for(target)` call is scoped to that actor.
58
+ */
59
+ export declare function createCredentialsProvider(cfg: IdentityConfig, identity: RuntimeIdentity | undefined, deps?: Partial<CredentialDeps>, cache?: CredentialCache): CredentialsProvider | undefined;
60
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {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