@langgraph-js/pure-graph 1.0.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.
Files changed (71) hide show
  1. package/README.md +16 -0
  2. package/dist/adapter/hono/assistants.d.ts +3 -0
  3. package/dist/adapter/hono/assistants.js +27 -0
  4. package/dist/adapter/hono/endpoint.d.ts +1 -0
  5. package/dist/adapter/hono/endpoint.js +3 -0
  6. package/dist/adapter/hono/index.d.ts +3 -0
  7. package/dist/adapter/hono/index.js +11 -0
  8. package/dist/adapter/hono/runs.d.ts +3 -0
  9. package/dist/adapter/hono/runs.js +71 -0
  10. package/dist/adapter/hono/threads.d.ts +3 -0
  11. package/dist/adapter/hono/threads.js +71 -0
  12. package/dist/adapter/hono/zod.d.ts +203 -0
  13. package/dist/adapter/hono/zod.js +43 -0
  14. package/dist/createEndpoint.d.ts +5 -0
  15. package/dist/createEndpoint.js +77 -0
  16. package/dist/global.d.ts +4 -0
  17. package/dist/global.js +5 -0
  18. package/dist/graph/stream.d.ts +39 -0
  19. package/dist/graph/stream.js +187 -0
  20. package/dist/graph/stringify.d.ts +1 -0
  21. package/dist/graph/stringify.js +214 -0
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.js +4 -0
  24. package/dist/queue/JsonPlusSerializer.d.ts +7 -0
  25. package/dist/queue/JsonPlusSerializer.js +138 -0
  26. package/dist/queue/event_message.d.ts +15 -0
  27. package/dist/queue/event_message.js +27 -0
  28. package/dist/queue/stream_queue.d.ts +161 -0
  29. package/dist/queue/stream_queue.js +175 -0
  30. package/dist/storage/index.d.ts +5 -0
  31. package/dist/storage/index.js +11 -0
  32. package/dist/storage/memory/checkpoint.d.ts +2 -0
  33. package/dist/storage/memory/checkpoint.js +2 -0
  34. package/dist/storage/memory/queue.d.ts +17 -0
  35. package/dist/storage/memory/queue.js +72 -0
  36. package/dist/storage/memory/threads.d.ts +39 -0
  37. package/dist/storage/memory/threads.js +115 -0
  38. package/dist/threads/index.d.ts +36 -0
  39. package/dist/threads/index.js +26 -0
  40. package/dist/types.d.ts +94 -0
  41. package/dist/types.js +1 -0
  42. package/dist/utils/getGraph.d.ts +10 -0
  43. package/dist/utils/getGraph.js +18 -0
  44. package/dist/utils/getLangGraphCommand.d.ts +9 -0
  45. package/dist/utils/getLangGraphCommand.js +13 -0
  46. package/package.json +39 -0
  47. package/src/adapter/hono/assistants.ts +41 -0
  48. package/src/adapter/hono/endpoint.ts +4 -0
  49. package/src/adapter/hono/index.ts +14 -0
  50. package/src/adapter/hono/runs.ts +102 -0
  51. package/src/adapter/hono/threads.ts +92 -0
  52. package/src/adapter/hono/zod.ts +49 -0
  53. package/src/createEndpoint.ts +106 -0
  54. package/src/global.ts +6 -0
  55. package/src/graph/stream.ts +253 -0
  56. package/src/graph/stringify.ts +219 -0
  57. package/src/index.ts +5 -0
  58. package/src/queue/JsonPlusSerializer.ts +143 -0
  59. package/src/queue/event_message.ts +30 -0
  60. package/src/queue/stream_queue.ts +236 -0
  61. package/src/storage/index.ts +14 -0
  62. package/src/storage/memory/checkpoint.ts +2 -0
  63. package/src/storage/memory/queue.ts +83 -0
  64. package/src/storage/memory/threads.ts +154 -0
  65. package/src/threads/index.ts +51 -0
  66. package/src/types.ts +116 -0
  67. package/src/utils/getGraph.ts +44 -0
  68. package/src/utils/getLangGraphCommand.ts +21 -0
  69. package/test/graph/index.ts +21 -0
  70. package/test/hono.ts +10 -0
  71. package/tsconfig.json +20 -0
