@skein-js/config 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @skein-js/config
2
+
3
+ > langgraph.json parser and graph loader (path:export) for skein-js.
4
+
5
+ Part of **[skein-js](https://github.com/mainawycliffe/skein)** — a TypeScript [Agent Protocol](https://github.com/langchain-ai/agent-protocol) server for [LangGraph.js](https://github.com/langchain-ai/langgraphjs), and a drop-in replacement for the LangGraph CLI.
6
+
7
+ **Status:** 🚧 Pre-alpha — implemented: `langgraph.json` loading + `path:export` graph resolution + graph-schema introspection.
8
+
9
+ ## What it does
10
+
11
+ `loadConfig()` reads an existing `langgraph.json` **unchanged**, validates it (Zod, unknown keys preserved), and returns the parsed config plus a lazy graph registry:
12
+
13
+ - **`graphs.load(id)`** resolves a `"./path:export"` entry to a runnable graph. It mirrors the LangGraph CLI's `resolveGraph` exactly — splits on the first colon, falls back to the `default` export, compiles an uncompiled `StateGraph`, unwraps the `createAgent` wrapper, and returns a factory export un-invoked so per-run config still applies — so a project moves onto skein-js with **no code change**. Loads are cached; a failed load is not memoized, so a transient error can be retried.
14
+ - **`graphs.schemas(id)`** extracts the graph's input/output/state/config JSON schemas (for assistant introspection).
15
+ - The parsed `env` / `store` / `checkpointer` / `http` fields are exposed on `config` for the CLI and adapters to wire up.
16
+
17
+ skein-js-specific `skein.json` overrides and driver selection are planned on top.
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { loadConfig } from "@skein-js/config";
23
+
24
+ const { config, graphs } = await loadConfig({ cwd: projectDir });
25
+ const graph = await graphs.load("agent"); // CompiledGraph or a per-config factory
26
+ ```
27
+
28
+ ## Reuse
29
+
30
+ Reuses `@langchain/langgraph-api`'s `./schema` parser (`getStaticGraphSchema`, `GraphSpec`) for introspection and mirrors its (non-exported) `resolveGraph` algorithm for `path:export` loading, rather than diverging from the CLI it replaces.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pnpm add @skein-js/config
36
+ ```
37
+
38
+ ## Learn more
39
+
40
+ - [skein-js overview](../../docs/index.md)
41
+ - [Reuse-first architecture](../../docs/reuse.md)
42
+ - [Roadmap](../../docs/roadmap.md)
43
+
44
+ ## License
45
+
46
+ [Apache-2.0](../../LICENSE)
@@ -0,0 +1,364 @@
1
+ import { GraphSpec, GraphSchema } from '@langchain/langgraph-api/schema';
2
+ export { GraphSpec } from '@langchain/langgraph-api/schema';
3
+ import { CompiledGraph } from '@langchain/langgraph';
4
+ import { z } from 'zod';
5
+ import { AuthEngine } from '@skein-js/core';
6
+
7
+ /**
8
+ * How a graph module is loaded from its absolute source path. Defaults to a native dynamic
9
+ * `import()`, but `skein dev` injects a vite-backed importer so TypeScript graphs load (and
10
+ * hot-reload) through vite's transform pipeline without a separate TS loader process.
11
+ */
12
+ type ModuleImporter = (sourceFile: string) => Promise<Record<string, unknown>>;
13
+ /** A factory export: called (optionally with config) to produce a compiled graph. */
14
+ type CompiledGraphFactory = (config: {
15
+ configurable?: Record<string, unknown>;
16
+ }) => CompiledGraph<string> | Promise<CompiledGraph<string>>;
17
+ /** A resolved graph: either a compiled graph or a factory that produces one per config. */
18
+ type ResolvedGraph = CompiledGraph<string> | CompiledGraphFactory;
19
+ /**
20
+ * Parse `"path:export"` into an absolute {@link GraphSpec}, resolving the path against
21
+ * `baseDir`. Mirrors LangGraph's `spec.split(":", 2)` + `exportSymbol || "default"`, so
22
+ * `"./src/agent.ts:graph"` → `{ sourceFile: "<baseDir>/src/agent.ts", exportSymbol: "graph" }`
23
+ * and a colon-less `"./src/agent.ts"` resolves to that module's default export.
24
+ */
25
+ declare function parseGraphSpec(spec: string, baseDir: string): GraphSpec;
26
+ /**
27
+ * Load the graph for a spec: import the module, read the export (falling back to `default`),
28
+ * and resolve it. A compiled-graph export is returned ready to run; a factory export is
29
+ * returned un-invoked (as a {@link CompiledGraphFactory}) so the caller can supply per-run
30
+ * config, exactly as LangGraph does.
31
+ */
32
+ declare function loadGraph(spec: GraphSpec, importModule?: ModuleImporter): Promise<ResolvedGraph>;
33
+
34
+ declare const langgraphJsonSchema: z.ZodObject<{
35
+ /** REQUIRED: map of graph id → "path:export". */
36
+ graphs: z.ZodRecord<z.ZodString, z.ZodString>;
37
+ /** JS/Node runtime pin (used by `skein build` / `dockerfile`). */
38
+ node_version: z.ZodOptional<z.ZodString>;
39
+ /** `.env` path or an inline map, loaded into `process.env` at boot. */
40
+ env: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
41
+ /** Long-term memory store config. */
42
+ store: z.ZodOptional<z.ZodObject<{
43
+ index: z.ZodOptional<z.ZodObject<{
44
+ embed: z.ZodOptional<z.ZodString>;
45
+ dims: z.ZodOptional<z.ZodNumber>;
46
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
47
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
48
+ embed: z.ZodOptional<z.ZodString>;
49
+ dims: z.ZodOptional<z.ZodNumber>;
50
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
51
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
52
+ embed: z.ZodOptional<z.ZodString>;
53
+ dims: z.ZodOptional<z.ZodNumber>;
54
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
55
+ }, z.ZodTypeAny, "passthrough">>>;
56
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
57
+ index: z.ZodOptional<z.ZodObject<{
58
+ embed: z.ZodOptional<z.ZodString>;
59
+ dims: z.ZodOptional<z.ZodNumber>;
60
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
61
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
62
+ embed: z.ZodOptional<z.ZodString>;
63
+ dims: z.ZodOptional<z.ZodNumber>;
64
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
65
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
66
+ embed: z.ZodOptional<z.ZodString>;
67
+ dims: z.ZodOptional<z.ZodNumber>;
68
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
69
+ }, z.ZodTypeAny, "passthrough">>>;
70
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
71
+ index: z.ZodOptional<z.ZodObject<{
72
+ embed: z.ZodOptional<z.ZodString>;
73
+ dims: z.ZodOptional<z.ZodNumber>;
74
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
75
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
76
+ embed: z.ZodOptional<z.ZodString>;
77
+ dims: z.ZodOptional<z.ZodNumber>;
78
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
79
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
80
+ embed: z.ZodOptional<z.ZodString>;
81
+ dims: z.ZodOptional<z.ZodNumber>;
82
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
83
+ }, z.ZodTypeAny, "passthrough">>>;
84
+ }, z.ZodTypeAny, "passthrough">>>;
85
+ /** Checkpointer backend; `"default"` == Postgres, absent == in-memory. */
86
+ checkpointer: z.ZodOptional<z.ZodObject<{
87
+ type: z.ZodString;
88
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
89
+ type: z.ZodString;
90
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
91
+ type: z.ZodString;
92
+ }, z.ZodTypeAny, "passthrough">>>;
93
+ /** Server customization (CORS, route toggles) applied by the framework adapter. */
94
+ http: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
95
+ /**
96
+ * Custom authentication + authorization. `path` is a `"file:export"` spec pointing at a module
97
+ * that default-exports (or named-exports) an `@langchain/langgraph-sdk/auth` `Auth` instance;
98
+ * when absent, every request is allowed (unauthenticated — the current behavior). Matches the
99
+ * LangGraph CLI's `auth` block, including `disable_studio_auth`.
100
+ */
101
+ auth: z.ZodOptional<z.ZodObject<{
102
+ path: z.ZodString;
103
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
104
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
105
+ path: z.ZodString;
106
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
107
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
108
+ path: z.ZodString;
109
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
110
+ }, z.ZodTypeAny, "passthrough">>>;
111
+ /** Extra lines appended by `skein dockerfile` / `build`. */
112
+ dockerfile_lines: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
113
+ /** Dependency hints for image builds. */
114
+ dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
115
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
116
+ /** REQUIRED: map of graph id → "path:export". */
117
+ graphs: z.ZodRecord<z.ZodString, z.ZodString>;
118
+ /** JS/Node runtime pin (used by `skein build` / `dockerfile`). */
119
+ node_version: z.ZodOptional<z.ZodString>;
120
+ /** `.env` path or an inline map, loaded into `process.env` at boot. */
121
+ env: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
122
+ /** Long-term memory store config. */
123
+ store: z.ZodOptional<z.ZodObject<{
124
+ index: z.ZodOptional<z.ZodObject<{
125
+ embed: z.ZodOptional<z.ZodString>;
126
+ dims: z.ZodOptional<z.ZodNumber>;
127
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
128
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
129
+ embed: z.ZodOptional<z.ZodString>;
130
+ dims: z.ZodOptional<z.ZodNumber>;
131
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
132
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
133
+ embed: z.ZodOptional<z.ZodString>;
134
+ dims: z.ZodOptional<z.ZodNumber>;
135
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
136
+ }, z.ZodTypeAny, "passthrough">>>;
137
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
138
+ index: z.ZodOptional<z.ZodObject<{
139
+ embed: z.ZodOptional<z.ZodString>;
140
+ dims: z.ZodOptional<z.ZodNumber>;
141
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
142
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
143
+ embed: z.ZodOptional<z.ZodString>;
144
+ dims: z.ZodOptional<z.ZodNumber>;
145
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
146
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
147
+ embed: z.ZodOptional<z.ZodString>;
148
+ dims: z.ZodOptional<z.ZodNumber>;
149
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
150
+ }, z.ZodTypeAny, "passthrough">>>;
151
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
152
+ index: z.ZodOptional<z.ZodObject<{
153
+ embed: z.ZodOptional<z.ZodString>;
154
+ dims: z.ZodOptional<z.ZodNumber>;
155
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
156
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
157
+ embed: z.ZodOptional<z.ZodString>;
158
+ dims: z.ZodOptional<z.ZodNumber>;
159
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
160
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
161
+ embed: z.ZodOptional<z.ZodString>;
162
+ dims: z.ZodOptional<z.ZodNumber>;
163
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
164
+ }, z.ZodTypeAny, "passthrough">>>;
165
+ }, z.ZodTypeAny, "passthrough">>>;
166
+ /** Checkpointer backend; `"default"` == Postgres, absent == in-memory. */
167
+ checkpointer: z.ZodOptional<z.ZodObject<{
168
+ type: z.ZodString;
169
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
170
+ type: z.ZodString;
171
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
172
+ type: z.ZodString;
173
+ }, z.ZodTypeAny, "passthrough">>>;
174
+ /** Server customization (CORS, route toggles) applied by the framework adapter. */
175
+ http: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
176
+ /**
177
+ * Custom authentication + authorization. `path` is a `"file:export"` spec pointing at a module
178
+ * that default-exports (or named-exports) an `@langchain/langgraph-sdk/auth` `Auth` instance;
179
+ * when absent, every request is allowed (unauthenticated — the current behavior). Matches the
180
+ * LangGraph CLI's `auth` block, including `disable_studio_auth`.
181
+ */
182
+ auth: z.ZodOptional<z.ZodObject<{
183
+ path: z.ZodString;
184
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
185
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
186
+ path: z.ZodString;
187
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
188
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
189
+ path: z.ZodString;
190
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
191
+ }, z.ZodTypeAny, "passthrough">>>;
192
+ /** Extra lines appended by `skein dockerfile` / `build`. */
193
+ dockerfile_lines: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
194
+ /** Dependency hints for image builds. */
195
+ dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
196
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
197
+ /** REQUIRED: map of graph id → "path:export". */
198
+ graphs: z.ZodRecord<z.ZodString, z.ZodString>;
199
+ /** JS/Node runtime pin (used by `skein build` / `dockerfile`). */
200
+ node_version: z.ZodOptional<z.ZodString>;
201
+ /** `.env` path or an inline map, loaded into `process.env` at boot. */
202
+ env: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
203
+ /** Long-term memory store config. */
204
+ store: z.ZodOptional<z.ZodObject<{
205
+ index: z.ZodOptional<z.ZodObject<{
206
+ embed: z.ZodOptional<z.ZodString>;
207
+ dims: z.ZodOptional<z.ZodNumber>;
208
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
209
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
210
+ embed: z.ZodOptional<z.ZodString>;
211
+ dims: z.ZodOptional<z.ZodNumber>;
212
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
213
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
214
+ embed: z.ZodOptional<z.ZodString>;
215
+ dims: z.ZodOptional<z.ZodNumber>;
216
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
217
+ }, z.ZodTypeAny, "passthrough">>>;
218
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
219
+ index: z.ZodOptional<z.ZodObject<{
220
+ embed: z.ZodOptional<z.ZodString>;
221
+ dims: z.ZodOptional<z.ZodNumber>;
222
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
223
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
224
+ embed: z.ZodOptional<z.ZodString>;
225
+ dims: z.ZodOptional<z.ZodNumber>;
226
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
227
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
228
+ embed: z.ZodOptional<z.ZodString>;
229
+ dims: z.ZodOptional<z.ZodNumber>;
230
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
231
+ }, z.ZodTypeAny, "passthrough">>>;
232
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
233
+ index: z.ZodOptional<z.ZodObject<{
234
+ embed: z.ZodOptional<z.ZodString>;
235
+ dims: z.ZodOptional<z.ZodNumber>;
236
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
237
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
238
+ embed: z.ZodOptional<z.ZodString>;
239
+ dims: z.ZodOptional<z.ZodNumber>;
240
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
241
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
242
+ embed: z.ZodOptional<z.ZodString>;
243
+ dims: z.ZodOptional<z.ZodNumber>;
244
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
245
+ }, z.ZodTypeAny, "passthrough">>>;
246
+ }, z.ZodTypeAny, "passthrough">>>;
247
+ /** Checkpointer backend; `"default"` == Postgres, absent == in-memory. */
248
+ checkpointer: z.ZodOptional<z.ZodObject<{
249
+ type: z.ZodString;
250
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
251
+ type: z.ZodString;
252
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
253
+ type: z.ZodString;
254
+ }, z.ZodTypeAny, "passthrough">>>;
255
+ /** Server customization (CORS, route toggles) applied by the framework adapter. */
256
+ http: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
257
+ /**
258
+ * Custom authentication + authorization. `path` is a `"file:export"` spec pointing at a module
259
+ * that default-exports (or named-exports) an `@langchain/langgraph-sdk/auth` `Auth` instance;
260
+ * when absent, every request is allowed (unauthenticated — the current behavior). Matches the
261
+ * LangGraph CLI's `auth` block, including `disable_studio_auth`.
262
+ */
263
+ auth: z.ZodOptional<z.ZodObject<{
264
+ path: z.ZodString;
265
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
266
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
267
+ path: z.ZodString;
268
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
269
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
270
+ path: z.ZodString;
271
+ disable_studio_auth: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
272
+ }, z.ZodTypeAny, "passthrough">>>;
273
+ /** Extra lines appended by `skein dockerfile` / `build`. */
274
+ dockerfile_lines: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
275
+ /** Dependency hints for image builds. */
276
+ dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
277
+ }, z.ZodTypeAny, "passthrough">>;
278
+ /** The validated `langgraph.json` shape (unknown keys preserved via passthrough). */
279
+ type LanggraphJson = z.infer<typeof langgraphJsonSchema>;
280
+ /** Validate parsed JSON against the {@link langgraphJsonSchema}, throwing on any violation. */
281
+ declare function parseLanggraphJson(raw: unknown): LanggraphJson;
282
+
283
+ /** JSON schemas extracted from a graph (and any subgraphs), keyed by subgraph namespace. */
284
+ type GraphSchemas = Record<string, GraphSchema>;
285
+ /** The graphs declared in `langgraph.json`, resolved and loadable on demand. */
286
+ interface GraphRegistry {
287
+ /** Declared graph ids, in config order. */
288
+ readonly ids: string[];
289
+ /** The resolved absolute spec for a graph id. Throws if the id is unknown. */
290
+ spec(graphId: string): GraphSpec;
291
+ /** Load (and cache) the resolved graph for an id — a compiled graph or a per-config factory. */
292
+ load(graphId: string): Promise<ResolvedGraph>;
293
+ /** Extract the graph's JSON schemas via langgraph-api (for assistant introspection). */
294
+ schemas(graphId: string): Promise<GraphSchemas>;
295
+ }
296
+ interface SkeinConfig {
297
+ /** The validated `langgraph.json` contents. */
298
+ config: LanggraphJson;
299
+ /** Absolute path to the loaded `langgraph.json`. */
300
+ configPath: string;
301
+ /** Directory holding `langgraph.json` — the base for resolving graph paths + `env`. */
302
+ configDir: string;
303
+ /** The declared graphs. */
304
+ graphs: GraphRegistry;
305
+ }
306
+ interface LoadConfigOptions {
307
+ /** Directory to resolve `configPath` (and default discovery) against. Defaults to `process.cwd()`. */
308
+ cwd?: string;
309
+ /** Path to a `langgraph.json`, absolute or relative to `cwd`. Defaults to `langgraph.json`. */
310
+ configPath?: string;
311
+ /**
312
+ * How graph modules are imported for execution. Defaults to a native dynamic `import()`. `skein
313
+ * dev` injects a vite-backed importer so TypeScript graphs load and hot-reload through vite
314
+ * without a separate TS-loader process. Schema introspection is unaffected — it statically
315
+ * analyses the TypeScript source and never executes the module.
316
+ */
317
+ importModule?: ModuleImporter;
318
+ }
319
+ declare function loadConfig(options?: LoadConfigOptions): Promise<SkeinConfig>;
320
+
321
+ /**
322
+ * Parse `.env` file text into a key→value map. Supports blank lines, `#` comments, an optional
323
+ * leading `export `, and single- or double-quoted values (quotes stripped). Later keys win.
324
+ */
325
+ declare function parseEnvFile(text: string): Record<string, string>;
326
+ /**
327
+ * Resolve `config.env` to a key→value map. An inline map is returned as-is; a string is treated
328
+ * as a `.env` path relative to `configDir` and parsed. A missing declared file resolves to `{}`
329
+ * (a common, tolerable dev state) — the caller can warn. No `env` field also yields `{}`.
330
+ */
331
+ declare function resolveEnv(config: LanggraphJson, configDir: string): Promise<Record<string, string>>;
332
+
333
+ /** The `auth` block from a parsed `langgraph.json` (see `langgraphJsonSchema`). */
334
+ interface AuthConfig {
335
+ path: string;
336
+ disable_studio_auth?: boolean;
337
+ }
338
+ /** Where and how to load the auth module — mirrors `loadGraph`'s importer seam. */
339
+ interface LoadAuthEngineOptions {
340
+ /** Directory the `auth.path` is resolved against (the `langgraph.json` location). */
341
+ configDir: string;
342
+ /** Module importer (native ESM by default; `skein dev` injects the vite-backed one). */
343
+ importModule?: ModuleImporter;
344
+ }
345
+ /**
346
+ * Load the auth engine declared by a `langgraph.json` `auth` block, or `undefined` when no `auth`
347
+ * is configured (unauthenticated — the default). Imports the `path:export` module, validates it is
348
+ * an `@langchain/langgraph-sdk` `Auth` instance, and adapts it to the injectable {@link AuthEngine}.
349
+ */
350
+ declare function loadAuthEngine(auth: AuthConfig | undefined, options: LoadAuthEngineOptions): Promise<AuthEngine | undefined>;
351
+
352
+ interface SkeinConfigErrorOptions {
353
+ /** Underlying error (JSON parse failure, import failure, …). */
354
+ cause?: unknown;
355
+ /** Structured detail — e.g. Zod validation issues. */
356
+ details?: unknown;
357
+ }
358
+ /** A problem loading or validating skein-js configuration. */
359
+ declare class SkeinConfigError extends Error {
360
+ readonly details?: unknown;
361
+ constructor(message: string, options?: SkeinConfigErrorOptions);
362
+ }
363
+
364
+ export { type AuthConfig, type CompiledGraphFactory, type GraphRegistry, type GraphSchemas, type LanggraphJson, type LoadAuthEngineOptions, type LoadConfigOptions, type ModuleImporter, type ResolvedGraph, type SkeinConfig, SkeinConfigError, type SkeinConfigErrorOptions, langgraphJsonSchema, loadAuthEngine, loadConfig, loadGraph, parseEnvFile, parseGraphSpec, parseLanggraphJson, resolveEnv };
package/dist/index.js ADDED
@@ -0,0 +1,324 @@
1
+ // src/load-config.ts
2
+ import { readFile } from "fs/promises";
3
+ import path2 from "path";
4
+ import {
5
+ getStaticGraphSchema
6
+ } from "@langchain/langgraph-api/schema";
7
+
8
+ // src/errors.ts
9
+ var SkeinConfigError = class extends Error {
10
+ details;
11
+ constructor(message, options = {}) {
12
+ super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
13
+ this.name = "SkeinConfigError";
14
+ this.details = options.details;
15
+ }
16
+ };
17
+
18
+ // src/graph-spec.ts
19
+ import path from "path";
20
+ import { pathToFileURL } from "url";
21
+ var nativeImport = (sourceFile) => import(pathToFileURL(sourceFile).href);
22
+ function parseGraphSpec(spec, baseDir) {
23
+ const [userFile, exportSymbol] = spec.split(":", 2);
24
+ if (!userFile) {
25
+ throw new SkeinConfigError(`Invalid graph spec "${spec}" \u2014 expected "path:export".`);
26
+ }
27
+ return {
28
+ sourceFile: path.resolve(baseDir, userFile),
29
+ exportSymbol: exportSymbol || "default"
30
+ };
31
+ }
32
+ function isUncompiledBuilder(value) {
33
+ return typeof value === "object" && value !== null && "compile" in value && typeof value.compile === "function";
34
+ }
35
+ function isCompiledGraphLike(value) {
36
+ return typeof value === "object" && value !== null && "builder" in value && typeof value.builder === "object" && value.builder !== null;
37
+ }
38
+ function afterResolve(graphLike) {
39
+ const graph = isUncompiledBuilder(graphLike) ? graphLike.compile() : graphLike;
40
+ const inner = graph.graph;
41
+ if (inner != null && typeof inner === "object" && isCompiledGraphLike(inner)) {
42
+ return inner;
43
+ }
44
+ return graph;
45
+ }
46
+ async function loadGraph(spec, importModule = nativeImport) {
47
+ let module;
48
+ try {
49
+ module = await importModule(spec.sourceFile);
50
+ } catch (cause) {
51
+ throw new SkeinConfigError(`Failed to import graph module "${spec.sourceFile}".`, { cause });
52
+ }
53
+ const exportSymbol = spec.exportSymbol || "default";
54
+ const exported = module[exportSymbol];
55
+ if (exported == null) {
56
+ throw new SkeinConfigError(`Module "${spec.sourceFile}" has no export "${exportSymbol}".`);
57
+ }
58
+ if (typeof exported === "function") {
59
+ const factory = exported;
60
+ return async (config) => afterResolve(await factory(config));
61
+ }
62
+ return afterResolve(exported);
63
+ }
64
+
65
+ // src/langgraph-json.ts
66
+ import { z } from "zod";
67
+ var storeIndexSchema = z.object({
68
+ embed: z.string().optional(),
69
+ dims: z.number().optional(),
70
+ fields: z.array(z.string()).optional()
71
+ }).passthrough();
72
+ var langgraphJsonSchema = z.object({
73
+ /** REQUIRED: map of graph id → "path:export". */
74
+ graphs: z.record(z.string()),
75
+ /** JS/Node runtime pin (used by `skein build` / `dockerfile`). */
76
+ node_version: z.string().optional(),
77
+ /** `.env` path or an inline map, loaded into `process.env` at boot. */
78
+ env: z.union([z.string(), z.record(z.string())]).optional(),
79
+ /** Long-term memory store config. */
80
+ store: z.object({ index: storeIndexSchema.optional() }).passthrough().optional(),
81
+ /** Checkpointer backend; `"default"` == Postgres, absent == in-memory. */
82
+ checkpointer: z.object({ type: z.string() }).passthrough().optional(),
83
+ /** Server customization (CORS, route toggles) applied by the framework adapter. */
84
+ http: z.object({}).passthrough().optional(),
85
+ /**
86
+ * Custom authentication + authorization. `path` is a `"file:export"` spec pointing at a module
87
+ * that default-exports (or named-exports) an `@langchain/langgraph-sdk/auth` `Auth` instance;
88
+ * when absent, every request is allowed (unauthenticated — the current behavior). Matches the
89
+ * LangGraph CLI's `auth` block, including `disable_studio_auth`.
90
+ */
91
+ auth: z.object({
92
+ path: z.string(),
93
+ disable_studio_auth: z.boolean().optional().default(false)
94
+ }).passthrough().optional(),
95
+ /** Extra lines appended by `skein dockerfile` / `build`. */
96
+ dockerfile_lines: z.array(z.string()).optional(),
97
+ /** Dependency hints for image builds. */
98
+ dependencies: z.array(z.string()).optional()
99
+ }).passthrough();
100
+ function parseLanggraphJson(raw) {
101
+ const result = langgraphJsonSchema.safeParse(raw);
102
+ if (!result.success) {
103
+ throw new SkeinConfigError("Invalid langgraph.json.", {
104
+ cause: result.error,
105
+ details: result.error.issues
106
+ });
107
+ }
108
+ return result.data;
109
+ }
110
+
111
+ // src/load-config.ts
112
+ async function readJsonFile(filePath) {
113
+ let text;
114
+ try {
115
+ text = await readFile(filePath, "utf8");
116
+ } catch (cause) {
117
+ throw new SkeinConfigError(`Could not read langgraph.json at "${filePath}".`, { cause });
118
+ }
119
+ try {
120
+ return JSON.parse(text);
121
+ } catch (cause) {
122
+ throw new SkeinConfigError(`langgraph.json at "${filePath}" is not valid JSON.`, { cause });
123
+ }
124
+ }
125
+ async function loadConfig(options = {}) {
126
+ const cwd = options.cwd ?? process.cwd();
127
+ const configPath = path2.resolve(cwd, options.configPath ?? "langgraph.json");
128
+ const configDir = path2.dirname(configPath);
129
+ const { importModule } = options;
130
+ const config = parseLanggraphJson(await readJsonFile(configPath));
131
+ const specs = /* @__PURE__ */ new Map();
132
+ for (const [graphId, spec] of Object.entries(config.graphs)) {
133
+ specs.set(graphId, parseGraphSpec(spec, configDir));
134
+ }
135
+ const graphCache = /* @__PURE__ */ new Map();
136
+ const schemaCache = /* @__PURE__ */ new Map();
137
+ const specFor = (graphId) => {
138
+ const spec = specs.get(graphId);
139
+ if (!spec) throw new SkeinConfigError(`Unknown graph "${graphId}".`);
140
+ return spec;
141
+ };
142
+ const memoize = (cache, graphId, work) => {
143
+ const cached = cache.get(graphId);
144
+ if (cached) return cached;
145
+ const pending = work().catch((error) => {
146
+ cache.delete(graphId);
147
+ throw error;
148
+ });
149
+ cache.set(graphId, pending);
150
+ return pending;
151
+ };
152
+ const graphs = {
153
+ ids: [...specs.keys()],
154
+ spec: specFor,
155
+ // async so an unknown id (specFor throwing) surfaces as a rejection, never a synchronous
156
+ // throw — callers uniformly `await graphs.load(id)`.
157
+ async load(graphId) {
158
+ const spec = specFor(graphId);
159
+ return memoize(graphCache, graphId, () => loadGraph(spec, importModule));
160
+ },
161
+ async schemas(graphId) {
162
+ const spec = specFor(graphId);
163
+ return memoize(schemaCache, graphId, () => getStaticGraphSchema(spec));
164
+ }
165
+ };
166
+ return { config, configPath, configDir, graphs };
167
+ }
168
+
169
+ // src/resolve-env.ts
170
+ import { readFile as readFile2 } from "fs/promises";
171
+ import path3 from "path";
172
+ function parseEnvFile(text) {
173
+ const env = {};
174
+ for (const rawLine of text.split(/\r?\n/)) {
175
+ const line = rawLine.trim();
176
+ if (line === "" || line.startsWith("#")) continue;
177
+ const withoutExport = line.startsWith("export ") ? line.slice("export ".length) : line;
178
+ const eq = withoutExport.indexOf("=");
179
+ if (eq === -1) continue;
180
+ const key = withoutExport.slice(0, eq).trim();
181
+ if (key === "") continue;
182
+ let value = withoutExport.slice(eq + 1).trim();
183
+ const quote = value[0];
184
+ if ((quote === '"' || quote === "'") && value.endsWith(quote) && value.length >= 2) {
185
+ value = value.slice(1, -1);
186
+ }
187
+ env[key] = value;
188
+ }
189
+ return env;
190
+ }
191
+ async function resolveEnv(config, configDir) {
192
+ const { env } = config;
193
+ if (env === void 0) return {};
194
+ if (typeof env !== "string") return { ...env };
195
+ const envPath = path3.resolve(configDir, env);
196
+ let text;
197
+ try {
198
+ text = await readFile2(envPath, "utf8");
199
+ } catch {
200
+ return {};
201
+ }
202
+ return parseEnvFile(text);
203
+ }
204
+
205
+ // src/auth-engine.ts
206
+ import { pathToFileURL as pathToFileURL2 } from "url";
207
+ import { isAuthMatching } from "@langchain/langgraph-api/auth";
208
+ import { SkeinHttpError } from "@skein-js/core";
209
+ function isAuthInstance(value) {
210
+ return typeof value === "object" && value !== null && "~handlerCache" in value;
211
+ }
212
+ function isHttpException(error) {
213
+ return typeof error === "object" && error !== null && "status" in error && "headers" in error;
214
+ }
215
+ function toSkeinError(error) {
216
+ if (isHttpException(error)) {
217
+ throw new SkeinHttpError(error.status, error.message || "Unauthorized", { cause: error });
218
+ }
219
+ throw error;
220
+ }
221
+ function normalizeUser(response) {
222
+ if (typeof response === "string") {
223
+ const user = {
224
+ identity: response,
225
+ display_name: response,
226
+ is_authenticated: true,
227
+ permissions: []
228
+ };
229
+ return { user, scopes: [] };
230
+ }
231
+ if (typeof response === "object" && response !== null && "identity" in response && typeof response.identity === "string") {
232
+ const raw = response;
233
+ const scopes = Array.isArray(raw.permissions) ? raw.permissions : [];
234
+ const user = {
235
+ ...raw,
236
+ permissions: scopes,
237
+ is_authenticated: typeof raw.is_authenticated === "boolean" ? raw.is_authenticated : true,
238
+ display_name: typeof raw.display_name === "string" ? raw.display_name : raw.identity
239
+ };
240
+ return { user, scopes };
241
+ }
242
+ throw new SkeinHttpError(
243
+ 500,
244
+ "Invalid auth response \u2014 return a string identity or an object with an `identity` property."
245
+ );
246
+ }
247
+ function createAuthEngine(handlers, studioAuthDisabled) {
248
+ return {
249
+ enabled: true,
250
+ studioAuthDisabled,
251
+ async authenticate(request) {
252
+ if (!handlers.authenticate) return void 0;
253
+ try {
254
+ return normalizeUser(await handlers.authenticate(request));
255
+ } catch (error) {
256
+ toSkeinError(error);
257
+ }
258
+ },
259
+ async authorize({ resource, action, value, context }) {
260
+ const callbacks = handlers.callbacks;
261
+ const key = [`${resource}:${action}`, resource, `*:${action}`, "*"].find(
262
+ (candidate) => callbacks?.[candidate]
263
+ );
264
+ const handler = key ? callbacks?.[key] : void 0;
265
+ if (!handler || !context) return { filters: void 0, value };
266
+ try {
267
+ const result = await handler({
268
+ event: `${resource}:${action}`,
269
+ resource,
270
+ action,
271
+ value,
272
+ user: context.user,
273
+ permissions: context.scopes
274
+ });
275
+ if (result == null || result === true) return { filters: void 0, value };
276
+ if (result === false) throw new SkeinHttpError(403, "Forbidden.");
277
+ if (typeof result !== "object") {
278
+ throw new SkeinHttpError(
279
+ 500,
280
+ `Auth handler returned an invalid result \u2014 expected a filter object, null, or a boolean, got "${typeof result}".`
281
+ );
282
+ }
283
+ return { filters: result, value };
284
+ } catch (error) {
285
+ toSkeinError(error);
286
+ }
287
+ },
288
+ matchesFilters(metadata, filters) {
289
+ return isAuthMatching(metadata, filters);
290
+ }
291
+ };
292
+ }
293
+ async function loadAuthEngine(auth, options) {
294
+ if (!auth) return void 0;
295
+ const spec = parseGraphSpec(auth.path, options.configDir);
296
+ const importModule = options.importModule ?? ((file) => import(pathToFileURL2(file).href));
297
+ let module;
298
+ try {
299
+ module = await importModule(spec.sourceFile);
300
+ } catch (cause) {
301
+ throw new SkeinConfigError(`Failed to import auth module "${spec.sourceFile}".`, { cause });
302
+ }
303
+ const exported = module[spec.exportSymbol];
304
+ if (exported == null) {
305
+ throw new SkeinConfigError(`Auth module "${spec.sourceFile}" has no export "${spec.exportSymbol}".`);
306
+ }
307
+ if (!isAuthInstance(exported)) {
308
+ throw new SkeinConfigError(
309
+ `Auth export "${auth.path}" is not an \`Auth\` instance from \`@langchain/langgraph-sdk/auth\`.`
310
+ );
311
+ }
312
+ return createAuthEngine(exported["~handlerCache"], auth.disable_studio_auth ?? false);
313
+ }
314
+ export {
315
+ SkeinConfigError,
316
+ langgraphJsonSchema,
317
+ loadAuthEngine,
318
+ loadConfig,
319
+ loadGraph,
320
+ parseEnvFile,
321
+ parseGraphSpec,
322
+ parseLanggraphJson,
323
+ resolveEnv
324
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@skein-js/config",
3
+ "version": "0.1.0",
4
+ "description": "langgraph.json parser and graph loader (path:export) for skein-js.",
5
+ "license": "Apache-2.0",
6
+ "author": "Maina Wycliffe <wmmaina7@gmail.com>",
7
+ "homepage": "https://github.com/mainawycliffe/skein/tree/main/packages/config#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/mainawycliffe/skein.git",
11
+ "directory": "packages/config"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/mainawycliffe/skein/issues"
15
+ },
16
+ "keywords": [
17
+ "langgraph",
18
+ "langgraph.json",
19
+ "config",
20
+ "agent-protocol"
21
+ ],
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "LICENSE",
35
+ "README.md"
36
+ ],
37
+ "sideEffects": false,
38
+ "engines": {
39
+ "node": ">=20"
40
+ },
41
+ "dependencies": {
42
+ "@langchain/langgraph-api": "^1.4.0",
43
+ "zod": "^3.25.76",
44
+ "@skein-js/core": "0.1.0"
45
+ },
46
+ "peerDependencies": {
47
+ "@langchain/langgraph": "^1.4.0",
48
+ "@langchain/langgraph-sdk": "^1.9.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }