@xbbg/langgraph 1.2.7 → 1.3.1

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/README.md CHANGED
@@ -140,12 +140,12 @@ Core Bloomberg request tools:
140
140
  - `xbbg_mktbar_snapshot` - bounded `//blp/mktbar` live bar observation for one ticker.
141
141
  - `xbbg_depth_snapshot` - bounded `//blp/mktdepthdata` market-depth observation for one ticker.
142
142
 
143
- For raw identifiers, ask for or pass Bloomberg's identifier syntax directly: `/isin/<ISIN>` for ISINs and `/cusip/<CUSIP>` for CUSIPs.
143
+ Securities are passed through in the form the user supplied them: Bloomberg tickers as `<TICKER> <MARKET_SECTOR>` (for example `<TICKER> <EXCHANGE> Equity`, `<INDEX_TICKER> Index`, `<CCY_PAIR> Curncy`), raw ISINs as `/isin/<ISIN>`, raw CUSIPs as `/cusip/<CUSIP>`. The market sector ending is Bloomberg's yellow key — `Equity`, `Index`, `Curncy`, `Comdty`, `Corp`, `Govt`, `Muni`, `Mtge`, `M-Mkt`, or `Pfd` (preferred securities) — and request tools pass it through to Bloomberg unvalidated. The agent guidance and every securities/ticker field description instruct the model that the ticker format is a template, not authorization to construct one — identifiers are never converted into guessed tickers; `xbbg_resolve_isins` exists for explicit resolution. Note `xbbg_ext_ticker`'s `parse_ticker` is narrower than the request tools: it parses generic futures-style tickers only (`Index`/`Curncy`/`Comdty`/`Corp`, or `<ROOT><N> <EXCHANGE> Equity`) and rejects other sectors.
144
144
  BQL is passed as one complete expression string. Use placeholder shapes such as `get(<FIELD>) for('<TICKER> <MARKET_SECTOR>')`, `get(<FIELD_1>, <FIELD_2>) for(['<TICKER_1> <MARKET_SECTOR>', '<TICKER_2> <MARKET_SECTOR>'])`, `get(<FIELD>, <WEIGHT_FIELD>) for(holdings('<ETF_TICKER> <MARKET_SECTOR>'))`, or `get(<FIELD>) for(members('<INDEX_TICKER> <MARKET_SECTOR>')) with(...)`. Prefer `xbbg_bdp`/`xbbg_bdh` for simple reference or historical requests.
145
145
 
146
146
  Dealer quote / BQR workflows in xbbg use fixed-income identifiers with a quote source, for example `/isin/<ISIN>@<QUOTE_SOURCE> <MARKET_SECTOR>`; use `xbbg_bqr` for that workflow and `xbbg_bdtick` for raw intraday ticks.
147
147
 
148
- Streaming surfaces are intentionally exposed only as bounded snapshot tools. Each snapshot requires `maxUpdates`, applies the configured `maxStreamUpdates`/`maxStreamWaitMs` caps, stops on count, timeout, or stream completion, and calls `unsubscribe(false)` unless `drain: true` is explicitly provided. The package does not expose open-ended async subscription iterators as agent tools.
148
+ Streaming surfaces are intentionally exposed only as bounded snapshot tools. Each snapshot requires `maxUpdates`, applies the configured `maxStreamUpdates`/`maxStreamWaitMs` caps, stops on count, timeout, or stream completion, and calls `unsubscribe(false)` unless `drain: true` is explicitly provided. The package does not expose open-ended async subscription iterators as agent tools. If collection succeeds but releasing the subscription fails, the snapshot result still returns the collected updates and reports the failure in an `unsubscribeError` field instead of discarding data.
149
149
 
