@tambo-ai/client 0.0.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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/elicitation.d.ts +59 -0
- package/dist/mcp/elicitation.d.ts.map +1 -0
- package/dist/mcp/elicitation.js +27 -0
- package/dist/mcp/elicitation.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +14 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-client.d.ts +185 -0
- package/dist/mcp/mcp-client.d.ts.map +1 -0
- package/dist/mcp/mcp-client.js +219 -0
- package/dist/mcp/mcp-client.js.map +1 -0
- package/dist/mcp/mcp-constants.d.ts +19 -0
- package/dist/mcp/mcp-constants.d.ts.map +1 -0
- package/dist/mcp/mcp-constants.js +21 -0
- package/dist/mcp/mcp-constants.js.map +1 -0
- package/dist/model/component-metadata.d.ts +390 -0
- package/dist/model/component-metadata.d.ts.map +1 -0
- package/dist/model/component-metadata.js +3 -0
- package/dist/model/component-metadata.js.map +1 -0
- package/dist/model/mcp-server-info.d.ts +72 -0
- package/dist/model/mcp-server-info.d.ts.map +1 -0
- package/dist/model/mcp-server-info.js +29 -0
- package/dist/model/mcp-server-info.js.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +15 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/json-schema.d.ts +42 -0
- package/dist/schema/json-schema.d.ts.map +1 -0
- package/dist/schema/json-schema.js +114 -0
- package/dist/schema/json-schema.js.map +1 -0
- package/dist/schema/schema.d.ts +49 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/schema.js +129 -0
- package/dist/schema/schema.js.map +1 -0
- package/dist/schema/standard-schema.d.ts +22 -0
- package/dist/schema/standard-schema.d.ts.map +1 -0
- package/dist/schema/standard-schema.js +42 -0
- package/dist/schema/standard-schema.js.map +1 -0
- package/dist/schema/validate.d.ts +14 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +148 -0
- package/dist/schema/validate.js.map +1 -0
- package/dist/tambo-client.d.ts +292 -0
- package/dist/tambo-client.d.ts.map +1 -0
- package/dist/tambo-client.js +508 -0
- package/dist/tambo-client.js.map +1 -0
- package/dist/tambo-stream.d.ts +112 -0
- package/dist/tambo-stream.d.ts.map +1 -0
- package/dist/tambo-stream.js +345 -0
- package/dist/tambo-stream.js.map +1 -0
- package/dist/types/auth.d.ts +24 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/event.d.ts +89 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/event.js +57 -0
- package/dist/types/event.js.map +1 -0
- package/dist/types/message.d.ts +122 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +10 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/thread.d.ts +58 -0
- package/dist/types/thread.d.ts.map +1 -0
- package/dist/types/thread.js +9 -0
- package/dist/types/thread.js.map +1 -0
- package/dist/types/tool-choice.d.ts +8 -0
- package/dist/types/tool-choice.d.ts.map +1 -0
- package/dist/types/tool-choice.js +3 -0
- package/dist/types/tool-choice.js.map +1 -0
- package/dist/utils/event-accumulator.d.ts +165 -0
- package/dist/utils/event-accumulator.d.ts.map +1 -0
- package/dist/utils/event-accumulator.js +1278 -0
- package/dist/utils/event-accumulator.js.map +1 -0
- package/dist/utils/json-patch.d.ts +18 -0
- package/dist/utils/json-patch.d.ts.map +1 -0
- package/dist/utils/json-patch.js +35 -0
- package/dist/utils/json-patch.js.map +1 -0
- package/dist/utils/keyed-throttle.d.ts +42 -0
- package/dist/utils/keyed-throttle.d.ts.map +1 -0
- package/dist/utils/keyed-throttle.js +86 -0
- package/dist/utils/keyed-throttle.js.map +1 -0
- package/dist/utils/registry-conversion.d.ts +53 -0
- package/dist/utils/registry-conversion.d.ts.map +1 -0
- package/dist/utils/registry-conversion.js +115 -0
- package/dist/utils/registry-conversion.js.map +1 -0
- package/dist/utils/send-message.d.ts +140 -0
- package/dist/utils/send-message.d.ts.map +1 -0
- package/dist/utils/send-message.js +183 -0
- package/dist/utils/send-message.js.map +1 -0
- package/dist/utils/stream-handler.d.ts +45 -0
- package/dist/utils/stream-handler.d.ts.map +1 -0
- package/dist/utils/stream-handler.js +47 -0
- package/dist/utils/stream-handler.js.map +1 -0
- package/dist/utils/thread-utils.d.ts +16 -0
- package/dist/utils/thread-utils.d.ts.map +1 -0
- package/dist/utils/thread-utils.js +34 -0
- package/dist/utils/thread-utils.js.map +1 -0
- package/dist/utils/tool-call-tracker.d.ts +74 -0
- package/dist/utils/tool-call-tracker.d.ts.map +1 -0
- package/dist/utils/tool-call-tracker.js +181 -0
- package/dist/utils/tool-call-tracker.js.map +1 -0
- package/dist/utils/tool-executor.d.ts +67 -0
- package/dist/utils/tool-executor.d.ts.map +1 -0
- package/dist/utils/tool-executor.js +160 -0
- package/dist/utils/tool-executor.js.map +1 -0
- package/dist/utils/unstrictify.d.ts +32 -0
- package/dist/utils/unstrictify.d.ts.map +1 -0
- package/dist/utils/unstrictify.js +160 -0
- package/dist/utils/unstrictify.js.map +1 -0
- package/esm/index.d.ts +43 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +78 -0
- package/esm/index.js.map +1 -0
- package/esm/mcp/elicitation.d.ts +59 -0
- package/esm/mcp/elicitation.d.ts.map +1 -0
- package/esm/mcp/elicitation.js +27 -0
- package/esm/mcp/elicitation.js.map +1 -0
- package/esm/mcp/index.d.ts +6 -0
- package/esm/mcp/index.d.ts.map +1 -0
- package/esm/mcp/index.js +14 -0
- package/esm/mcp/index.js.map +1 -0
- package/esm/mcp/mcp-client.d.ts +185 -0
- package/esm/mcp/mcp-client.d.ts.map +1 -0
- package/esm/mcp/mcp-client.js +219 -0
- package/esm/mcp/mcp-client.js.map +1 -0
- package/esm/mcp/mcp-constants.d.ts +19 -0
- package/esm/mcp/mcp-constants.d.ts.map +1 -0
- package/esm/mcp/mcp-constants.js +21 -0
- package/esm/mcp/mcp-constants.js.map +1 -0
- package/esm/model/component-metadata.d.ts +390 -0
- package/esm/model/component-metadata.d.ts.map +1 -0
- package/esm/model/component-metadata.js +3 -0
- package/esm/model/component-metadata.js.map +1 -0
- package/esm/model/mcp-server-info.d.ts +72 -0
- package/esm/model/mcp-server-info.d.ts.map +1 -0
- package/esm/model/mcp-server-info.js +29 -0
- package/esm/model/mcp-server-info.js.map +1 -0
- package/esm/schema/index.d.ts +5 -0
- package/esm/schema/index.d.ts.map +1 -0
- package/esm/schema/index.js +15 -0
- package/esm/schema/index.js.map +1 -0
- package/esm/schema/json-schema.d.ts +42 -0
- package/esm/schema/json-schema.d.ts.map +1 -0
- package/esm/schema/json-schema.js +114 -0
- package/esm/schema/json-schema.js.map +1 -0
- package/esm/schema/schema.d.ts +49 -0
- package/esm/schema/schema.d.ts.map +1 -0
- package/esm/schema/schema.js +129 -0
- package/esm/schema/schema.js.map +1 -0
- package/esm/schema/standard-schema.d.ts +22 -0
- package/esm/schema/standard-schema.d.ts.map +1 -0
- package/esm/schema/standard-schema.js +42 -0
- package/esm/schema/standard-schema.js.map +1 -0
- package/esm/schema/validate.d.ts +14 -0
- package/esm/schema/validate.d.ts.map +1 -0
- package/esm/schema/validate.js +148 -0
- package/esm/schema/validate.js.map +1 -0
- package/esm/tambo-client.d.ts +292 -0
- package/esm/tambo-client.d.ts.map +1 -0
- package/esm/tambo-client.js +508 -0
- package/esm/tambo-client.js.map +1 -0
- package/esm/tambo-stream.d.ts +112 -0
- package/esm/tambo-stream.d.ts.map +1 -0
- package/esm/tambo-stream.js +345 -0
- package/esm/tambo-stream.js.map +1 -0
- package/esm/types/auth.d.ts +24 -0
- package/esm/types/auth.d.ts.map +1 -0
- package/esm/types/auth.js +3 -0
- package/esm/types/auth.js.map +1 -0
- package/esm/types/event.d.ts +89 -0
- package/esm/types/event.d.ts.map +1 -0
- package/esm/types/event.js +57 -0
- package/esm/types/event.js.map +1 -0
- package/esm/types/message.d.ts +122 -0
- package/esm/types/message.d.ts.map +1 -0
- package/esm/types/message.js +10 -0
- package/esm/types/message.js.map +1 -0
- package/esm/types/thread.d.ts +58 -0
- package/esm/types/thread.d.ts.map +1 -0
- package/esm/types/thread.js +9 -0
- package/esm/types/thread.js.map +1 -0
- package/esm/types/tool-choice.d.ts +8 -0
- package/esm/types/tool-choice.d.ts.map +1 -0
- package/esm/types/tool-choice.js +3 -0
- package/esm/types/tool-choice.js.map +1 -0
- package/esm/utils/event-accumulator.d.ts +165 -0
- package/esm/utils/event-accumulator.d.ts.map +1 -0
- package/esm/utils/event-accumulator.js +1278 -0
- package/esm/utils/event-accumulator.js.map +1 -0
- package/esm/utils/json-patch.d.ts +18 -0
- package/esm/utils/json-patch.d.ts.map +1 -0
- package/esm/utils/json-patch.js +35 -0
- package/esm/utils/json-patch.js.map +1 -0
- package/esm/utils/keyed-throttle.d.ts +42 -0
- package/esm/utils/keyed-throttle.d.ts.map +1 -0
- package/esm/utils/keyed-throttle.js +86 -0
- package/esm/utils/keyed-throttle.js.map +1 -0
- package/esm/utils/registry-conversion.d.ts +53 -0
- package/esm/utils/registry-conversion.d.ts.map +1 -0
- package/esm/utils/registry-conversion.js +115 -0
- package/esm/utils/registry-conversion.js.map +1 -0
- package/esm/utils/send-message.d.ts +140 -0
- package/esm/utils/send-message.d.ts.map +1 -0
- package/esm/utils/send-message.js +183 -0
- package/esm/utils/send-message.js.map +1 -0
- package/esm/utils/stream-handler.d.ts +45 -0
- package/esm/utils/stream-handler.d.ts.map +1 -0
- package/esm/utils/stream-handler.js +47 -0
- package/esm/utils/stream-handler.js.map +1 -0
- package/esm/utils/thread-utils.d.ts +16 -0
- package/esm/utils/thread-utils.d.ts.map +1 -0
- package/esm/utils/thread-utils.js +34 -0
- package/esm/utils/thread-utils.js.map +1 -0
- package/esm/utils/tool-call-tracker.d.ts +74 -0
- package/esm/utils/tool-call-tracker.d.ts.map +1 -0
- package/esm/utils/tool-call-tracker.js +181 -0
- package/esm/utils/tool-call-tracker.js.map +1 -0
- package/esm/utils/tool-executor.d.ts +67 -0
- package/esm/utils/tool-executor.d.ts.map +1 -0
- package/esm/utils/tool-executor.js +160 -0
- package/esm/utils/tool-executor.js.map +1 -0
- package/esm/utils/unstrictify.d.ts +32 -0
- package/esm/utils/unstrictify.d.ts.map +1 -0
- package/esm/utils/unstrictify.js +160 -0
- package/esm/utils/unstrictify.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tambo-specific Custom Event Types for Streaming API
|
|
4
|
+
*
|
|
5
|
+
* Defines custom events specific to Tambo functionality.
|
|
6
|
+
* For standard AG-UI events, import directly from `@ag-ui/core`.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isTamboCustomEvent = isTamboCustomEvent;
|
|
10
|
+
exports.asTamboCustomEvent = asTamboCustomEvent;
|
|
11
|
+
/**
|
|
12
|
+
* Known Tambo custom event names for type narrowing
|
|
13
|
+
*/
|
|
14
|
+
const TAMBO_CUSTOM_EVENT_NAMES = [
|
|
15
|
+
"tambo.component.start",
|
|
16
|
+
"tambo.component.props_delta",
|
|
17
|
+
"tambo.component.state_delta",
|
|
18
|
+
"tambo.component.end",
|
|
19
|
+
"tambo.run.awaiting_input",
|
|
20
|
+
"tambo.message.parent",
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Type guard to check if an event is a Tambo custom event.
|
|
24
|
+
* Validates that the event has a name matching known Tambo custom event types.
|
|
25
|
+
* @param event - Event object to check
|
|
26
|
+
* @param event.name - Event name to match against known Tambo event types
|
|
27
|
+
* @returns True if event is a TamboCustomEvent
|
|
28
|
+
*/
|
|
29
|
+
function isTamboCustomEvent(event) {
|
|
30
|
+
return (typeof event.name === "string" &&
|
|
31
|
+
TAMBO_CUSTOM_EVENT_NAMES.includes(event.name));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Casts a CustomEvent to the specific TamboCustomEvent type based on its name.
|
|
35
|
+
* Uses exhaustive type checking to ensure all event types are handled.
|
|
36
|
+
* @param event - The CustomEvent to cast
|
|
37
|
+
* @returns The properly typed TamboCustomEvent, or undefined if not a known Tambo event
|
|
38
|
+
*/
|
|
39
|
+
function asTamboCustomEvent(event) {
|
|
40
|
+
switch (event.name) {
|
|
41
|
+
case "tambo.component.start":
|
|
42
|
+
return event;
|
|
43
|
+
case "tambo.component.props_delta":
|
|
44
|
+
return event;
|
|
45
|
+
case "tambo.component.state_delta":
|
|
46
|
+
return event;
|
|
47
|
+
case "tambo.component.end":
|
|
48
|
+
return event;
|
|
49
|
+
case "tambo.run.awaiting_input":
|
|
50
|
+
return event;
|
|
51
|
+
case "tambo.message.parent":
|
|
52
|
+
return event;
|
|
53
|
+
default:
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA0HH,gDAOC;AAQD,gDAmBC;AArDD;;GAEG;AACH,MAAM,wBAAwB,GAAG;IAC/B,uBAAuB;IACvB,6BAA6B;IAC7B,6BAA6B;IAC7B,qBAAqB;IACrB,0BAA0B;IAC1B,sBAAsB;CACd,CAAC;AAEX;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,KAElC;IACC,OAAO,CACL,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC7B,wBAA8C,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CACrE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,KAAkB;IAElB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,uBAAuB;YAC1B,OAAO,KAA4B,CAAC;QACtC,KAAK,6BAA6B;YAChC,OAAO,KAAiC,CAAC;QAC3C,KAAK,6BAA6B;YAChC,OAAO,KAAiC,CAAC;QAC3C,KAAK,qBAAqB;YACxB,OAAO,KAA0B,CAAC;QACpC,KAAK,0BAA0B;YAC7B,OAAO,KAA8B,CAAC;QACxC,KAAK,sBAAsB;YACzB,OAAO,KAA2B,CAAC;QACrC;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["/**\n * Tambo-specific Custom Event Types for Streaming API\n *\n * Defines custom events specific to Tambo functionality.\n * For standard AG-UI events, import directly from `@ag-ui/core`.\n */\n\nimport type { CustomEvent } from \"@ag-ui/core\";\nimport type { Operation } from \"fast-json-patch\";\n\ntype TamboCustomEventEnvelope<TName extends string, TValue> = Omit<\n CustomEvent,\n \"name\" | \"value\"\n> & {\n name: TName;\n value: TValue;\n};\n\n/**\n * Component start event (custom: tambo.component.start)\n */\nexport type ComponentStartEvent = TamboCustomEventEnvelope<\n \"tambo.component.start\",\n {\n messageId: string;\n componentId: string;\n componentName: string;\n }\n>;\n\n/**\n * Component props delta event (custom: tambo.component.props_delta)\n * Uses JSON Patch (RFC 6902) to update component props\n */\nexport type ComponentPropsDeltaEvent = TamboCustomEventEnvelope<\n \"tambo.component.props_delta\",\n {\n componentId: string;\n operations: Operation[];\n }\n>;\n\n/**\n * Component state delta event (custom: tambo.component.state_delta)\n * Uses JSON Patch (RFC 6902) to update component state\n */\nexport type ComponentStateDeltaEvent = TamboCustomEventEnvelope<\n \"tambo.component.state_delta\",\n {\n componentId: string;\n operations: Operation[];\n }\n>;\n\n/**\n * Component end event (custom: tambo.component.end)\n */\nexport type ComponentEndEvent = TamboCustomEventEnvelope<\n \"tambo.component.end\",\n {\n componentId: string;\n }\n>;\n\n/**\n * Pending tool call information from awaiting_input event\n */\nexport interface PendingToolCall {\n toolCallId: string;\n toolName: string;\n arguments: string;\n}\n\n/**\n * Run awaiting input event (custom: tambo.run.awaiting_input)\n * Signals that the run is paused waiting for client-side tool execution\n */\nexport type RunAwaitingInputEvent = TamboCustomEventEnvelope<\n \"tambo.run.awaiting_input\",\n {\n pendingToolCalls: PendingToolCall[];\n }\n>;\n\n/**\n * Message parent event (custom: tambo.message.parent)\n * Emitted when a message was created during the generation of another message\n * (e.g., MCP sampling or elicitation).\n */\nexport type MessageParentEvent = TamboCustomEventEnvelope<\n \"tambo.message.parent\",\n {\n messageId: string;\n parentMessageId: string;\n }\n>;\n\n/**\n * Union type of Tambo-specific custom events\n */\nexport type TamboCustomEvent =\n | ComponentStartEvent\n | ComponentPropsDeltaEvent\n | ComponentStateDeltaEvent\n | ComponentEndEvent\n | RunAwaitingInputEvent\n | MessageParentEvent;\n\n/**\n * Known Tambo custom event names for type narrowing\n */\nconst TAMBO_CUSTOM_EVENT_NAMES = [\n \"tambo.component.start\",\n \"tambo.component.props_delta\",\n \"tambo.component.state_delta\",\n \"tambo.component.end\",\n \"tambo.run.awaiting_input\",\n \"tambo.message.parent\",\n] as const;\n\n/**\n * Type guard to check if an event is a Tambo custom event.\n * Validates that the event has a name matching known Tambo custom event types.\n * @param event - Event object to check\n * @param event.name - Event name to match against known Tambo event types\n * @returns True if event is a TamboCustomEvent\n */\nexport function isTamboCustomEvent(event: {\n name?: string;\n}): event is TamboCustomEvent {\n return (\n typeof event.name === \"string\" &&\n (TAMBO_CUSTOM_EVENT_NAMES as readonly string[]).includes(event.name)\n );\n}\n\n/**\n * Casts a CustomEvent to the specific TamboCustomEvent type based on its name.\n * Uses exhaustive type checking to ensure all event types are handled.\n * @param event - The CustomEvent to cast\n * @returns The properly typed TamboCustomEvent, or undefined if not a known Tambo event\n */\nexport function asTamboCustomEvent(\n event: CustomEvent,\n): TamboCustomEvent | undefined {\n switch (event.name) {\n case \"tambo.component.start\":\n return event as ComponentStartEvent;\n case \"tambo.component.props_delta\":\n return event as ComponentPropsDeltaEvent;\n case \"tambo.component.state_delta\":\n return event as ComponentStateDeltaEvent;\n case \"tambo.component.end\":\n return event as ComponentEndEvent;\n case \"tambo.run.awaiting_input\":\n return event as RunAwaitingInputEvent;\n case \"tambo.message.parent\":\n return event as MessageParentEvent;\n default:\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message and Content Types
|
|
3
|
+
*
|
|
4
|
+
* Re-exports message and content types from `@tambo-ai/typescript-sdk`.
|
|
5
|
+
* Messages use Anthropic-style content blocks pattern where a message
|
|
6
|
+
* contains an array of content blocks (text, tool calls, tool results, components).
|
|
7
|
+
*/
|
|
8
|
+
export type { TextContent, ToolResultContent, ResourceContent, } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
9
|
+
export type { InputMessage } from "@tambo-ai/typescript-sdk/resources/threads/runs";
|
|
10
|
+
import type { RunCreateParams } from "@tambo-ai/typescript-sdk/resources/threads/runs";
|
|
11
|
+
/**
|
|
12
|
+
* Message type for initial messages that seed a new thread.
|
|
13
|
+
* Supports system and assistant roles in addition to user,
|
|
14
|
+
* and restricts content to text and resource blocks (no tool results).
|
|
15
|
+
*/
|
|
16
|
+
export type InitialInputMessage = RunCreateParams.Thread.InitialMessage;
|
|
17
|
+
export type { MessageListResponse, MessageGetResponse, } from "@tambo-ai/typescript-sdk/resources/threads/messages";
|
|
18
|
+
import type { TextContent, ToolUseContent, ToolResultContent, ComponentContent, ResourceContent } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
19
|
+
/**
|
|
20
|
+
* Streaming state for component content blocks.
|
|
21
|
+
* Tracks the lifecycle of component prop/state streaming.
|
|
22
|
+
*/
|
|
23
|
+
export type ComponentStreamingState = "started" | "streaming" | "done";
|
|
24
|
+
/**
|
|
25
|
+
* Extended ComponentContent with streaming state.
|
|
26
|
+
* Used by the SDK to track component rendering lifecycle.
|
|
27
|
+
*/
|
|
28
|
+
export interface TamboComponentContent extends ComponentContent {
|
|
29
|
+
/**
|
|
30
|
+
* Current streaming state of this component's props.
|
|
31
|
+
* - 'started': Component block created, awaiting props
|
|
32
|
+
* - 'streaming': Props are being streamed
|
|
33
|
+
* - 'done': Props streaming complete
|
|
34
|
+
*
|
|
35
|
+
* Optional for historical messages loaded from API (defaults to "done").
|
|
36
|
+
*/
|
|
37
|
+
streamingState?: ComponentStreamingState;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Special display properties that can be included in tool input.
|
|
41
|
+
* These are used to customize tool status messages shown in the UI.
|
|
42
|
+
*/
|
|
43
|
+
export interface TamboToolDisplayProps {
|
|
44
|
+
/** Message shown while the tool is executing */
|
|
45
|
+
_tambo_statusMessage?: string;
|
|
46
|
+
/** Message shown after the tool completes */
|
|
47
|
+
_tambo_completionStatusMessage?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Extended ToolUseContent with computed state properties.
|
|
51
|
+
* Used by the SDK to provide pre-computed tool state to consumers.
|
|
52
|
+
*
|
|
53
|
+
* Note: The computed properties are populated by `useTambo()` hook.
|
|
54
|
+
* When accessed via lower-level APIs, they may be undefined.
|
|
55
|
+
*/
|
|
56
|
+
export interface TamboToolUseContent extends Omit<ToolUseContent, "input"> {
|
|
57
|
+
/**
|
|
58
|
+
* Tool input parameters with internal `_tambo_*` properties removed.
|
|
59
|
+
* Consumers see only the actual tool parameters.
|
|
60
|
+
*/
|
|
61
|
+
input: Record<string, unknown>;
|
|
62
|
+
/**
|
|
63
|
+
* Whether this tool call has completed (has a matching tool_result).
|
|
64
|
+
* Computed by `useTambo()` based on presence of matching tool_result.
|
|
65
|
+
*/
|
|
66
|
+
hasCompleted?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The status message to display, resolved based on tool execution state.
|
|
69
|
+
* Automatically updates as tool progresses through execution lifecycle.
|
|
70
|
+
* Computed by `useTambo()`.
|
|
71
|
+
*/
|
|
72
|
+
statusMessage?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Extracted Tambo display properties from the tool input.
|
|
75
|
+
* Consumers can use these for custom rendering if needed.
|
|
76
|
+
* Computed by `useTambo()`.
|
|
77
|
+
*/
|
|
78
|
+
tamboDisplayProps?: TamboToolDisplayProps;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Message role (from SDK)
|
|
82
|
+
* Includes 'system' to accommodate messages loaded from API.
|
|
83
|
+
*/
|
|
84
|
+
export type MessageRole = "user" | "assistant" | "system";
|
|
85
|
+
/**
|
|
86
|
+
* Union type of all content block types.
|
|
87
|
+
* Uses TamboComponentContent and TamboToolUseContent which include computed state.
|
|
88
|
+
*/
|
|
89
|
+
export type Content = TextContent | TamboToolUseContent | ToolResultContent | TamboComponentContent | ResourceContent;
|
|
90
|
+
/**
|
|
91
|
+
* Message in a thread (simplified from SDK's MessageGetResponse)
|
|
92
|
+
*/
|
|
93
|
+
export interface TamboThreadMessage {
|
|
94
|
+
/** Unique message identifier */
|
|
95
|
+
id: string;
|
|
96
|
+
/** Message role (user or assistant) */
|
|
97
|
+
role: MessageRole;
|
|
98
|
+
/** Content blocks in the message */
|
|
99
|
+
content: Content[];
|
|
100
|
+
/** When the message was created (optional for historical messages loaded from API) */
|
|
101
|
+
createdAt?: string;
|
|
102
|
+
/** Message metadata */
|
|
103
|
+
metadata?: Record<string, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* The id of the parent message, if this message was created during
|
|
106
|
+
* generation of another message (e.g., MCP sampling or elicitation).
|
|
107
|
+
*/
|
|
108
|
+
parentMessageId?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Reasoning content from the model (transient - only during streaming).
|
|
111
|
+
* Each element is a reasoning "chunk" - models may emit multiple reasoning blocks.
|
|
112
|
+
* This data is not persisted to the database and will not be present in
|
|
113
|
+
* messages loaded from the API.
|
|
114
|
+
*/
|
|
115
|
+
reasoning?: string[];
|
|
116
|
+
/**
|
|
117
|
+
* Duration of the reasoning phase in milliseconds (for display purposes).
|
|
118
|
+
* Populated when reasoning completes.
|
|
119
|
+
*/
|
|
120
|
+
reasoningDurationMS?: number;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,eAAe,GAChB,MAAM,oDAAoD,CAAC;AAG5D,YAAY,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAEvF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,cAAc,CAAC;AAExE,YAAY,EACV,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qDAAqD,CAAC;AAG7D,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,oDAAoD,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,6CAA6C;IAC7C,8BAA8B,CAAC,EAAE,MAAM,CAAC;CACzC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;IACxE;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;CAC3C;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,OAAO,GACf,WAAW,GACX,mBAAmB,GACnB,iBAAiB,GACjB,qBAAqB,GACrB,eAAe,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IAEX,uCAAuC;IACvC,IAAI,EAAE,WAAW,CAAC;IAElB,oCAAoC;IACpC,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Message and Content Types
|
|
4
|
+
*
|
|
5
|
+
* Re-exports message and content types from `@tambo-ai/typescript-sdk`.
|
|
6
|
+
* Messages use Anthropic-style content blocks pattern where a message
|
|
7
|
+
* contains an array of content blocks (text, tool calls, tool results, components).
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Message and Content Types\n *\n * Re-exports message and content types from `@tambo-ai/typescript-sdk`.\n * Messages use Anthropic-style content blocks pattern where a message\n * contains an array of content blocks (text, tool calls, tool results, components).\n */\n\n// Re-export content block types from TypeScript SDK\n// Note: ToolUseContent and ComponentContent are NOT re-exported - use TamboToolUseContent\n// and TamboComponentContent instead, which include computed state properties.\nexport type {\n TextContent,\n ToolResultContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n// Re-export message types from TypeScript SDK\nexport type { InputMessage } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\nimport type { RunCreateParams } from \"@tambo-ai/typescript-sdk/resources/threads/runs\";\n\n/**\n * Message type for initial messages that seed a new thread.\n * Supports system and assistant roles in addition to user,\n * and restricts content to text and resource blocks (no tool results).\n */\nexport type InitialInputMessage = RunCreateParams.Thread.InitialMessage;\n\nexport type {\n MessageListResponse,\n MessageGetResponse,\n} from \"@tambo-ai/typescript-sdk/resources/threads/messages\";\n\n// Import for Content union type\nimport type {\n TextContent,\n ToolUseContent,\n ToolResultContent,\n ComponentContent,\n ResourceContent,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Streaming state for component content blocks.\n * Tracks the lifecycle of component prop/state streaming.\n */\nexport type ComponentStreamingState = \"started\" | \"streaming\" | \"done\";\n\n/**\n * Extended ComponentContent with streaming state.\n * Used by the SDK to track component rendering lifecycle.\n */\nexport interface TamboComponentContent extends ComponentContent {\n /**\n * Current streaming state of this component's props.\n * - 'started': Component block created, awaiting props\n * - 'streaming': Props are being streamed\n * - 'done': Props streaming complete\n *\n * Optional for historical messages loaded from API (defaults to \"done\").\n */\n streamingState?: ComponentStreamingState;\n}\n\n/**\n * Special display properties that can be included in tool input.\n * These are used to customize tool status messages shown in the UI.\n */\nexport interface TamboToolDisplayProps {\n /** Message shown while the tool is executing */\n _tambo_statusMessage?: string;\n /** Message shown after the tool completes */\n _tambo_completionStatusMessage?: string;\n}\n\n/**\n * Extended ToolUseContent with computed state properties.\n * Used by the SDK to provide pre-computed tool state to consumers.\n *\n * Note: The computed properties are populated by `useTambo()` hook.\n * When accessed via lower-level APIs, they may be undefined.\n */\nexport interface TamboToolUseContent extends Omit<ToolUseContent, \"input\"> {\n /**\n * Tool input parameters with internal `_tambo_*` properties removed.\n * Consumers see only the actual tool parameters.\n */\n input: Record<string, unknown>;\n\n /**\n * Whether this tool call has completed (has a matching tool_result).\n * Computed by `useTambo()` based on presence of matching tool_result.\n */\n hasCompleted?: boolean;\n\n /**\n * The status message to display, resolved based on tool execution state.\n * Automatically updates as tool progresses through execution lifecycle.\n * Computed by `useTambo()`.\n */\n statusMessage?: string;\n\n /**\n * Extracted Tambo display properties from the tool input.\n * Consumers can use these for custom rendering if needed.\n * Computed by `useTambo()`.\n */\n tamboDisplayProps?: TamboToolDisplayProps;\n}\n\n/**\n * Message role (from SDK)\n * Includes 'system' to accommodate messages loaded from API.\n */\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\n\n/**\n * Union type of all content block types.\n * Uses TamboComponentContent and TamboToolUseContent which include computed state.\n */\nexport type Content =\n | TextContent\n | TamboToolUseContent\n | ToolResultContent\n | TamboComponentContent\n | ResourceContent;\n\n/**\n * Message in a thread (simplified from SDK's MessageGetResponse)\n */\nexport interface TamboThreadMessage {\n /** Unique message identifier */\n id: string;\n\n /** Message role (user or assistant) */\n role: MessageRole;\n\n /** Content blocks in the message */\n content: Content[];\n\n /** When the message was created (optional for historical messages loaded from API) */\n createdAt?: string;\n\n /** Message metadata */\n metadata?: Record<string, unknown>;\n\n /**\n * The id of the parent message, if this message was created during\n * generation of another message (e.g., MCP sampling or elicitation).\n */\n parentMessageId?: string;\n\n /**\n * Reasoning content from the model (transient - only during streaming).\n * Each element is a reasoning \"chunk\" - models may emit multiple reasoning blocks.\n * This data is not persisted to the database and will not be present in\n * messages loaded from the API.\n */\n reasoning?: string[];\n\n /**\n * Duration of the reasoning phase in milliseconds (for display purposes).\n * Populated when reasoning completes.\n */\n reasoningDurationMS?: number;\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thread Types
|
|
3
|
+
*
|
|
4
|
+
* Re-exports thread types from `@tambo-ai/typescript-sdk` and defines
|
|
5
|
+
* React-specific extensions for streaming state management.
|
|
6
|
+
*/
|
|
7
|
+
import type { TamboThreadMessage } from "./message";
|
|
8
|
+
export type { ThreadCreateResponse, ThreadRetrieveResponse, ThreadListResponse, } from "@tambo-ai/typescript-sdk/resources/threads/threads";
|
|
9
|
+
/**
|
|
10
|
+
* Run status indicates the current state of the thread's run lifecycle.
|
|
11
|
+
* Matches the API's RunStatus — no "complete" or "error" variants.
|
|
12
|
+
* Error information is tracked separately in StreamingState.error.
|
|
13
|
+
*/
|
|
14
|
+
export type RunStatus = "idle" | "waiting" | "streaming";
|
|
15
|
+
/**
|
|
16
|
+
* Thread represents a conversation with the AI
|
|
17
|
+
* Extended from SDK's ThreadRetrieveResponse with additional fields for React state
|
|
18
|
+
*/
|
|
19
|
+
export interface TamboThread {
|
|
20
|
+
/** Unique thread identifier */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Thread name */
|
|
23
|
+
name?: string;
|
|
24
|
+
/** Messages in the thread */
|
|
25
|
+
messages: TamboThreadMessage[];
|
|
26
|
+
/** Current run status */
|
|
27
|
+
status: RunStatus;
|
|
28
|
+
/** Thread metadata */
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
/** When the thread was created */
|
|
31
|
+
createdAt: string;
|
|
32
|
+
/** When the thread was last updated */
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
/** Whether the last run was cancelled (resets to false when a new run starts) */
|
|
35
|
+
lastRunCancelled: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Streaming state tracks the progress of an active run
|
|
39
|
+
* This is React-specific and not part of the SDK
|
|
40
|
+
*/
|
|
41
|
+
export interface StreamingState {
|
|
42
|
+
/** Current streaming status */
|
|
43
|
+
status: RunStatus;
|
|
44
|
+
/** Active run ID (if streaming) */
|
|
45
|
+
runId?: string;
|
|
46
|
+
/** Active message ID being streamed */
|
|
47
|
+
messageId?: string;
|
|
48
|
+
/** When the current run started */
|
|
49
|
+
startTime?: number;
|
|
50
|
+
/** When reasoning started (for duration calculation) */
|
|
51
|
+
reasoningStartTime?: number;
|
|
52
|
+
/** Error information if status is 'error' */
|
|
53
|
+
error?: {
|
|
54
|
+
message: string;
|
|
55
|
+
code?: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/types/thread.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAGpD,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,oDAAoD,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,6BAA6B;IAC7B,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAE/B,yBAAyB;IACzB,MAAM,EAAE,SAAS,CAAC;IAElB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAElB,iFAAiF;IACjF,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,MAAM,EAAE,SAAS,CAAC;IAElB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,6CAA6C;IAC7C,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Thread Types
|
|
4
|
+
*
|
|
5
|
+
* Re-exports thread types from `@tambo-ai/typescript-sdk` and defines
|
|
6
|
+
* React-specific extensions for streaming state management.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=thread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../../src/types/thread.ts"],"names":[],"mappings":";AAAA;;;;;GAKG","sourcesContent":["/**\n * Thread Types\n *\n * Re-exports thread types from `@tambo-ai/typescript-sdk` and defines\n * React-specific extensions for streaming state management.\n */\n\nimport type { TamboThreadMessage } from \"./message\";\n\n// Re-export thread types from TypeScript SDK\nexport type {\n ThreadCreateResponse,\n ThreadRetrieveResponse,\n ThreadListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/threads/threads\";\n\n/**\n * Run status indicates the current state of the thread's run lifecycle.\n * Matches the API's RunStatus — no \"complete\" or \"error\" variants.\n * Error information is tracked separately in StreamingState.error.\n */\nexport type RunStatus = \"idle\" | \"waiting\" | \"streaming\";\n\n/**\n * Thread represents a conversation with the AI\n * Extended from SDK's ThreadRetrieveResponse with additional fields for React state\n */\nexport interface TamboThread {\n /** Unique thread identifier */\n id: string;\n\n /** Thread name */\n name?: string;\n\n /** Messages in the thread */\n messages: TamboThreadMessage[];\n\n /** Current run status */\n status: RunStatus;\n\n /** Thread metadata */\n metadata?: Record<string, unknown>;\n\n /** When the thread was created */\n createdAt: string;\n\n /** When the thread was last updated */\n updatedAt: string;\n\n /** Whether the last run was cancelled (resets to false when a new run starts) */\n lastRunCancelled: boolean;\n}\n\n/**\n * Streaming state tracks the progress of an active run\n * This is React-specific and not part of the SDK\n */\nexport interface StreamingState {\n /** Current streaming status */\n status: RunStatus;\n\n /** Active run ID (if streaming) */\n runId?: string;\n\n /** Active message ID being streamed */\n messageId?: string;\n\n /** When the current run started */\n startTime?: number;\n\n /** When reasoning started (for duration calculation) */\n reasoningStartTime?: number;\n\n /** Error information if status is 'error' */\n error?: {\n message: string;\n code?: string;\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-choice.d.ts","sourceRoot":"","sources":["../../src/types/tool-choice.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,UAAU,GACV,MAAM,GACN;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-choice.js","sourceRoot":"","sources":["../../src/types/tool-choice.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Tool choice type matching the API format.\n * Controls how the model selects tools during generation.\n */\nexport type ToolChoice =\n | \"auto\" // Model decides (default)\n | \"required\" // Must use at least one tool\n | \"none\" // Cannot use tools\n | { name: string }; // Must use specific tool\n"]}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Accumulation Logic for Streaming API
|
|
3
|
+
*
|
|
4
|
+
* Implements a reducer that transforms AG-UI event streams into React state.
|
|
5
|
+
* Used with useReducer to accumulate events into thread state.
|
|
6
|
+
*/
|
|
7
|
+
import type { AGUIEvent } from "@ag-ui/core";
|
|
8
|
+
import type { InitialInputMessage, TamboThreadMessage } from "../types/message";
|
|
9
|
+
import type { StreamingState, TamboThread } from "../types/thread";
|
|
10
|
+
import type { JSONSchema7 } from "json-schema";
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when an unreachable case is reached in a switch statement.
|
|
13
|
+
* This indicates a programming error where not all cases were handled.
|
|
14
|
+
*/
|
|
15
|
+
export declare class UnreachableCaseError extends Error {
|
|
16
|
+
constructor(value: never);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Per-thread state managed by the stream reducer.
|
|
20
|
+
* Tracks thread data, streaming status, and accumulating data.
|
|
21
|
+
*/
|
|
22
|
+
export interface ThreadState {
|
|
23
|
+
thread: TamboThread;
|
|
24
|
+
streaming: StreamingState;
|
|
25
|
+
/**
|
|
26
|
+
* Accumulating tool call arguments as JSON strings (for streaming).
|
|
27
|
+
* Maps tool call ID to accumulated JSON string.
|
|
28
|
+
*/
|
|
29
|
+
accumulatingToolArgs: Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* ID of the last completed run. Persists across the session so it's
|
|
32
|
+
* available as `previousRunId` when sending follow-up messages, even
|
|
33
|
+
* after the streaming state has been cleared (e.g., after page reload
|
|
34
|
+
* and thread re-fetch).
|
|
35
|
+
*/
|
|
36
|
+
lastCompletedRunId?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* State managed by the stream reducer.
|
|
40
|
+
* Maintains a map of all threads being tracked.
|
|
41
|
+
*/
|
|
42
|
+
export interface StreamState {
|
|
43
|
+
/**
|
|
44
|
+
* Map of thread ID to thread state
|
|
45
|
+
*/
|
|
46
|
+
threadMap: Record<string, ThreadState>;
|
|
47
|
+
/**
|
|
48
|
+
* Current active thread ID (for UI context)
|
|
49
|
+
*/
|
|
50
|
+
currentThreadId: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Event action - dispatches an AG-UI event to update thread state.
|
|
54
|
+
*/
|
|
55
|
+
export interface EventAction {
|
|
56
|
+
type: "EVENT";
|
|
57
|
+
event: AGUIEvent;
|
|
58
|
+
threadId: string;
|
|
59
|
+
/** Pre-parsed partial JSON args for TOOL_CALL_ARGS events. Avoids double-parsing. */
|
|
60
|
+
parsedToolArgs?: Record<string, unknown>;
|
|
61
|
+
/** Original tool schemas for unstrictifying tool call args at TOOL_CALL_END. */
|
|
62
|
+
toolSchemas?: Map<string, JSONSchema7>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Initialize thread action - creates a new thread in the threadMap.
|
|
66
|
+
*/
|
|
67
|
+
export interface InitThreadAction {
|
|
68
|
+
type: "INIT_THREAD";
|
|
69
|
+
threadId: string;
|
|
70
|
+
initialThread?: Partial<TamboThread>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Set current thread action - changes the active thread.
|
|
74
|
+
*/
|
|
75
|
+
export interface SetCurrentThreadAction {
|
|
76
|
+
type: "SET_CURRENT_THREAD";
|
|
77
|
+
threadId: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Start new thread action - atomically creates and switches to a new thread.
|
|
81
|
+
* This prevents race conditions when multiple calls happen concurrently.
|
|
82
|
+
*/
|
|
83
|
+
export interface StartNewThreadAction {
|
|
84
|
+
type: "START_NEW_THREAD";
|
|
85
|
+
threadId: string;
|
|
86
|
+
initialThread?: Partial<TamboThread>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Load thread messages action - loads messages from API into stream state.
|
|
90
|
+
* Used when switching to an existing thread to populate its messages.
|
|
91
|
+
*/
|
|
92
|
+
export interface LoadThreadMessagesAction {
|
|
93
|
+
type: "LOAD_THREAD_MESSAGES";
|
|
94
|
+
threadId: string;
|
|
95
|
+
messages: TamboThreadMessage[];
|
|
96
|
+
/**
|
|
97
|
+
* If true, skip loading if the thread is currently streaming.
|
|
98
|
+
* This prevents overwriting in-flight streaming messages.
|
|
99
|
+
*/
|
|
100
|
+
skipIfStreaming?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Set last completed run ID action - stores metadata from the API
|
|
104
|
+
* so it can be used as `previousRunId` for follow-up messages.
|
|
105
|
+
*/
|
|
106
|
+
export interface SetLastCompletedRunIdAction {
|
|
107
|
+
type: "SET_LAST_COMPLETED_RUN_ID";
|
|
108
|
+
threadId: string;
|
|
109
|
+
lastCompletedRunId: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Update thread name action - sets the name on a thread.
|
|
113
|
+
* Used after auto-generating a thread name via the API.
|
|
114
|
+
*/
|
|
115
|
+
export interface UpdateThreadNameAction {
|
|
116
|
+
type: "UPDATE_THREAD_NAME";
|
|
117
|
+
threadId: string;
|
|
118
|
+
name: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Action type for the stream reducer.
|
|
122
|
+
*/
|
|
123
|
+
export type StreamAction = EventAction | InitThreadAction | SetCurrentThreadAction | StartNewThreadAction | LoadThreadMessagesAction | SetLastCompletedRunIdAction | UpdateThreadNameAction;
|
|
124
|
+
/**
|
|
125
|
+
* Create initial thread state for a new thread.
|
|
126
|
+
* @param threadId - Unique thread identifier
|
|
127
|
+
* @returns Initial thread state
|
|
128
|
+
*/
|
|
129
|
+
export declare function createInitialThreadState(threadId: string): ThreadState;
|
|
130
|
+
/**
|
|
131
|
+
* Placeholder thread ID used for new threads before they get a real ID from the server.
|
|
132
|
+
* This allows optimistic UI updates (showing user messages immediately) before the
|
|
133
|
+
* server responds with the actual thread ID.
|
|
134
|
+
*/
|
|
135
|
+
export declare const PLACEHOLDER_THREAD_ID = "placeholder";
|
|
136
|
+
/**
|
|
137
|
+
* Check if a thread ID is a placeholder (not a real API thread ID).
|
|
138
|
+
* @param threadId - Thread ID to check
|
|
139
|
+
* @returns True if this is a placeholder thread ID
|
|
140
|
+
*/
|
|
141
|
+
export declare function isPlaceholderThreadId(threadId: string | null | undefined): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Create initial stream state with placeholder thread.
|
|
144
|
+
* @returns Initial stream state
|
|
145
|
+
*/
|
|
146
|
+
export declare function createInitialState(): StreamState;
|
|
147
|
+
/**
|
|
148
|
+
* Create initial stream state with placeholder thread seeded with initial messages.
|
|
149
|
+
* The messages are converted from InputMessage format to TamboThreadMessage format
|
|
150
|
+
* for immediate UI display before any API call.
|
|
151
|
+
* @param initialMessages - Messages to seed the placeholder thread with
|
|
152
|
+
* @returns Initial stream state with messages in the placeholder thread
|
|
153
|
+
*/
|
|
154
|
+
export declare function createInitialStateWithMessages(initialMessages: InitialInputMessage[]): StreamState;
|
|
155
|
+
/**
|
|
156
|
+
* Stream reducer that accumulates events into thread state.
|
|
157
|
+
*
|
|
158
|
+
* This reducer handles all AG-UI events and Tambo custom events,
|
|
159
|
+
* transforming them into immutable state updates per thread.
|
|
160
|
+
* @param state - Current stream state
|
|
161
|
+
* @param action - Action to process
|
|
162
|
+
* @returns Updated stream state
|
|
163
|
+
*/
|
|
164
|
+
export declare function streamReducer(state: StreamState, action: StreamAction): StreamState;
|
|
165
|
+
//# sourceMappingURL=event-accumulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-accumulator.d.ts","sourceRoot":"","sources":["../../src/utils/event-accumulator.ts"],"names":[],"mappings":"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"}
|