@telemai/sdk 0.1.0 → 0.2.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.
@@ -0,0 +1,269 @@
1
+ import { Schema } from 'ai';
2
+ import { TrajectorySnapshot, Telem, SearchOptions, SearchResponse, FetchOptions, FetchResponse } from '../index.cjs';
3
+
4
+ /** One flattened history entry: the wire shape. */
5
+ type HistoryMessage = Record<string, string> & {
6
+ role: string;
7
+ content: string;
8
+ };
9
+ /** A flattened entry PLUS the identity the delta needs. The wire carries no id;
10
+ * the host assigns one at build time (`"\u0000pos:" + index` where messages have
11
+ * none of their own). */
12
+ type FlatMessage = {
13
+ id: string;
14
+ entry: HistoryMessage;
15
+ };
16
+ /** The mode, read per call: `ancestors` (default) is phase 1, `history` is both
17
+ * phases, `off` is the kill switch. Anything unrecognized is the DEFAULT, not
18
+ * `off` — the rollback lever is the exact word. */
19
+ type IncrementalMode = "ancestors" | "history" | "off";
20
+ /** One ancestor entry this call chose not to send the context for. `entry` is the
21
+ * very object inside `ancestors`, so restoring is a swap on the body about to be
22
+ * re-sent — same node_key, same everything else. */
23
+ type OmittedContext = {
24
+ key: string;
25
+ entry: Record<string, unknown>;
26
+ context: unknown;
27
+ };
28
+ /** One call's two unacknowledged promises, held until the response proves or
29
+ * discards them. */
30
+ type DeliveryPlan = {
31
+ scope: string;
32
+ /** Snapshot keys this request carries FULL context for: what a 2xx proves. */
33
+ sentWithContext: string[];
34
+ /** What this request WITHHELD, kept whole for the guard's 409. Empty is also
35
+ * the gate: a 409 on a request that omitted nothing is a plain error. */
36
+ omitted: OmittedContext[];
37
+ /** The epoch is a guess (the host could not read its own state); the history
38
+ * then goes out in FULL. */
39
+ epochDegraded: boolean;
40
+ history?: HistorySend;
41
+ };
42
+ /** The generation a watermark belongs to. `session_key` alone is not monotonic
43
+ * and is best-effort; the last flattened id plus the count pin it down. */
44
+ type HistoryEpoch = {
45
+ sessionKey: string;
46
+ lastMsgId: string;
47
+ msgCount: number;
48
+ };
49
+ /** What one call promised to the baseline. */
50
+ type HistorySend = {
51
+ conversationKey: string;
52
+ epoch: HistoryEpoch;
53
+ sent: Array<{
54
+ id: string;
55
+ hash: string;
56
+ }>;
57
+ };
58
+ /** One ancestor entry as it rides in `ancestors`: a snapshot copy that may carry
59
+ * `context` or `context_omitted`. */
60
+ type PlannedAncestor = Record<string, unknown>;
61
+ type IncrementalOptions = {
62
+ /** The mode, resolved per call. Default: `TELEM_INCREMENTAL` from the env. */
63
+ mode?: () => IncrementalMode;
64
+ /** The differential harness's bypass of the capability probe. Default:
65
+ * `TELEM_INCREMENTAL_FORCE=1` from the env. Never production. */
66
+ forced?: () => boolean;
67
+ };
68
+ /**
69
+ * One instance's beliefs — the equivalent of one opencode plugin instance's
70
+ * factory closure. A host creates one per root agent and shares it with every
71
+ * child, so a child never re-sends what its parent already proved.
72
+ */
73
+ declare function createIncrementalState(options?: IncrementalOptions): {
74
+ planAncestors: (plan: DeliveryPlan, chain: readonly Record<string, unknown>[]) => PlannedAncestor[];
75
+ planHistory: (plan: DeliveryPlan, conversationId: string, sessionKey: string, flat: readonly FlatMessage[]) => Promise<HistoryMessage[]>;
76
+ recordDelivery: (plan: DeliveryPlan, body: unknown) => void;
77
+ sendWithOmissionRetry: <T>(plan: DeliveryPlan, send: () => Promise<T>) => Promise<T>;
78
+ };
79
+ type IncrementalState = ReturnType<typeof createIncrementalState>;
80
+
81
+ /** The execute options the integration reads. `ai@5`, `6` and `7` all carry
82
+ * these three; the type is structural so nothing here depends on the peer's
83
+ * own declarations. */
84
+ type TelemVercelToolExecutionOptions = {
85
+ toolCallId: string;
86
+ /** The messages sent to the model for this step: no system prompt, and not
87
+ * the assistant message that made the call. */
88
+ messages: readonly unknown[];
89
+ /** Forwarded to the Telem request: an abort stops it and skips the retry. */
90
+ abortSignal?: AbortSignal;
91
+ };
92
+ /** What `onResponse` sees after every successful search and fetch the tools make. */
93
+ type TelemVercelCallEvent = {
94
+ kind: "search";
95
+ agent: TelemVercelAgent;
96
+ query: string | string[];
97
+ response: SearchResponse;
98
+ } | {
99
+ kind: "fetch";
100
+ agent: TelemVercelAgent;
101
+ url: string | string[];
102
+ response: FetchResponse;
103
+ };
104
+ /** What the model reads back. Defaults: `search` the top results, compact;
105
+ * `fetch` one page's status, error and text. Applies to subagents too. */
106
+ type TelemVercelRenderOptions = {
107
+ search?: (response: SearchResponse) => unknown;
108
+ fetch?: (response: FetchResponse) => unknown;
109
+ };
110
+ /** One tool call, as the history renders it: the current call's `running` marker. */
111
+ type TelemVercelToolCallRef = {
112
+ name: string;
113
+ input: unknown;
114
+ };
115
+ type TelemVercelAgentOptions = {
116
+ telem: Telem;
117
+ /** Names the integration in every derived key. Required, never defaulted:
118
+ * it is what keeps one product's rows apart from another's. */
119
+ harness: string;
120
+ /** One id per agent conversation. Minted when absent. A chat that spans
121
+ * several HTTP requests must pass a stable id (the chat id), or every request
122
+ * becomes its own session. */
123
+ conversationId?: string;
124
+ /** The root-first chain this agent hangs under; `child()` fills it. */
125
+ ancestors?: readonly TrajectorySnapshot[];
126
+ /** `ancestors` (phase 1, the default), `history` (both phases) or `off`.
127
+ * Unset reads `TELEM_INCREMENTAL` per call. */
128
+ incremental?: IncrementalMode;
129
+ /** What the model reads back from the two tools. Inherited by subagents. */
130
+ render?: TelemVercelRenderOptions;
131
+ /** Called after every successful search and fetch, root and subagents alike,
132
+ * with the agent that made it and the response: for logging and metrics,
133
+ * without replacing a tool. A throw or a rejection here is swallowed; it
134
+ * never fails the call. */
135
+ onResponse?: (event: TelemVercelCallEvent) => void | Promise<void>;
136
+ /** Advanced: the ledgers to share. `child()` passes its parent's, so a child
137
+ * never re-sends what the parent already proved delivered. */
138
+ incrementalState?: IncrementalState;
139
+ };
140
+ type TelemVercelSearchInput = {
141
+ query: string;
142
+ goal?: string;
143
+ context?: string;
144
+ };
145
+ type TelemVercelFetchInput = {
146
+ url: string;
147
+ goal?: string;
148
+ };
149
+ /** The default `render.search`: the top results, compact. */
150
+ type TelemVercelSearchOutput = Array<{
151
+ provider: string;
152
+ title: string;
153
+ url: string;
154
+ summary: string | null;
155
+ }>;
156
+ /** The default `render.fetch`: one page's status, error and text. */
157
+ type TelemVercelFetchOutput = {
158
+ status: string | undefined;
159
+ error: unknown;
160
+ content: string;
161
+ };
162
+ /** One AI SDK tool as a plain object: `description`, a branded `inputSchema`,
163
+ * and `execute`. */
164
+ type TelemVercelTool<INPUT> = {
165
+ description: string;
166
+ inputSchema: Schema<INPUT>;
167
+ execute: (input: INPUT, options: TelemVercelToolExecutionOptions) => Promise<unknown>;
168
+ };
169
+ type TelemVercelAgent = {
170
+ /** This conversation's identity: the id every derived key hangs off. */
171
+ readonly conversationId: string;
172
+ /** The root-first ancestor chain; empty for a root agent. */
173
+ readonly ancestors: readonly TrajectorySnapshot[];
174
+ readonly telem: Telem;
175
+ /** `telem_search` and `telem_fetch`, lineage attached from the execute options. */
176
+ readonly tools: {
177
+ telem_search: TelemVercelTool<TelemVercelSearchInput>;
178
+ telem_fetch: TelemVercelTool<TelemVercelFetchInput>;
179
+ };
180
+ /** The SDK search with this agent's lineage attached from `execution` — for a
181
+ * tool of the user's own. Several calls with the same options are distinct nodes. */
182
+ search(query: string | string[], options?: SearchOptions | null, execution?: TelemVercelToolExecutionOptions): Promise<SearchResponse>;
183
+ /** The SDK fetch with this agent's lineage attached from `execution`. */
184
+ fetch(url: string | string[], options?: FetchOptions | null, execution?: TelemVercelToolExecutionOptions): Promise<FetchResponse>;
185
+ /** This agent frozen at the calling turn: what its subagents carry. Keyed on
186
+ * the TURN, so subagents started by several tool calls of one turn share one
187
+ * snapshot — which is why it carries nothing call-specific: siblings must send
188
+ * one snapshot key with byte-identical context, or the backend's first writer
189
+ * fixes a context the others never sent. `spawnedAt` defaults to now. */
190
+ snapshot(execution?: TelemVercelToolExecutionOptions, spawnedAt?: string): Promise<TrajectorySnapshot>;
191
+ /** A new agent whose chain ends with this agent's snapshot at the calling
192
+ * turn, sharing the incremental ledgers. Call it inside the tool that starts
193
+ * the subagent and hand the child's `tools` to the subagent. */
194
+ child(execution?: TelemVercelToolExecutionOptions, options?: {
195
+ conversationId?: string;
196
+ spawnedAt?: string;
197
+ }): Promise<TelemVercelAgent>;
198
+ };
199
+ /**
200
+ * Flatten the messages a tool was called with into the backend's history shape,
201
+ * one entry per message that carries text, reasoning or a tool call, each with
202
+ * its positional identity. `tool` messages are dropped: their calls are already
203
+ * `completed` markers, and a result can be a whole page. Reasoning parts land in
204
+ * `reasoning`, never in `content`.
205
+ *
206
+ * `current` is the call being made right now. It is not in `messages`, and the
207
+ * exporter reads the current call out of the LAST entry, so it is appended as a
208
+ * `running` marker built from the tool's own name and input.
209
+ */
210
+ declare function telemVercelMessageHistory(messages: readonly unknown[], current?: TelemVercelToolCallRef): FlatMessage[];
211
+ /** Whether subagents link by themselves on this runtime: `AsyncLocalStorage`
212
+ * was found. When false, link them with `childTelemVercelTools`. */
213
+ declare const telemVercelAutoNesting: boolean;
214
+ /**
215
+ * Create one agent: a conversation identity, the tools that carry it, and the
216
+ * calls that attach it to a tool of the user's own. `createTelemVercelTools` is the
217
+ * front door; this is the layer under it.
218
+ */
219
+ declare function createTelemVercelAgent(options: TelemVercelAgentOptions): TelemVercelAgent;
220
+ /** A tool as the AI SDK sees it: anything with an optional `execute`. */
221
+ type TelemVercelToolLike = {
222
+ execute?: (...args: any[]) => unknown;
223
+ } & Record<string, unknown>;
224
+ type TelemVercelToolsOptions<T extends Record<string, TelemVercelToolLike>> = Omit<TelemVercelAgentOptions, "incrementalState"> & {
225
+ /** Your own tools. Each is returned wrapped, so a run started inside it is
226
+ * linked. Tools without `execute` pass through untouched. */
227
+ tools?: T;
228
+ };
229
+ type TelemVercelTools<T extends Record<string, TelemVercelToolLike>> = T & TelemVercelAgent["tools"];
230
+ /**
231
+ * Build the tool set once and pass it to every `generateText`, `streamText` or
232
+ * `ToolLoopAgent` of one conversation. `telem_search` and `telem_fetch` carry
233
+ * lineage on every call; a run started inside any tool in the set — a subagent —
234
+ * links to the tool call that started it, with nothing else to write.
235
+ *
236
+ * Build it where the conversation starts, once per conversation: a set shared
237
+ * by several conversations records them as one.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * const delegate = tool({
242
+ * description: "Research one question.",
243
+ * inputSchema: z.object({ brief: z.string() }),
244
+ * execute: async ({ brief }): Promise<string> => (await generateText({ model, tools, prompt: brief })).text,
245
+ * })
246
+ * const tools = createTelemVercelTools({ telem, harness: "my-app", tools: { delegate } })
247
+ * await generateText({ model, tools, prompt })
248
+ * ```
249
+ */
250
+ declare function createTelemVercelTools<T extends Record<string, TelemVercelToolLike> = {}>(options: TelemVercelToolsOptions<T>): TelemVercelTools<T>;
251
+ /**
252
+ * The tool set for a subagent, linked to the tool call that starts it, by hand.
253
+ * For a runtime without `AsyncLocalStorage` (`telemVercelAutoNesting` is false), or to name
254
+ * the child's conversation. Inside the tool that starts the subagent:
255
+ * `const subTools = await childTelemVercelTools(tools, options)`, then pass `subTools`
256
+ * to the subagent's generateText. The set is bound to the child outright, and the
257
+ * same line works one level down: the set knows which tool call it runs in.
258
+ */
259
+ declare function childTelemVercelTools<T extends Record<string, TelemVercelToolLike>>(tools: TelemVercelTools<T>, execution: TelemVercelToolExecutionOptions, options?: {
260
+ conversationId?: string;
261
+ }): Promise<TelemVercelTools<T>>;
262
+ /**
263
+ * The agent a tool call belongs to, for a tool of your own that calls Telem:
264
+ * `const agent = await telemVercelAgentFor(tools, options); agent.search(query, {}, options)`.
265
+ * The root agent outside any run started by a tool; the linked child inside one.
266
+ */
267
+ declare function telemVercelAgentFor(tools: object, execution?: TelemVercelToolExecutionOptions): Promise<TelemVercelAgent>;
268
+
269
+ export { type TelemVercelAgent, type TelemVercelAgentOptions, type TelemVercelCallEvent, type TelemVercelFetchInput, type TelemVercelFetchOutput, type TelemVercelRenderOptions, type TelemVercelSearchInput, type TelemVercelSearchOutput, type TelemVercelTool, type TelemVercelToolCallRef, type TelemVercelToolExecutionOptions, type TelemVercelToolLike, type TelemVercelTools, type TelemVercelToolsOptions, childTelemVercelTools, createTelemVercelAgent, createTelemVercelTools, createTelemVercelAgent as default, telemVercelAgentFor, telemVercelAutoNesting, telemVercelMessageHistory };
@@ -0,0 +1,269 @@
1
+ import { Schema } from 'ai';
2
+ import { TrajectorySnapshot, Telem, SearchOptions, SearchResponse, FetchOptions, FetchResponse } from '../index.js';
3
+
4
+ /** One flattened history entry: the wire shape. */
5
+ type HistoryMessage = Record<string, string> & {
6
+ role: string;
7
+ content: string;
8
+ };
9
+ /** A flattened entry PLUS the identity the delta needs. The wire carries no id;
10
+ * the host assigns one at build time (`"\u0000pos:" + index` where messages have
11
+ * none of their own). */
12
+ type FlatMessage = {
13
+ id: string;
14
+ entry: HistoryMessage;
15
+ };
16
+ /** The mode, read per call: `ancestors` (default) is phase 1, `history` is both
17
+ * phases, `off` is the kill switch. Anything unrecognized is the DEFAULT, not
18
+ * `off` — the rollback lever is the exact word. */
19
+ type IncrementalMode = "ancestors" | "history" | "off";
20
+ /** One ancestor entry this call chose not to send the context for. `entry` is the
21
+ * very object inside `ancestors`, so restoring is a swap on the body about to be
22
+ * re-sent — same node_key, same everything else. */
23
+ type OmittedContext = {
24
+ key: string;
25
+ entry: Record<string, unknown>;
26
+ context: unknown;
27
+ };
28
+ /** One call's two unacknowledged promises, held until the response proves or
29
+ * discards them. */
30
+ type DeliveryPlan = {
31
+ scope: string;
32
+ /** Snapshot keys this request carries FULL context for: what a 2xx proves. */
33
+ sentWithContext: string[];
34
+ /** What this request WITHHELD, kept whole for the guard's 409. Empty is also
35
+ * the gate: a 409 on a request that omitted nothing is a plain error. */
36
+ omitted: OmittedContext[];
37
+ /** The epoch is a guess (the host could not read its own state); the history
38
+ * then goes out in FULL. */
39
+ epochDegraded: boolean;
40
+ history?: HistorySend;
41
+ };
42
+ /** The generation a watermark belongs to. `session_key` alone is not monotonic
43
+ * and is best-effort; the last flattened id plus the count pin it down. */
44
+ type HistoryEpoch = {
45
+ sessionKey: string;
46
+ lastMsgId: string;
47
+ msgCount: number;
48
+ };
49
+ /** What one call promised to the baseline. */
50
+ type HistorySend = {
51
+ conversationKey: string;
52
+ epoch: HistoryEpoch;
53
+ sent: Array<{
54
+ id: string;
55
+ hash: string;
56
+ }>;
57
+ };
58
+ /** One ancestor entry as it rides in `ancestors`: a snapshot copy that may carry
59
+ * `context` or `context_omitted`. */
60
+ type PlannedAncestor = Record<string, unknown>;
61
+ type IncrementalOptions = {
62
+ /** The mode, resolved per call. Default: `TELEM_INCREMENTAL` from the env. */
63
+ mode?: () => IncrementalMode;
64
+ /** The differential harness's bypass of the capability probe. Default:
65
+ * `TELEM_INCREMENTAL_FORCE=1` from the env. Never production. */
66
+ forced?: () => boolean;
67
+ };
68
+ /**
69
+ * One instance's beliefs — the equivalent of one opencode plugin instance's
70
+ * factory closure. A host creates one per root agent and shares it with every
71
+ * child, so a child never re-sends what its parent already proved.
72
+ */
73
+ declare function createIncrementalState(options?: IncrementalOptions): {
74
+ planAncestors: (plan: DeliveryPlan, chain: readonly Record<string, unknown>[]) => PlannedAncestor[];
75
+ planHistory: (plan: DeliveryPlan, conversationId: string, sessionKey: string, flat: readonly FlatMessage[]) => Promise<HistoryMessage[]>;
76
+ recordDelivery: (plan: DeliveryPlan, body: unknown) => void;
77
+ sendWithOmissionRetry: <T>(plan: DeliveryPlan, send: () => Promise<T>) => Promise<T>;
78
+ };
79
+ type IncrementalState = ReturnType<typeof createIncrementalState>;
80
+
81
+ /** The execute options the integration reads. `ai@5`, `6` and `7` all carry
82
+ * these three; the type is structural so nothing here depends on the peer's
83
+ * own declarations. */
84
+ type TelemVercelToolExecutionOptions = {
85
+ toolCallId: string;
86
+ /** The messages sent to the model for this step: no system prompt, and not
87
+ * the assistant message that made the call. */
88
+ messages: readonly unknown[];
89
+ /** Forwarded to the Telem request: an abort stops it and skips the retry. */
90
+ abortSignal?: AbortSignal;
91
+ };
92
+ /** What `onResponse` sees after every successful search and fetch the tools make. */
93
+ type TelemVercelCallEvent = {
94
+ kind: "search";
95
+ agent: TelemVercelAgent;
96
+ query: string | string[];
97
+ response: SearchResponse;
98
+ } | {
99
+ kind: "fetch";
100
+ agent: TelemVercelAgent;
101
+ url: string | string[];
102
+ response: FetchResponse;
103
+ };
104
+ /** What the model reads back. Defaults: `search` the top results, compact;
105
+ * `fetch` one page's status, error and text. Applies to subagents too. */
106
+ type TelemVercelRenderOptions = {
107
+ search?: (response: SearchResponse) => unknown;
108
+ fetch?: (response: FetchResponse) => unknown;
109
+ };
110
+ /** One tool call, as the history renders it: the current call's `running` marker. */
111
+ type TelemVercelToolCallRef = {
112
+ name: string;
113
+ input: unknown;
114
+ };
115
+ type TelemVercelAgentOptions = {
116
+ telem: Telem;
117
+ /** Names the integration in every derived key. Required, never defaulted:
118
+ * it is what keeps one product's rows apart from another's. */
119
+ harness: string;
120
+ /** One id per agent conversation. Minted when absent. A chat that spans
121
+ * several HTTP requests must pass a stable id (the chat id), or every request
122
+ * becomes its own session. */
123
+ conversationId?: string;
124
+ /** The root-first chain this agent hangs under; `child()` fills it. */
125
+ ancestors?: readonly TrajectorySnapshot[];
126
+ /** `ancestors` (phase 1, the default), `history` (both phases) or `off`.
127
+ * Unset reads `TELEM_INCREMENTAL` per call. */
128
+ incremental?: IncrementalMode;
129
+ /** What the model reads back from the two tools. Inherited by subagents. */
130
+ render?: TelemVercelRenderOptions;
131
+ /** Called after every successful search and fetch, root and subagents alike,
132
+ * with the agent that made it and the response: for logging and metrics,
133
+ * without replacing a tool. A throw or a rejection here is swallowed; it
134
+ * never fails the call. */
135
+ onResponse?: (event: TelemVercelCallEvent) => void | Promise<void>;
136
+ /** Advanced: the ledgers to share. `child()` passes its parent's, so a child
137
+ * never re-sends what the parent already proved delivered. */
138
+ incrementalState?: IncrementalState;
139
+ };
140
+ type TelemVercelSearchInput = {
141
+ query: string;
142
+ goal?: string;
143
+ context?: string;
144
+ };
145
+ type TelemVercelFetchInput = {
146
+ url: string;
147
+ goal?: string;
148
+ };
149
+ /** The default `render.search`: the top results, compact. */
150
+ type TelemVercelSearchOutput = Array<{
151
+ provider: string;
152
+ title: string;
153
+ url: string;
154
+ summary: string | null;
155
+ }>;
156
+ /** The default `render.fetch`: one page's status, error and text. */
157
+ type TelemVercelFetchOutput = {
158
+ status: string | undefined;
159
+ error: unknown;
160
+ content: string;
161
+ };
162
+ /** One AI SDK tool as a plain object: `description`, a branded `inputSchema`,
163
+ * and `execute`. */
164
+ type TelemVercelTool<INPUT> = {
165
+ description: string;
166
+ inputSchema: Schema<INPUT>;
167
+ execute: (input: INPUT, options: TelemVercelToolExecutionOptions) => Promise<unknown>;
168
+ };
169
+ type TelemVercelAgent = {
170
+ /** This conversation's identity: the id every derived key hangs off. */
171
+ readonly conversationId: string;
172
+ /** The root-first ancestor chain; empty for a root agent. */
173
+ readonly ancestors: readonly TrajectorySnapshot[];
174
+ readonly telem: Telem;
175
+ /** `telem_search` and `telem_fetch`, lineage attached from the execute options. */
176
+ readonly tools: {
177
+ telem_search: TelemVercelTool<TelemVercelSearchInput>;
178
+ telem_fetch: TelemVercelTool<TelemVercelFetchInput>;
179
+ };
180
+ /** The SDK search with this agent's lineage attached from `execution` — for a
181
+ * tool of the user's own. Several calls with the same options are distinct nodes. */
182
+ search(query: string | string[], options?: SearchOptions | null, execution?: TelemVercelToolExecutionOptions): Promise<SearchResponse>;
183
+ /** The SDK fetch with this agent's lineage attached from `execution`. */
184
+ fetch(url: string | string[], options?: FetchOptions | null, execution?: TelemVercelToolExecutionOptions): Promise<FetchResponse>;
185
+ /** This agent frozen at the calling turn: what its subagents carry. Keyed on
186
+ * the TURN, so subagents started by several tool calls of one turn share one
187
+ * snapshot — which is why it carries nothing call-specific: siblings must send
188
+ * one snapshot key with byte-identical context, or the backend's first writer
189
+ * fixes a context the others never sent. `spawnedAt` defaults to now. */
190
+ snapshot(execution?: TelemVercelToolExecutionOptions, spawnedAt?: string): Promise<TrajectorySnapshot>;
191
+ /** A new agent whose chain ends with this agent's snapshot at the calling
192
+ * turn, sharing the incremental ledgers. Call it inside the tool that starts
193
+ * the subagent and hand the child's `tools` to the subagent. */
194
+ child(execution?: TelemVercelToolExecutionOptions, options?: {
195
+ conversationId?: string;
196
+ spawnedAt?: string;
197
+ }): Promise<TelemVercelAgent>;
198
+ };
199
+ /**
200
+ * Flatten the messages a tool was called with into the backend's history shape,
201
+ * one entry per message that carries text, reasoning or a tool call, each with
202
+ * its positional identity. `tool` messages are dropped: their calls are already
203
+ * `completed` markers, and a result can be a whole page. Reasoning parts land in
204
+ * `reasoning`, never in `content`.
205
+ *
206
+ * `current` is the call being made right now. It is not in `messages`, and the
207
+ * exporter reads the current call out of the LAST entry, so it is appended as a
208
+ * `running` marker built from the tool's own name and input.
209
+ */
210
+ declare function telemVercelMessageHistory(messages: readonly unknown[], current?: TelemVercelToolCallRef): FlatMessage[];
211
+ /** Whether subagents link by themselves on this runtime: `AsyncLocalStorage`
212
+ * was found. When false, link them with `childTelemVercelTools`. */
213
+ declare const telemVercelAutoNesting: boolean;
214
+ /**
215
+ * Create one agent: a conversation identity, the tools that carry it, and the
216
+ * calls that attach it to a tool of the user's own. `createTelemVercelTools` is the
217
+ * front door; this is the layer under it.
218
+ */
219
+ declare function createTelemVercelAgent(options: TelemVercelAgentOptions): TelemVercelAgent;
220
+ /** A tool as the AI SDK sees it: anything with an optional `execute`. */
221
+ type TelemVercelToolLike = {
222
+ execute?: (...args: any[]) => unknown;
223
+ } & Record<string, unknown>;
224
+ type TelemVercelToolsOptions<T extends Record<string, TelemVercelToolLike>> = Omit<TelemVercelAgentOptions, "incrementalState"> & {
225
+ /** Your own tools. Each is returned wrapped, so a run started inside it is
226
+ * linked. Tools without `execute` pass through untouched. */
227
+ tools?: T;
228
+ };
229
+ type TelemVercelTools<T extends Record<string, TelemVercelToolLike>> = T & TelemVercelAgent["tools"];
230
+ /**
231
+ * Build the tool set once and pass it to every `generateText`, `streamText` or
232
+ * `ToolLoopAgent` of one conversation. `telem_search` and `telem_fetch` carry
233
+ * lineage on every call; a run started inside any tool in the set — a subagent —
234
+ * links to the tool call that started it, with nothing else to write.
235
+ *
236
+ * Build it where the conversation starts, once per conversation: a set shared
237
+ * by several conversations records them as one.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * const delegate = tool({
242
+ * description: "Research one question.",
243
+ * inputSchema: z.object({ brief: z.string() }),
244
+ * execute: async ({ brief }): Promise<string> => (await generateText({ model, tools, prompt: brief })).text,
245
+ * })
246
+ * const tools = createTelemVercelTools({ telem, harness: "my-app", tools: { delegate } })
247
+ * await generateText({ model, tools, prompt })
248
+ * ```
249
+ */
250
+ declare function createTelemVercelTools<T extends Record<string, TelemVercelToolLike> = {}>(options: TelemVercelToolsOptions<T>): TelemVercelTools<T>;
251
+ /**
252
+ * The tool set for a subagent, linked to the tool call that starts it, by hand.
253
+ * For a runtime without `AsyncLocalStorage` (`telemVercelAutoNesting` is false), or to name
254
+ * the child's conversation. Inside the tool that starts the subagent:
255
+ * `const subTools = await childTelemVercelTools(tools, options)`, then pass `subTools`
256
+ * to the subagent's generateText. The set is bound to the child outright, and the
257
+ * same line works one level down: the set knows which tool call it runs in.
258
+ */
259
+ declare function childTelemVercelTools<T extends Record<string, TelemVercelToolLike>>(tools: TelemVercelTools<T>, execution: TelemVercelToolExecutionOptions, options?: {
260
+ conversationId?: string;
261
+ }): Promise<TelemVercelTools<T>>;
262
+ /**
263
+ * The agent a tool call belongs to, for a tool of your own that calls Telem:
264
+ * `const agent = await telemVercelAgentFor(tools, options); agent.search(query, {}, options)`.
265
+ * The root agent outside any run started by a tool; the linked child inside one.
266
+ */
267
+ declare function telemVercelAgentFor(tools: object, execution?: TelemVercelToolExecutionOptions): Promise<TelemVercelAgent>;
268
+
269
+ export { type TelemVercelAgent, type TelemVercelAgentOptions, type TelemVercelCallEvent, type TelemVercelFetchInput, type TelemVercelFetchOutput, type TelemVercelRenderOptions, type TelemVercelSearchInput, type TelemVercelSearchOutput, type TelemVercelTool, type TelemVercelToolCallRef, type TelemVercelToolExecutionOptions, type TelemVercelToolLike, type TelemVercelTools, type TelemVercelToolsOptions, childTelemVercelTools, createTelemVercelAgent, createTelemVercelTools, createTelemVercelAgent as default, telemVercelAgentFor, telemVercelAutoNesting, telemVercelMessageHistory };