150
150
  ```ts
151
151
  import { createBloombergTools, createBdpTool } from "@xbbg/langgraph";
@@ -166,6 +166,7 @@ Extension helper tools:
166
166
  - `xbbg_ext_constants` - static constants and formatting helpers for dates, futures months, dividend types, and ETF/dividend columns.
167
167
  - `xbbg_ext_columns` - rename helpers for dividend, ETF, and earnings-shaped Bloomberg responses.
168
168
  - `xbbg_ext_calculate` - small numeric helper for level percentage calculations.
169
+ - `xbbg_ext_chart_spec` - renderer-neutral chart specs for frontend generative UI; converts bounded rows from `xbbg_bdh`, `xbbg_bdib`, holdings, depth, or already-shaped row data into Vega-Lite JSON.
169
170
 
170
171
  ```ts
171
172
  import { createBloombergExtTools, createAllBloombergTools } from "@xbbg/langgraph";
@@ -176,10 +177,40 @@ const allTools = createAllBloombergTools({
176
177
  });
177
178
  ```
178
179
 
180
+ ### Chart specs and generative UI frontends
181
+
182
+ `xbbg_ext_chart_spec` does not fetch Bloomberg data and does not render images. Use a data tool first, then pass its bounded rows into the chart-spec helper. The result is a portable visualization payload:
183
+
184
+ ```json
185
+ {
186
+ "kind": "xbbg.visualization",
187
+ "component": "xbbg_chart",
188
+ "renderer": "vega-lite",
189
+ "spec": { "data": { "values": [] }, "mark": { "type": "line" } }
190
+ }
191
+ ```
192
+
193
+ Frontend runtimes should register their own `xbbg_chart` component and render `data.spec` with their preferred Vega-Lite React wrapper. This keeps `@xbbg/langgraph` dependency-free and works with CopilotKit `useRenderTool`, assistant-ui data/generative UI renderers, Vercel AI SDK tool parts, or LangGraph `typedUi()` adapters.
194
+
195
+ Example tool input after a historical request:
196
+
197
+ ```json
198
+ {
199
+ "source": "bdh",
200
+ "rows": [{ "ticker": "AAPL US Equity", "date": "20240102", "value": 190.1 }],
201
+ "xField": "date",
202
+ "yFields": ["value"],
203
+ "seriesField": "ticker",
204
+ "title": "AAPL PX_LAST"
205
+ }
206
+ ```
207
+
179
208
  ## Engine handling
180
209
 
181
210
  By default the first tool invocation lazily imports `@xbbg/core`, calls `connect(engineConfig)`, and reuses the resulting engine across the tool set. Parallel LangGraph tool calls share the same in-flight initialization promise.
182
211
 
212
+ Lazily connected engines get a hard per-request timeout (`DEFAULT_ENGINE_REQUEST_TIMEOUT_MS`, 60s) because `@xbbg/core` disables request timeouts by default, which would let a wedged Terminal session hang tool calls forever. Pass `engineConfig: { requestTimeoutMs: ... }` to change it, or `0` to disable. A user-supplied `engine` is used as-is — its configuration and lifecycle (including disconnect) stay with the caller.
213
+
183
214
  ```ts
184
215
  import * as xbbg from "@xbbg/core";
185
216
  import { createBloombergTools } from "@xbbg/langgraph";
@@ -188,6 +219,10 @@ const engine = await xbbg.connect({ host: "localhost", port: 8194 });
188
219
  const tools = createBloombergTools({ engine });