@@ -0,0 +1,44 @@
1
+ import {
2
+ BaseCheckpointSaver,
3
+ BaseStore,
4
+ CompiledGraph,
5
+ CompiledStateGraph,
6
+ LangGraphRunnableConfig,
7
+ } from '@langchain/langgraph';
8
+ import { globalCheckPointer } from '../global';
9
+
10
+ export type CompiledGraphFactory<T extends string> = (config: {
11
+ configurable?: Record<string, unknown>;
12
+ }) => Promise<CompiledGraph<T>>;
13
+
14
+ export const GRAPHS: Record<string, CompiledGraph<string> | CompiledGraphFactory<string>> = {};
15
+
16
+ export async function registerGraph(
17
+ graphId: string,
18
+ graph: CompiledGraph<any> | CompiledStateGraph<any, any, any, any, any, any, any> | CompiledGraphFactory<any>,
19
+ ) {
20
+ GRAPHS[graphId] = graph;
21
+ }
22
+ export async function getGraph(
23
+ graphId: string,
24
+ config: LangGraphRunnableConfig | undefined,
25
+ options?: {
26
+ checkpointer?: BaseCheckpointSaver | null;
27
+ store?: BaseStore;
28
+ },
29
+ ) {
30
+ if (!GRAPHS[graphId]) throw new Error(`Graph "${graphId}" not found`);
31
+
32
+ const compiled =
33
+ typeof GRAPHS[graphId] === 'function' ? await GRAPHS[graphId](config ?? { configurable: {} }) : GRAPHS[graphId];
34
+
35
+ if (typeof options?.checkpointer !== 'undefined') {
36
+ compiled.checkpointer = options?.checkpointer ?? globalCheckPointer;
37
+ } else {
38
+ compiled.checkpointer = globalCheckPointer;
39
+ }
40
+
41
+ compiled.store = options?.store ?? undefined;
42
+
43
+ return compiled;
44
+ }
@@ -0,0 +1,21 @@
1
+ import { Command, Send } from '@langchain/langgraph';
2
+ import { Command as ClientCommand } from '@langgraph-js/sdk';
3
+ export interface RunSend {
4
+ node: string;
5
+ input?: unknown;
6
+ }
7
+
8
+ export interface RunCommand extends ClientCommand {}
9
+
10
+ export const getLangGraphCommand = (command: RunCommand) => {
11
+ let goto = command.goto != null && !Array.isArray(command.goto) ? [command.goto] : command.goto;
12
+
13
+ return new Command({
14
+ goto: goto?.map((item: string | RunSend) => {
15
+ if (typeof item !== 'string') return new Send(item.node, item.input);
16
+ return item;
17
+ }),
18
+ update: command.update ?? undefined,
19
+ resume: command.resume,
20
+ });
21
+ };
@@ -0,0 +1,21 @@
1
+ import { entrypoint, StateGraph } from '@langchain/langgraph';
2
+ import { createReactAgent, createReactAgentAnnotation } from '@langchain/langgraph/prebuilt';
3
+ import { createState } from '@langgraph-js/pro';
4
+ const state = createState(createReactAgentAnnotation()).build({});
5
+ export const graph = new StateGraph(state)
6
+ .addNode('agent', async (state) => {
7
+ await new Promise((resolve) => setTimeout(resolve, 5000));
8
+ console.log('done');
9
+ return {
10
+ messages: [
11
+ ...state.messages,
12
+ {
13
+ role: 'ai',
14
+ content: 'Hello, world!',
15
+ },
16
+ ],
17
+ };
18
+ })
19
+ .addEdge('__start__', 'agent')
20
+ .addEdge('agent', '__end__')
21
+ .compile();
package/test/hono.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { registerGraph } from '../src/createEndpoint';
2
+ import { graph } from './graph/index';
3
+ import { Hono } from 'hono';
4
+ import LangGraphApp from '../src/adapter/hono/index';
5
+ registerGraph('test', graph);
6
+
7
+ const app = new Hono();
8
+ app.route('/', LangGraphApp);
9
+
10
+ export default app;
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [],
4
+ "allowJs": true,
5
+ "skipLibCheck": true,
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "target": "esnext",
9
+ "module": "esnext",
10
+ "moduleResolution": "bundler",
11
+ "resolveJsonModule": true,
12
+ "isolatedModules": true,
13
+ "jsx": "preserve",
14
+ "incremental": true,
15
+ "outDir": "./dist",
16
+ "declaration": true
17
+ },
18
+ "include": ["src/**/*.ts"],
19
+ "exclude": ["node_modules"]
20
+ }