@lzn1998/dsh-langgraph 1.0.1 → 1.6.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 (44) hide show
  1. package/README.md +172 -51
  2. package/bench/README.md +54 -0
  3. package/bench/demo-video.mjs +208 -0
  4. package/bench/results-harness.json +125 -0
  5. package/bench/run.mjs +139 -0
  6. package/compose/analysis.js +359 -0
  7. package/compose/build.js +274 -0
  8. package/compose/constants.js +83 -0
  9. package/compose/guard.js +72 -0
  10. package/compose/nodes.js +214 -0
  11. package/compose/resolve.js +97 -0
  12. package/compose/schema.js +975 -0
  13. package/compose/specs.js +218 -0
  14. package/compose/template.js +260 -0
  15. package/compose/tool.js +713 -0
  16. package/docs/BENCHMARK.md +116 -0
  17. package/docs/COMPOSE.md +376 -0
  18. package/docs/CONTEXT.md +34 -18
  19. package/docs/DETAIL.md +48 -1
  20. package/docs/ECOSYSTEM.md +30 -5
  21. package/gallery/README.md +69 -0
  22. package/gallery/assets/gallery.png +0 -0
  23. package/gallery/assets/session.png +0 -0
  24. package/gallery/index.html +516 -0
  25. package/gallery/specs/approval-plan.lg.json +51 -0
  26. package/gallery/specs/data-extract.lg.json +75 -0
  27. package/gallery/specs/incident-triage.lg.json +64 -0
  28. package/gallery/specs/pr-review.lg.json +49 -0
  29. package/gallery/specs/repo-scan.lg.json +54 -0
  30. package/gallery/specs/research-brief.lg.json +94 -0
  31. package/index.d.ts +136 -0
  32. package/index.js +423 -46
  33. package/media/dsh-langgraph-demo.webm +0 -0
  34. package/media/raw/page@0d0adc4d6eb7b946d722093988db7e67.webm +0 -0
  35. package/media/raw/page@0fceaacbda6d8f2da8485736c565ed87.webm +0 -0
  36. package/media/raw/page@49c6bb9135c0c35ed8cf9054a8e05711.webm +0 -0
  37. package/media/raw/page@86f5e37e1c1218697f8724a6bafda8d2.webm +0 -0
  38. package/media/raw/page@9b5b70b442c0ace7d4b135fc80edba73.webm +0 -0
  39. package/media/raw/page@beb9164240f13ad017c3fa7e8f20a772.webm +0 -0
  40. package/media/raw/page@db4ee1834adcc9e8d5b4708eabe4eb5c.webm +0 -0
  41. package/media/raw/page@e9c63a0029d3181e41506fc4bf8da05a.webm +0 -0
  42. package/media/raw/page@eaf729b06925fe86e9e9e4bf48e2cdcc.webm +0 -0
  43. package/media/raw/page@f0d6fd1a2534e69bc2f228b30ae19a9c.webm +0 -0
  44. package/package.json +7 -3
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Resolve a graph id to a registry entry or a stored composed spec.
3
+ *
4
+ * Registered graphs win, so a profile graph can never be shadowed by a spec.
5
+ * Composed specs carry the same `{ id, description, input, build }` shape the
6
+ * runtime already compiles and runs; the only extra job is an owner check and a
7
+ * per-owner entry cache (specs are immutable).
8
+ */
9
+
10
+ import { LIMITS } from './constants.js'
11
+ import { analyze } from './analysis.js'
12
+ import { buildSpecGraph } from './build.js'
13
+ import { isSpecId } from './specs.js'
14
+
15
+ /** JSON Schema of one state field, for the model-facing input hint. */
16
+ function fieldSchema(definition) {
17
+ switch (definition.type) {
18
+ case 'string':
19
+ return { type: 'string' }
20
+ case 'number':
21
+ return { type: 'number' }
22
+ case 'boolean':
23
+ return { type: 'boolean' }
24
+ case 'json':
25
+ return {}
26
+ case 'string[]':
27
+ return { type: 'array', items: { type: 'string' } }
28
+ case 'number[]':
29
+ return { type: 'array', items: { type: 'number' } }
30
+ default:
31
+ return {}
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Graph input schema: every state field is optional because its default fills
37
+ * it; the defaults are shown as JSON Schema `default` annotations.
38
+ * @param {object} spec - a GraphSpec.
39
+ * @returns {object} a JSON Schema object.
40
+ */
41
+ export function inputSchemaOf(spec) {
42
+ const properties = {}
43
+ for (const [field, definition] of Object.entries(spec.state)) {
44
+ properties[field] = {
45
+ ...fieldSchema(definition),
46
+ ...(definition.default === undefined ? {} : { default: definition.default }),
47
+ }
48
+ }
49
+ return { type: 'object', properties, additionalProperties: false }
50
+ }
51
+
52
+ /**
53
+ * Create the resolver used by `langgraph_run`, `langgraph_threads`, and the
54
+ * topology route.
55
+ * @param {object} options - resolver dependencies.
56
+ * @param {Map<string, object>} options.registry - registered graph entries.
57
+ * @param {() => Promise<object | undefined> | object | undefined} options.getStore - the spec store.
58
+ * @param {Map<string, object>} [options.cache] - owner-qualified entry cache.
59
+ * @returns {(id: string, sessionId: string | undefined, options?: { allSessions?: boolean }) => Promise<object | undefined>} the resolver.
60
+ */
61
+ export function createResolver({ registry, getStore, cache = new Map() }) {
62
+ return async function resolveEntry(id, sessionId, options = {}) {
63
+ const registered = registry.get(id)
64
+ if (registered !== undefined) return registered
65
+ if (!isSpecId(id)) return undefined
66
+
67
+ const cacheKey = `${options.allSessions === true ? '*' : sessionId ?? ''}\u0000${id}`
68
+ const cached = cache.get(cacheKey)
69
+ if (cached !== undefined) return cached
70
+
71
+ const store = await getStore()
72
+ if (store === undefined) return undefined
73
+ const record = store.getRecord(id, sessionId, { allSessions: options.allSessions === true })
74
+ if (record === undefined) return undefined
75
+
76
+ const spec = record.spec
77
+ const mapLimits = spec.nodes
78
+ .filter(node => node.do === 'map')
79
+ .map(node => node.maxConcurrency ?? LIMITS.defaultMaxConcurrency)
80
+ const entry = {
81
+ id,
82
+ composed: true,
83
+ spec,
84
+ analysis: analyze(spec),
85
+ ...(typeof spec.name === 'string' ? { name: spec.name } : {}),
86
+ ...(typeof spec.description === 'string' ? { description: spec.description } : {}),
87
+ input: inputSchemaOf(spec),
88
+ build: api => buildSpecGraph(api, spec),
89
+ maxSteps: Number.isInteger(spec.maxSteps) ? spec.maxSteps : LIMITS.defaultMaxSteps,
90
+ // v1 applies the strictest map cap as the run's global LangGraph cap.
91
+ ...(mapLimits.length === 0 ? {} : { maxConcurrency: Math.min(...mapLimits) }),
92
+ ...(Array.isArray(spec.output) ? { output: spec.output } : {}),
93
+ }
94
+ cache.set(cacheKey, entry)
95
+ return entry
96
+ }
97
+ }