189
220
  ```
190
221
 
222
+ ### Cancellation
223
+
224
+ Tools honor the LangChain/LangGraph `AbortSignal` (`graph.invoke(input, { signal })`): an aborted call rejects immediately, already-cancelled calls never start Bloomberg work, and snapshot tools stop collecting and unsubscribe right away (skipping `drain`) instead of running out their timeout. In-flight Bloomberg request/response calls cannot be cancelled mid-flight; they are bounded by the engine request timeout above.
225
+
191
226
  ## Limits and outputs
192
227
 
193
228
  Defaults:
@@ -199,6 +234,12 @@ Defaults:
199
234
  - `maxStreamUpdates = 10`
200
235
  - `maxStreamWaitMs = 15000`
201
236
 
237
+ Date inputs accept `YYYY-MM-DD` or `YYYYMMDD` strings, integer `YYYYMMDD` values (parsed as calendar dates), and epoch milliseconds; ambiguous numbers between those ranges and ambiguous `MM/DD/YYYY` strings are rejected with actionable schema errors. `Date` instances are deliberately not part of the wire contract: JSON tool calls cannot carry them and `z.date()` breaks JSON Schema conversion in zod v4.
238
+
239
+ Schemas only advertise parameters the engine accepts: `format` exists on `xbbg_bdp`/`xbbg_bdh` only, because the engine rejects it for BulkData (`xbbg_bds`), BQL, search, field-info, and BEQS output; a model-sent `format` on those tools is stripped rather than forwarded. The exported `toolParameterJsonSchema(tool)` returns the provider-ready `$ref`-free JSON Schema used in each tool's embedded provider definition.
240
+
241
+ Empty results are called out in the model-facing summary (`empty result; verify identifiers, fields, and date range before concluding no data exists`) so agents distinguish "no rows" from silent failure instead of inventing data.
242
+
202
243
  Each tool uses `backend: "json"` for finite request results and LangChain `content_and_artifact` output. The model-facing content starts with a short summary and then includes bounded JSON data:
203
244
 
204
245
  ```text
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ type XbbgCoreModule = typeof xbbg;
5
5
  type XbbgEngineLike = Pick<Awaited<ReturnType<XbbgCoreModule["connect"]>>, "bdp" | "bdh" | "bds" | "bdib" | "bdtick" | "bql" | "bsrch" | "bqr" | "bflds" | "beqs" | "yas" | "preferreds" | "corporateBonds" | "indexMembers" | "resolveIsins" | "issuerIsins" | "etfHoldings" | "stream" | "mktbar" | "depth">;
6
6
  type XbbgCoreLike = Pick<XbbgCoreModule, "connect" | "ext">;
7
7
 
8
- declare const BLOOMBERG_TOOL_NAMES: readonly ["xbbg_bdp", "xbbg_bdh", "xbbg_bds", "xbbg_bdib", "xbbg_bdtick", "xbbg_bql", "xbbg_bsrch", "xbbg_bqr", "xbbg_bflds", "xbbg_beqs", "xbbg_yas", "xbbg_preferreds", "xbbg_corporate_bonds", "xbbg_index_members", "xbbg_resolve_isins", "xbbg_issuer_isins", "xbbg_etf_holdings", "xbbg_stream_snapshot", "xbbg_mktbar_snapshot", "xbbg_depth_snapshot", "xbbg_ext_ticker", "xbbg_ext_futures", "xbbg_ext_cdx", "xbbg_ext_currency", "xbbg_ext_bql_builder", "xbbg_ext_market_session", "xbbg_ext_yas_overrides", "xbbg_ext_constants", "xbbg_ext_columns", "xbbg_ext_calculate"];
8
+ declare const BLOOMBERG_TOOL_NAMES: readonly ["xbbg_bdp", "xbbg_bdh", "xbbg_bds", "xbbg_bdib", "xbbg_bdtick", "xbbg_bql", "xbbg_bsrch", "xbbg_bqr", "xbbg_bflds", "xbbg_beqs", "xbbg_yas", "xbbg_preferreds", "xbbg_corporate_bonds", "xbbg_index_members", "xbbg_resolve_isins", "xbbg_issuer_isins", "xbbg_etf_holdings", "xbbg_stream_snapshot", "xbbg_mktbar_snapshot", "xbbg_depth_snapshot", "xbbg_ext_ticker", "xbbg_ext_futures", "xbbg_ext_cdx", "xbbg_ext_currency", "xbbg_ext_bql_builder", "xbbg_ext_chart_spec", "xbbg_ext_market_session", "xbbg_ext_yas_overrides", "xbbg_ext_constants", "xbbg_ext_columns", "xbbg_ext_calculate"];
9
9
  type BloombergToolName = (typeof BLOOMBERG_TOOL_NAMES)[number];
10
10
  interface BloombergToolsOptions {
11
11
  readonly engine?: XbbgEngineLike;
@@ -24,7 +24,7 @@ interface BloombergToolsOptions {
24
24
  }
25
25
  interface NormalizedBloombergToolsOptions {
26
26
  readonly engine?: XbbgEngineLike;
27
- readonly engineConfig?: xbbg.EngineConfig;
27
+ readonly engineConfig: xbbg.EngineConfig;
28
28
  readonly core?: XbbgCoreLike;
29
29
  readonly maxSecurities: number;
30
30
  readonly maxFields: number;
@@ -37,6 +37,13 @@ interface NormalizedBloombergToolsOptions {
37
37
  readonly validateFields: boolean | undefined;
38
38
  readonly disabledTools: ReadonlySet<BloombergToolName>;
39
39
  }
40
+ /**
41
+ * Default hard per-request timeout applied to lazily connected engines.
42
+ * @xbbg/core disables request timeouts by default (`requestTimeoutMs: 0`),
43
+ * which would let a wedged Terminal session hang tool calls forever. An
44
+ * explicit `engineConfig.requestTimeoutMs` (including 0) always wins.
45
+ */
46
+ declare const DEFAULT_ENGINE_REQUEST_TIMEOUT_MS = 60000;
40
47
 
41
48
  type BloombergTool = StructuredToolInterface;
42
49
  declare function createBdpTool(options?: BloombergToolsOptions): BloombergTool;
@@ -68,7 +75,7 @@ interface BloombergToolInstructionsOptions {
68
75
  }
69
76
  declare function getBloombergToolInstructions(options?: BloombergToolInstructionsOptions): string;
70
77
 
71
- declare const BLOOMBERG_EXT_TOOL_NAMES: readonly ("xbbg_bdp" | "xbbg_bdh" | "xbbg_bds" | "xbbg_bdib" | "xbbg_bdtick" | "xbbg_bql" | "xbbg_bsrch" | "xbbg_bqr" | "xbbg_bflds" | "xbbg_beqs" | "xbbg_yas" | "xbbg_preferreds" | "xbbg_corporate_bonds" | "xbbg_index_members" | "xbbg_resolve_isins" | "xbbg_issuer_isins" | "xbbg_etf_holdings" | "xbbg_stream_snapshot" | "xbbg_mktbar_snapshot" | "xbbg_depth_snapshot" | "xbbg_ext_ticker" | "xbbg_ext_futures" | "xbbg_ext_cdx" | "xbbg_ext_currency" | "xbbg_ext_bql_builder" | "xbbg_ext_market_session" | "xbbg_ext_yas_overrides" | "xbbg_ext_constants" | "xbbg_ext_columns" | "xbbg_ext_calculate")[];
78
+ declare const BLOOMBERG_EXT_TOOL_NAMES: readonly ("xbbg_bdp" | "xbbg_bdh" | "xbbg_bds" | "xbbg_bdib" | "xbbg_bdtick" | "xbbg_bql" | "xbbg_bsrch" | "xbbg_bqr" | "xbbg_bflds" | "xbbg_beqs" | "xbbg_yas" | "xbbg_preferreds" | "xbbg_corporate_bonds" | "xbbg_index_members" | "xbbg_resolve_isins" | "xbbg_issuer_isins" | "xbbg_etf_holdings" | "xbbg_stream_snapshot" | "xbbg_mktbar_snapshot" | "xbbg_depth_snapshot" | "xbbg_ext_ticker" | "xbbg_ext_futures" | "xbbg_ext_cdx" | "xbbg_ext_currency" | "xbbg_ext_bql_builder" | "xbbg_ext_chart_spec" | "xbbg_ext_market_session" | "xbbg_ext_yas_overrides" | "xbbg_ext_constants" | "xbbg_ext_columns" | "xbbg_ext_calculate")[];
72
79
  declare function createExtTickerTool(options?: BloombergToolsOptions): BloombergTool;
73
80
  declare function createExtFuturesTool(options?: BloombergToolsOptions): BloombergTool;
74
81
  declare function createExtCdxTool(options?: BloombergToolsOptions): BloombergTool;
@@ -79,6 +86,7 @@ declare function createExtYasOverridesTool(options?: BloombergToolsOptions): Blo
79
86
  declare function createExtConstantsTool(options?: BloombergToolsOptions): BloombergTool;
80
87
  declare function createExtColumnsTool(options?: BloombergToolsOptions): BloombergTool;
81
88
  declare function createExtCalculateTool(options?: BloombergToolsOptions): BloombergTool;
89
+ declare function createExtChartSpecTool(options?: BloombergToolsOptions): BloombergTool;
82
90
  declare function createBloombergExtTools(options?: BloombergToolsOptions): BloombergTool[];
83
91
 
84
92
  interface ToolEnvelope {
@@ -88,6 +96,84 @@ interface ToolEnvelope {
88
96
  readonly data: unknown;
89
97
  }
90
98
 
99
+ /**
100
+ * Subset of the LangChain runnable config forwarded to tool functions.
101
+ * `signal` aborts the call: the LangChain wrapper rejects immediately, and
102
+ * Bloomberg tool functions use it to stop waiting and release subscriptions.
103
+ */
104
+ interface ToolInvocationConfig {
105
+ readonly signal?: AbortSignal;
106
+ }
107
+ /**
108
+ * Provider-ready JSON Schema for a Bloomberg tool's input parameters, using
109
+ * the same conversion settings as the embedded provider tool definition
110
+ * ($ref-free, input-side of transforms). Exposed so consumers do not each
111
+ * reinvent zod -> JSON Schema conversion and sanitization.
112
+ */
113
+ declare function toolParameterJsonSchema(toolInstance: StructuredToolInterface): Record<string, unknown>;
114
+
115
+ type BloombergChartSource = "bdh" | "bdib" | "holdings" | "depth" | "rows";
116
+ type ChartKind = "line" | "area" | "bar" | "scatter" | "candlestick" | "depth";
117
+ type ChartRenderer = "vega-lite";
118
+ type ChartScalar = string | number | boolean | null;
119
+ type ChartRow = Readonly<Record<string, ChartScalar>>;
120
+ interface ChartSpecInput {
121
+ readonly source: BloombergChartSource;
122
+ readonly rows: readonly ChartRow[];
123
+ readonly renderer?: ChartRenderer;
124
+ readonly chart?: ChartKind;
125
+ readonly title?: string;
126
+ readonly xField?: string;
127
+ readonly yFields?: readonly string[];
128
+ readonly seriesField?: string;
129
+ readonly labelField?: string;
130
+ readonly valueField?: string;
131
+ readonly openField?: string;
132
+ readonly highField?: string;
133
+ readonly lowField?: string;
134
+ readonly closeField?: string;
135
+ readonly sideField?: string;
136
+ readonly priceField?: string;
137
+ readonly sizeField?: string;
138
+ readonly maxPoints?: number;
139
+ }
140
+
141
+ interface ChartSpecSummary {
142
+ readonly chart: ChartKind;
143
+ readonly inputRows: number;
144
+ readonly renderer: "vega-lite";
145
+ readonly rowCount: number;
146
+ readonly source: BloombergChartSource;
147
+ readonly title: string;
148
+ readonly truncatedInput: boolean;
149
+ readonly xField?: string;
150
+ readonly yFields: readonly string[];
151
+ readonly seriesField?: string;
152
+ }
153
+ interface VegaLiteSpec {
154
+ readonly $schema: "https://vega.github.io/schema/vega-lite/v5.json";
155
+ readonly data: {
156
+ readonly values: readonly ChartRow[];
157
+ };
158
+ readonly description: string;
159
+ readonly title: string;
160
+ readonly [key: string]: unknown;
161
+ }
162
+ interface ChartSpecOutput {
163
+ readonly kind: "xbbg.visualization";
164
+ readonly version: 1;
165
+ readonly component: "xbbg_chart";
166
+ readonly renderer: "vega-lite";
167
+ readonly rowCount: number;
168
+ readonly inputRowCount: number;
169
+ readonly truncatedInput: boolean;
170
+ readonly source: BloombergChartSource;
171
+ readonly chart: ChartKind;
172
+ readonly summary: ChartSpecSummary;
173
+ readonly spec: VegaLiteSpec;
174
+ readonly warnings: readonly string[];
175
+ }
176
+
91
177
  declare function createAllBloombergTools(options?: BloombergToolsOptions): BloombergTool[];
92
178
 
93
- export { BLOOMBERG_EXT_TOOL_NAMES, BLOOMBERG_TOOL_INSTRUCTIONS, BLOOMBERG_TOOL_NAMES, type BloombergTool, type BloombergToolInstructionsOptions, type BloombergToolName, type BloombergToolsOptions, type NormalizedBloombergToolsOptions, type ToolEnvelope, createAllBloombergTools, createBdhTool, createBdibTool, createBdpTool, createBdsTool, createBdtickTool, createBeqsTool, createBfldsTool, createBloombergExtTools, createBloombergTools, createBqlTool, createBqrTool, createBsrchTool, createCorporateBondsTool, createDepthSnapshotTool, createEtfHoldingsTool, createExtBqlBuilderTool, createExtCalculateTool, createExtCdxTool, createExtColumnsTool, createExtConstantsTool, createExtCurrencyTool, createExtFuturesTool, createExtMarketSessionTool, createExtTickerTool, createExtYasOverridesTool, createIndexMembersTool, createIssuerIsinsTool, createMktbarSnapshotTool, createPreferredsTool, createResolveIsinsTool, createStreamSnapshotTool, createYasTool, getBloombergToolInstructions };
179
+ export { BLOOMBERG_EXT_TOOL_NAMES, BLOOMBERG_TOOL_INSTRUCTIONS, BLOOMBERG_TOOL_NAMES, type BloombergChartSource, type BloombergTool, type BloombergToolInstructionsOptions, type BloombergToolName, type BloombergToolsOptions, type ChartKind, type ChartRenderer, type ChartRow, type ChartScalar, type ChartSpecInput, type ChartSpecOutput, type ChartSpecSummary, DEFAULT_ENGINE_REQUEST_TIMEOUT_MS, type NormalizedBloombergToolsOptions, type ToolEnvelope, type ToolInvocationConfig, type VegaLiteSpec, createAllBloombergTools, createBdhTool, createBdibTool, createBdpTool, createBdsTool, createBdtickTool, createBeqsTool, createBfldsTool, createBloombergExtTools, createBloombergTools, createBqlTool, createBqrTool, createBsrchTool, createCorporateBondsTool, createDepthSnapshotTool, createEtfHoldingsTool, createExtBqlBuilderTool, createExtCalculateTool, createExtCdxTool, createExtChartSpecTool, createExtColumnsTool, createExtConstantsTool, createExtCurrencyTool, createExtFuturesTool, createExtMarketSessionTool, createExtTickerTool, createExtYasOverridesTool, createIndexMembersTool, createIssuerIsinsTool, createMktbarSnapshotTool, createPreferredsTool, createResolveIsinsTool, createStreamSnapshotTool, createYasTool, getBloombergToolInstructions, toolParameterJsonSchema };