@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 @@
|
|
|
1
|
+
{"version":3,"file":"unstrictify.js","sourceRoot":"","sources":["../../src/utils/unstrictify.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAoJH,kFA4BC;AAOD,8BAaC;AAhMD;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAChC,uBAAoC,EACpC,qBAA8C;IAE9C,IAAI,uBAAuB,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,6DAA6D,uBAAuB,CAAC,IAAI,MAAM,OAAO,uBAAuB,EAAE,CAChI,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC;SACpD,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,cAAc,CAAC,EAAE,EAAE;QACvC,MAAM,UAAU,GACd,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC5D,6CAA6C;QAC7C,MAAM,mBAAmB,GACvB,aAAa,IAAI,CAAC,uBAAuB,CAAC,UAAU,IAAI,EAAE,CAAC;YACzD,CAAC,CAAC,uBAAuB,CAAC,UAAU,EAAE,CAAC,aAAa,CAAC;Y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CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Unstrictify tool call parameters using the original JSON Schema.\n *\n * When OpenAI's structured outputs mode is enabled, all optional parameters\n * become required-and-nullable. The LLM then sends `null` for parameters the\n * user didn't specify. This module reverses that transformation by comparing\n * the LLM's output against the original schema and stripping nulls for\n * parameters that were originally optional and non-nullable.\n *\n * Copied from packages/core/src/strictness/tool-call-strict.ts (minus the\n * OpenAI-specific `unstrictifyToolCallRequest` wrapper).\n */\n\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\n\n/**\n * Unstrictify the parameters of a tool call request.\n *\n * This effectively reverses the process of strictifyToolCallParams, for a\n * tool call request that was built from a strict JSON Schema, by returning a\n * updated tool call request with the parameter values unstrictified.\n * @returns The params with strictification-induced nulls stripped.\n */\nfunction unstrictifyToolCallParams(\n originalToolParamSchema: JSONSchema7,\n toolCallRequestParams: Record<string, unknown>,\n): Record<string, unknown> {\n if (originalToolParamSchema.type !== \"object\") {\n throw new Error(\n `tool call parameter schema must be an object, instead got ${originalToolParamSchema.type} / ${typeof originalToolParamSchema}`,\n );\n }\n const newParams = Object.entries(toolCallRequestParams)\n .map(([parameterName, parameterValue]) => {\n const isRequired =\n originalToolParamSchema.required?.includes(parameterName);\n // find the param in the original tool schema\n const originalParamSchema =\n parameterName in (originalToolParamSchema.properties ?? {})\n ? originalToolParamSchema.properties?.[parameterName]\n : undefined;\n\n // This should never happen, because the strict schema was derived from\n // the original schema, so the parameter should always be present.\n if (!originalParamSchema) {\n throw new Error(\n `Tool call request parameter ${parameterName} not found in original tool`,\n );\n }\n\n if (\n parameterValue === null &&\n !canBeNull(originalParamSchema) &&\n !isRequired\n ) {\n // This is the meat of this function. In the strict schema, this is\n // \"required and can be null\", but in the original schema, the param was\n // not required.\n if (\n typeof originalParamSchema === \"object\" &&\n \"default\" in originalParamSchema\n ) {\n return [parameterName, originalParamSchema.default] as const;\n }\n return undefined;\n }\n\n // recurse into arrays\n if (\n typeof originalParamSchema === \"object\" &&\n originalParamSchema.type === \"array\"\n ) {\n const arrayValue = parameterValue as unknown[];\n const itemSchema = originalParamSchema.items;\n if (\n Array.isArray(arrayValue) &&\n itemSchema &&\n typeof itemSchema === \"object\" &&\n !Array.isArray(itemSchema)\n ) {\n const newArrayValue = arrayValue.map((item) => {\n if (\n itemSchema.type === \"object\" &&\n typeof item === \"object\" &&\n item !== null\n ) {\n // recurse into each object in the array\n return unstrictifyToolCallParams(\n itemSchema,\n item as Record<string, unknown>,\n );\n }\n return item;\n });\n return [parameterName, newArrayValue] as const;\n }\n return [parameterName, parameterValue] as const;\n }\n\n // recurse into the parameter value, passing along the matching original schema\n if (\n typeof originalParamSchema === \"object\" &&\n originalParamSchema.type === \"object\"\n ) {\n // If the LLM sent a JSON string instead of an object (common with z.any() schemas),\n // try to parse it\n let objectValue = parameterValue;\n if (typeof parameterValue === \"string\") {\n try {\n const parsed = JSON.parse(parameterValue);\n if (typeof parsed === \"object\" && parsed !== null) {\n objectValue = parsed;\n }\n } catch {\n // Not valid JSON, keep original value\n }\n }\n\n // Only recurse if we have an actual object AND the schema has properties defined.\n // If the schema has no properties (e.g., z.any() which produces {type: 'object', anyOf: [...]}),\n // just return the value as-is without recursing.\n const hasProperties =\n originalParamSchema.properties &&\n Object.keys(originalParamSchema.properties).length > 0;\n\n if (\n hasProperties &&\n typeof objectValue === \"object\" &&\n objectValue !== null &&\n !Array.isArray(objectValue)\n ) {\n const newParamValue = unstrictifyToolCallParams(\n originalParamSchema,\n objectValue as Record<string, unknown>,\n );\n return [parameterName, newParamValue] as const;\n }\n\n // Return the (possibly parsed) object value without recursing\n return [parameterName, objectValue] as const;\n }\n\n return [parameterName, parameterValue] as const;\n })\n .filter((param) => param !== undefined);\n return Object.fromEntries(newParams);\n}\n\n/**\n * Unstrictify tool call params using the original JSON Schema.\n *\n * Unlike the private `unstrictifyToolCallParams` which throws on unknown params,\n * this function separates params into schema-defined vs `_tambo_*` pass-through\n * (server-injected params not in the original schema), unstrictifies only the\n * schema-defined ones, and merges pass-through params back. Unknown keys that\n * aren't in the schema and don't have the `_tambo_` prefix are dropped.\n * @returns The params with strictification-induced nulls stripped for optional\n * non-nullable properties, and pass-through params preserved as-is.\n */\nexport function unstrictifyToolCallParamsFromSchema(\n originalSchema: JSONSchema7,\n params: Record<string, unknown>,\n): Record<string, unknown> {\n if (originalSchema.type !== \"object\") {\n return params;\n }\n\n const schemaProperties = originalSchema.properties ?? {};\n const schemaDefinedParams: Record<string, unknown> = {};\n const passThroughParams: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (key in schemaProperties) {\n schemaDefinedParams[key] = value;\n } else if (key.startsWith(\"_tambo_\")) {\n passThroughParams[key] = value;\n }\n // Unknown keys not in schema and not _tambo_* are dropped —\n // they're likely hallucinated by the model.\n }\n\n const unstrictified = unstrictifyToolCallParams(\n originalSchema,\n schemaDefinedParams,\n );\n\n return { ...unstrictified, ...passThroughParams };\n}\n\n/**\n * Check if a JSON Schema definition allows null values.\n * @param originalSchema - The schema definition to check\n * @returns True if the schema allows null values\n */\nexport function canBeNull(originalSchema: JSONSchema7Definition): boolean {\n if (typeof originalSchema !== \"object\") {\n return false;\n }\n\n if (originalSchema.type === \"null\") {\n return true;\n }\n\n if (originalSchema.anyOf?.some((anyOf) => canBeNull(anyOf))) {\n return true;\n }\n return false;\n}\n"]}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tambo-ai/client` - Framework-agnostic client for Tambo AI
|
|
3
|
+
*
|
|
4
|
+
* Provides streaming, tool execution, and thread management
|
|
5
|
+
* without React dependencies.
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
/** Client version constant. */
|
|
9
|
+
export declare const CLIENT_VERSION = "1.0.0";
|
|
10
|
+
export { TamboClient } from "./tambo-client.js";
|
|
11
|
+
export type { TamboClientOptions, RunOptions, ClientState, BeforeRunContext, ContextHelperFn, } from "./tambo-client.js";
|
|
12
|
+
export { TamboStream } from "./tambo-stream.js";
|
|
13
|
+
export type { StreamEvent, TamboStreamOptions } from "./tambo-stream.js";
|
|
14
|
+
export { createRunStream, dispatchUserMessage, dispatchToolResults, executeToolsAndContinue, } from "./utils/send-message.js";
|
|
15
|
+
export type { SendMessageOptions, CreateRunStreamParams, CreateRunStreamResult, ExecuteToolsParams, ExecuteToolsResult, RunStream, CreateStream, } from "./utils/send-message.js";
|
|
16
|
+
export type { TamboThread, StreamingState, RunStatus } from "./types/thread.js";
|
|
17
|
+
export type { TamboThreadMessage, TamboComponentContent, TamboToolUseContent, TamboToolDisplayProps, Content, MessageRole, ComponentStreamingState, InitialInputMessage, } from "./types/message.js";
|
|
18
|
+
export type { ComponentStartEvent, ComponentPropsDeltaEvent, ComponentStateDeltaEvent, ComponentEndEvent, RunAwaitingInputEvent, MessageParentEvent, TamboCustomEvent, PendingToolCall as PendingToolCallEvent, } from "./types/event.js";
|
|
19
|
+
export { isTamboCustomEvent, asTamboCustomEvent } from "./types/event.js";
|
|
20
|
+
export type { TamboAuthState } from "./types/auth.js";
|
|
21
|
+
export type { ToolChoice } from "./types/tool-choice.js";
|
|
22
|
+
export type { TextContent, ToolResultContent, ResourceContent, InputMessage, MessageListResponse, MessageGetResponse, } from "./types/message.js";
|
|
23
|
+
export type { ThreadCreateResponse, ThreadRetrieveResponse, ThreadListResponse, } from "./types/thread.js";
|
|
24
|
+
export type { SupportedSchema, ToolAnnotations, ParameterSpec, ComponentContextToolMetadata, ComponentContextTool, RegisteredComponent, ComponentRegistry, TamboToolRegistry, JSONSchemaLite, TamboTool, TamboToolJSONSchema, TamboToolUnknown, TamboToolStandardSchema, UnsupportedSchemaTamboTool, TamboToolAssociations, TamboComponent, RegisterToolsFn, RegisterToolFn, DefineToolFn, } from "./model/component-metadata.js";
|
|
25
|
+
export type { McpServerInfo, NormalizedMcpServerInfo, } from "./model/mcp-server-info.js";
|
|
26
|
+
export { MCPTransport, getMcpServerUniqueKey } from "./model/mcp-server-info.js";
|
|
27
|
+
export { looksLikeJSONSchema, makeJsonSchemaPartial, getParametersFromToolSchema, safeSchemaToJsonSchema, schemaToJsonSchema, isStandardSchema, assertNoRecordSchema, } from "./schema/index.js";
|
|
28
|
+
export { MCPClient, ServerType, REGISTRY_SERVER_KEY, toElicitationRequestedSchema, hasRequestedSchema, } from "./mcp/index.js";
|
|
29
|
+
export type { MCPToolCallResult, MCPToolSpec, MCPElicitationHandler, MCPSamplingHandler, MCPHandlers, ElicitationRequestedSchema, TamboElicitationRequest, TamboElicitationResponse, ElicitationContextState, PrimitiveSchemaDefinition, } from "./mcp/index.js";
|
|
30
|
+
export { streamReducer, createInitialState, createInitialStateWithMessages, createInitialThreadState, isPlaceholderThreadId, PLACEHOLDER_THREAD_ID, UnreachableCaseError, } from "./utils/event-accumulator.js";
|
|
31
|
+
export type { ThreadState, StreamState, StreamAction, EventAction, InitThreadAction, SetCurrentThreadAction, StartNewThreadAction, LoadThreadMessagesAction, SetLastCompletedRunIdAction, UpdateThreadNameAction, } from "./utils/event-accumulator.js";
|
|
32
|
+
export { executeStreamableToolCall, createThrottledStreamableExecutor, executeClientTool, executeAllPendingTools, } from "./utils/tool-executor.js";
|
|
33
|
+
export type { PendingToolCall } from "./utils/tool-executor.js";
|
|
34
|
+
export { ToolCallTracker } from "./utils/tool-call-tracker.js";
|
|
35
|
+
export { handleEventStream } from "./utils/stream-handler.js";
|
|
36
|
+
export type { StreamHandlerOptions } from "./utils/stream-handler.js";
|
|
37
|
+
export { findComponentContent } from "./utils/thread-utils.js";
|
|
38
|
+
export { createKeyedThrottle } from "./utils/keyed-throttle.js";
|
|
39
|
+
export type { KeyedThrottle } from "./utils/keyed-throttle.js";
|
|
40
|
+
export { applyJsonPatch } from "./utils/json-patch.js";
|
|
41
|
+
export { unstrictifyToolCallParamsFromSchema, canBeNull, } from "./utils/unstrictify.js";
|
|
42
|
+
export { toAvailableComponent, toAvailableComponents, toAvailableTool, toAvailableTools, } from "./utils/registry-conversion.js";
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,+BAA+B;AAC/B,eAAO,MAAM,cAAc,UAAU,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGtE,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,YAAY,GACb,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,IAAI,oBAAoB,GACxC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC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AW,EACX,WAAW,EACX,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,mCAAmC,EACnC,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GACjB,MAAM,6BAA6B,CAAC"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `@tambo-ai/client` - Framework-agnostic client for Tambo AI
|
|
4
|
+
*
|
|
5
|
+
* Provides streaming, tool execution, and thread management
|
|
6
|
+
* without React dependencies.
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.toAvailableTools = exports.toAvailableTool = exports.toAvailableComponents = exports.toAvailableComponent = exports.canBeNull = exports.unstrictifyToolCallParamsFromSchema = exports.applyJsonPatch = exports.createKeyedThrottle = exports.findComponentContent = exports.handleEventStream = exports.ToolCallTracker = exports.executeAllPendingTools = exports.executeClientTool = exports.createThrottledStreamableExecutor = exports.executeStreamableToolCall = exports.UnreachableCaseError = exports.PLACEHOLDER_THREAD_ID = exports.isPlaceholderThreadId = exports.createInitialThreadState = exports.createInitialStateWithMessages = exports.createInitialState = exports.streamReducer = exports.hasRequestedSchema = exports.toElicitationRequestedSchema = exports.REGISTRY_SERVER_KEY = exports.ServerType = exports.MCPClient = exports.assertNoRecordSchema = exports.isStandardSchema = exports.schemaToJsonSchema = exports.safeSchemaToJsonSchema = exports.getParametersFromToolSchema = exports.makeJsonSchemaPartial = exports.looksLikeJSONSchema = exports.getMcpServerUniqueKey = exports.MCPTransport = exports.asTamboCustomEvent = exports.isTamboCustomEvent = exports.executeToolsAndContinue = exports.dispatchToolResults = exports.dispatchUserMessage = exports.createRunStream = exports.TamboStream = exports.TamboClient = exports.CLIENT_VERSION = void 0;
|
|
11
|
+
/** Client version constant. */
|
|
12
|
+
exports.CLIENT_VERSION = "1.0.0";
|
|
13
|
+
// -- Core classes --
|
|
14
|
+
var tambo_client_1 = require("./tambo-client.js");
|
|
15
|
+
Object.defineProperty(exports, "TamboClient", { enumerable: true, get: function () { return tambo_client_1.TamboClient; } });
|
|
16
|
+
var tambo_stream_1 = require("./tambo-stream.js");
|
|
17
|
+
Object.defineProperty(exports, "TamboStream", { enumerable: true, get: function () { return tambo_stream_1.TamboStream; } });
|
|
18
|
+
// -- Send message utilities --
|
|
19
|
+
var send_message_1 = require("./utils/send-message.js");
|
|
20
|
+
Object.defineProperty(exports, "createRunStream", { enumerable: true, get: function () { return send_message_1.createRunStream; } });
|
|
21
|
+
Object.defineProperty(exports, "dispatchUserMessage", { enumerable: true, get: function () { return send_message_1.dispatchUserMessage; } });
|
|
22
|
+
Object.defineProperty(exports, "dispatchToolResults", { enumerable: true, get: function () { return send_message_1.dispatchToolResults; } });
|
|
23
|
+
Object.defineProperty(exports, "executeToolsAndContinue", { enumerable: true, get: function () { return send_message_1.executeToolsAndContinue; } });
|
|
24
|
+
var event_1 = require("./types/event.js");
|
|
25
|
+
Object.defineProperty(exports, "isTamboCustomEvent", { enumerable: true, get: function () { return event_1.isTamboCustomEvent; } });
|
|
26
|
+
Object.defineProperty(exports, "asTamboCustomEvent", { enumerable: true, get: function () { return event_1.asTamboCustomEvent; } });
|
|
27
|
+
var mcp_server_info_1 = require("./model/mcp-server-info.js");
|
|
28
|
+
Object.defineProperty(exports, "MCPTransport", { enumerable: true, get: function () { return mcp_server_info_1.MCPTransport; } });
|
|
29
|
+
Object.defineProperty(exports, "getMcpServerUniqueKey", { enumerable: true, get: function () { return mcp_server_info_1.getMcpServerUniqueKey; } });
|
|
30
|
+
// -- Schema --
|
|
31
|
+
var index_1 = require("./schema/index.js");
|
|
32
|
+
Object.defineProperty(exports, "looksLikeJSONSchema", { enumerable: true, get: function () { return index_1.looksLikeJSONSchema; } });
|
|
33
|
+
Object.defineProperty(exports, "makeJsonSchemaPartial", { enumerable: true, get: function () { return index_1.makeJsonSchemaPartial; } });
|
|
34
|
+
Object.defineProperty(exports, "getParametersFromToolSchema", { enumerable: true, get: function () { return index_1.getParametersFromToolSchema; } });
|
|
35
|
+
Object.defineProperty(exports, "safeSchemaToJsonSchema", { enumerable: true, get: function () { return index_1.safeSchemaToJsonSchema; } });
|
|
36
|
+
Object.defineProperty(exports, "schemaToJsonSchema", { enumerable: true, get: function () { return index_1.schemaToJsonSchema; } });
|
|
37
|
+
Object.defineProperty(exports, "isStandardSchema", { enumerable: true, get: function () { return index_1.isStandardSchema; } });
|
|
38
|
+
Object.defineProperty(exports, "assertNoRecordSchema", { enumerable: true, get: function () { return index_1.assertNoRecordSchema; } });
|
|
39
|
+
// -- MCP --
|
|
40
|
+
var index_2 = require("./mcp/index.js");
|
|
41
|
+
Object.defineProperty(exports, "MCPClient", { enumerable: true, get: function () { return index_2.MCPClient; } });
|
|
42
|
+
Object.defineProperty(exports, "ServerType", { enumerable: true, get: function () { return index_2.ServerType; } });
|
|
43
|
+
Object.defineProperty(exports, "REGISTRY_SERVER_KEY", { enumerable: true, get: function () { return index_2.REGISTRY_SERVER_KEY; } });
|
|
44
|
+
Object.defineProperty(exports, "toElicitationRequestedSchema", { enumerable: true, get: function () { return index_2.toElicitationRequestedSchema; } });
|
|
45
|
+
Object.defineProperty(exports, "hasRequestedSchema", { enumerable: true, get: function () { return index_2.hasRequestedSchema; } });
|
|
46
|
+
// -- Utils --
|
|
47
|
+
var event_accumulator_1 = require("./utils/event-accumulator.js");
|
|
48
|
+
Object.defineProperty(exports, "streamReducer", { enumerable: true, get: function () { return event_accumulator_1.streamReducer; } });
|
|
49
|
+
Object.defineProperty(exports, "createInitialState", { enumerable: true, get: function () { return event_accumulator_1.createInitialState; } });
|
|
50
|
+
Object.defineProperty(exports, "createInitialStateWithMessages", { enumerable: true, get: function () { return event_accumulator_1.createInitialStateWithMessages; } });
|
|
51
|
+
Object.defineProperty(exports, "createInitialThreadState", { enumerable: true, get: function () { return event_accumulator_1.createInitialThreadState; } });
|
|
52
|
+
Object.defineProperty(exports, "isPlaceholderThreadId", { enumerable: true, get: function () { return event_accumulator_1.isPlaceholderThreadId; } });
|
|
53
|
+
Object.defineProperty(exports, "PLACEHOLDER_THREAD_ID", { enumerable: true, get: function () { return event_accumulator_1.PLACEHOLDER_THREAD_ID; } });
|
|
54
|
+
Object.defineProperty(exports, "UnreachableCaseError", { enumerable: true, get: function () { return event_accumulator_1.UnreachableCaseError; } });
|
|
55
|
+
var tool_executor_1 = require("./utils/tool-executor.js");
|
|
56
|
+
Object.defineProperty(exports, "executeStreamableToolCall", { enumerable: true, get: function () { return tool_executor_1.executeStreamableToolCall; } });
|
|
57
|
+
Object.defineProperty(exports, "createThrottledStreamableExecutor", { enumerable: true, get: function () { return tool_executor_1.createThrottledStreamableExecutor; } });
|
|
58
|
+
Object.defineProperty(exports, "executeClientTool", { enumerable: true, get: function () { return tool_executor_1.executeClientTool; } });
|
|
59
|
+
Object.defineProperty(exports, "executeAllPendingTools", { enumerable: true, get: function () { return tool_executor_1.executeAllPendingTools; } });
|
|
60
|
+
var tool_call_tracker_1 = require("./utils/tool-call-tracker.js");
|
|
61
|
+
Object.defineProperty(exports, "ToolCallTracker", { enumerable: true, get: function () { return tool_call_tracker_1.ToolCallTracker; } });
|
|
62
|
+
var stream_handler_1 = require("./utils/stream-handler.js");
|
|
63
|
+
Object.defineProperty(exports, "handleEventStream", { enumerable: true, get: function () { return stream_handler_1.handleEventStream; } });
|
|
64
|
+
var thread_utils_1 = require("./utils/thread-utils.js");
|
|
65
|
+
Object.defineProperty(exports, "findComponentContent", { enumerable: true, get: function () { return thread_utils_1.findComponentContent; } });
|
|
66
|
+
var keyed_throttle_1 = require("./utils/keyed-throttle.js");
|
|
67
|
+
Object.defineProperty(exports, "createKeyedThrottle", { enumerable: true, get: function () { return keyed_throttle_1.createKeyedThrottle; } });
|
|
68
|
+
var json_patch_1 = require("./utils/json-patch.js");
|
|
69
|
+
Object.defineProperty(exports, "applyJsonPatch", { enumerable: true, get: function () { return json_patch_1.applyJsonPatch; } });
|
|
70
|
+
var unstrictify_1 = require("./utils/unstrictify.js");
|
|
71
|
+
Object.defineProperty(exports, "unstrictifyToolCallParamsFromSchema", { enumerable: true, get: function () { return unstrictify_1.unstrictifyToolCallParamsFromSchema; } });
|
|
72
|
+
Object.defineProperty(exports, "canBeNull", { enumerable: true, get: function () { return unstrictify_1.canBeNull; } });
|
|
73
|
+
var registry_conversion_1 = require("./utils/registry-conversion.js");
|
|
74
|
+
Object.defineProperty(exports, "toAvailableComponent", { enumerable: true, get: function () { return registry_conversion_1.toAvailableComponent; } });
|
|
75
|
+
Object.defineProperty(exports, "toAvailableComponents", { enumerable: true, get: function () { return registry_conversion_1.toAvailableComponents; } });
|
|
76
|
+
Object.defineProperty(exports, "toAvailableTool", { enumerable: true, get: function () { return registry_conversion_1.toAvailableTool; } });
|
|
77
|
+
Object.defineProperty(exports, "toAvailableTools", { enumerable: true, get: function () { return registry_conversion_1.toAvailableTools; } });
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,+BAA+B;AAClB,QAAA,cAAc,GAAG,OAAO,CAAC;AAEtC,qBAAqB;AACrB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAQpB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAGpB,+BAA+B;AAC/B,qDAK8B;AAJ5B,+GAAA,eAAe,OAAA;AACf,mHAAA,mBAAmB,OAAA;AACnB,mHAAA,mBAAmB,OAAA;AACnB,uHAAA,uBAAuB,OAAA;AAkCzB,uCAAuE;AAA9D,2GAAA,kBAAkB,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AA6C/C,2DAA8E;AAArE,+GAAA,YAAY,OAAA;AAAE,wHAAA,qBAAqB,OAAA;AAE5C,eAAe;AACf,wCAQwB;AAPtB,4GAAA,mBAAmB,OAAA;AACnB,8GAAA,qBAAqB,OAAA;AACrB,oHAAA,2BAA2B,OAAA;AAC3B,+GAAA,sBAAsB,OAAA;AACtB,2GAAA,kBAAkB,OAAA;AAClB,yGAAA,gBAAgB,OAAA;AAChB,6GAAA,oBAAoB,OAAA;AAGtB,YAAY;AACZ,qCAMqB;AALnB,kGAAA,SAAS,OAAA;AACT,mGAAA,UAAU,OAAA;AACV,4GAAA,mBAAmB,OAAA;AACnB,qHAAA,4BAA4B,OAAA;AAC5B,2GAAA,kBAAkB,OAAA;AAepB,cAAc;AACd,+DAQmC;AAPjC,kHAAA,aAAa,OAAA;AACb,uHAAA,kBAAkB,OAAA;AAClB,mIAAA,8BAA8B,OAAA;AAC9B,6HAAA,wBAAwB,OAAA;AACxB,0HAAA,qBAAqB,OAAA;AACrB,0HAAA,qBAAqB,OAAA;AACrB,yHAAA,oBAAoB,OAAA;AAetB,uDAK+B;AAJ7B,0HAAA,yBAAyB,OAAA;AACzB,kIAAA,iCAAiC,OAAA;AACjC,kHAAA,iBAAiB,OAAA;AACjB,uHAAA,sBAAsB,OAAA;AAIxB,+DAA4D;AAAnD,oHAAA,eAAe,OAAA;AACxB,yDAA2D;AAAlD,mHAAA,iBAAiB,OAAA;AAE1B,qDAA4D;AAAnD,oHAAA,oBAAoB,OAAA;AAC7B,yDAA6D;AAApD,qHAAA,mBAAmB,OAAA;AAE5B,iDAAoD;AAA3C,4GAAA,cAAc,OAAA;AACvB,mDAG6B;AAF3B,kIAAA,mCAAmC,OAAA;AACnC,wGAAA,SAAS,OAAA;AAEX,mEAKqC;AAJnC,2HAAA,oBAAoB,OAAA;AACpB,4HAAA,qBAAqB,OAAA;AACrB,sHAAA,eAAe,OAAA;AACf,uHAAA,gBAAgB,OAAA","sourcesContent":["/**\n * `@tambo-ai/client` - Framework-agnostic client for Tambo AI\n *\n * Provides streaming, tool execution, and thread management\n * without React dependencies.\n * @packageDocumentation\n */\n\n/** Client version constant. */\nexport const CLIENT_VERSION = \"1.0.0\";\n\n// -- Core classes --\nexport { TamboClient } from \"./tambo-client\";\nexport type {\n TamboClientOptions,\n RunOptions,\n ClientState,\n BeforeRunContext,\n ContextHelperFn,\n} from \"./tambo-client\";\nexport { TamboStream } from \"./tambo-stream\";\nexport type { StreamEvent, TamboStreamOptions } from \"./tambo-stream\";\n\n// -- Send message utilities --\nexport {\n createRunStream,\n dispatchUserMessage,\n dispatchToolResults,\n executeToolsAndContinue,\n} from \"./utils/send-message\";\nexport type {\n SendMessageOptions,\n CreateRunStreamParams,\n CreateRunStreamResult,\n ExecuteToolsParams,\n ExecuteToolsResult,\n RunStream,\n CreateStream,\n} from \"./utils/send-message\";\n\n// -- Types --\nexport type { TamboThread, StreamingState, RunStatus } from \"./types/thread\";\nexport type {\n TamboThreadMessage,\n TamboComponentContent,\n TamboToolUseContent,\n TamboToolDisplayProps,\n Content,\n MessageRole,\n ComponentStreamingState,\n InitialInputMessage,\n} from \"./types/message\";\nexport type {\n ComponentStartEvent,\n ComponentPropsDeltaEvent,\n ComponentStateDeltaEvent,\n ComponentEndEvent,\n RunAwaitingInputEvent,\n MessageParentEvent,\n TamboCustomEvent,\n PendingToolCall as PendingToolCallEvent,\n} from \"./types/event\";\nexport { isTamboCustomEvent, asTamboCustomEvent } from \"./types/event\";\nexport type { TamboAuthState } from \"./types/auth\";\nexport type { ToolChoice } from \"./types/tool-choice\";\n\n// Re-export SDK types that are part of the public API\nexport type {\n TextContent,\n ToolResultContent,\n ResourceContent,\n InputMessage,\n MessageListResponse,\n MessageGetResponse,\n} from \"./types/message\";\nexport type {\n ThreadCreateResponse,\n ThreadRetrieveResponse,\n ThreadListResponse,\n} from \"./types/thread\";\n\n// -- Model --\nexport type {\n SupportedSchema,\n ToolAnnotations,\n ParameterSpec,\n ComponentContextToolMetadata,\n ComponentContextTool,\n RegisteredComponent,\n ComponentRegistry,\n TamboToolRegistry,\n JSONSchemaLite,\n TamboTool,\n TamboToolJSONSchema,\n TamboToolUnknown,\n TamboToolStandardSchema,\n UnsupportedSchemaTamboTool,\n TamboToolAssociations,\n TamboComponent,\n RegisterToolsFn,\n RegisterToolFn,\n DefineToolFn,\n} from \"./model/component-metadata\";\nexport type {\n McpServerInfo,\n NormalizedMcpServerInfo,\n} from \"./model/mcp-server-info\";\nexport { MCPTransport, getMcpServerUniqueKey } from \"./model/mcp-server-info\";\n\n// -- Schema --\nexport {\n looksLikeJSONSchema,\n makeJsonSchemaPartial,\n getParametersFromToolSchema,\n safeSchemaToJsonSchema,\n schemaToJsonSchema,\n isStandardSchema,\n assertNoRecordSchema,\n} from \"./schema/index\";\n\n// -- MCP --\nexport {\n MCPClient,\n ServerType,\n REGISTRY_SERVER_KEY,\n toElicitationRequestedSchema,\n hasRequestedSchema,\n} from \"./mcp/index\";\nexport type {\n MCPToolCallResult,\n MCPToolSpec,\n MCPElicitationHandler,\n MCPSamplingHandler,\n MCPHandlers,\n ElicitationRequestedSchema,\n TamboElicitationRequest,\n TamboElicitationResponse,\n ElicitationContextState,\n PrimitiveSchemaDefinition,\n} from \"./mcp/index\";\n\n// -- Utils --\nexport {\n streamReducer,\n createInitialState,\n createInitialStateWithMessages,\n createInitialThreadState,\n isPlaceholderThreadId,\n PLACEHOLDER_THREAD_ID,\n UnreachableCaseError,\n} from \"./utils/event-accumulator\";\nexport type {\n ThreadState,\n StreamState,\n StreamAction,\n EventAction,\n InitThreadAction,\n SetCurrentThreadAction,\n StartNewThreadAction,\n LoadThreadMessagesAction,\n SetLastCompletedRunIdAction,\n UpdateThreadNameAction,\n} from \"./utils/event-accumulator\";\n\nexport {\n executeStreamableToolCall,\n createThrottledStreamableExecutor,\n executeClientTool,\n executeAllPendingTools,\n} from \"./utils/tool-executor\";\nexport type { PendingToolCall } from \"./utils/tool-executor\";\n\nexport { ToolCallTracker } from \"./utils/tool-call-tracker\";\nexport { handleEventStream } from \"./utils/stream-handler\";\nexport type { StreamHandlerOptions } from \"./utils/stream-handler\";\nexport { findComponentContent } from \"./utils/thread-utils\";\nexport { createKeyedThrottle } from \"./utils/keyed-throttle\";\nexport type { KeyedThrottle } from \"./utils/keyed-throttle\";\nexport { applyJsonPatch } from \"./utils/json-patch\";\nexport {\n unstrictifyToolCallParamsFromSchema,\n canBeNull,\n} from \"./utils/unstrictify\";\nexport {\n toAvailableComponent,\n toAvailableComponents,\n toAvailableTool,\n toAvailableTools,\n} from \"./utils/registry-conversion\";\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ElicitRequestFormParams, PrimitiveSchemaDefinition } from "@modelcontextprotocol/sdk/spec.types.js";
|
|
2
|
+
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Schema type for elicitation request fields
|
|
5
|
+
*/
|
|
6
|
+
export type ElicitationRequestedSchema = ElicitRequestFormParams["requestedSchema"];
|
|
7
|
+
/**
|
|
8
|
+
* Elicitation request from MCP server
|
|
9
|
+
*/
|
|
10
|
+
export interface TamboElicitationRequest {
|
|
11
|
+
message: string;
|
|
12
|
+
requestedSchema: ElicitationRequestedSchema;
|
|
13
|
+
/** AbortSignal that fires when the server cancels the request (e.g., timeout) */
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Re-export PrimitiveSchemaDefinition for consumers that need to work with schema fields
|
|
18
|
+
*/
|
|
19
|
+
export type { PrimitiveSchemaDefinition };
|
|
20
|
+
type ElicitRequestParamsWithRequestedSchema = Extract<ElicitRequest["params"], {
|
|
21
|
+
requestedSchema: unknown;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Elicitation response to be sent back
|
|
25
|
+
*/
|
|
26
|
+
export interface TamboElicitationResponse {
|
|
27
|
+
action: "accept" | "decline" | "cancel";
|
|
28
|
+
content?: Record<string, unknown>;
|
|
29
|
+
[x: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Elicitation context state - read-only interface for consumers.
|
|
33
|
+
* State management is handled internally by useElicitation hook.
|
|
34
|
+
*/
|
|
35
|
+
export interface ElicitationContextState {
|
|
36
|
+
/** Current elicitation request, or null if none active */
|
|
37
|
+
elicitation: TamboElicitationRequest | null;
|
|
38
|
+
/** Function to call when user responds to elicitation (clears state automatically) */
|
|
39
|
+
resolveElicitation: ((response: TamboElicitationResponse) => void) | null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Narrow the runtime ElicitRequest requestedSchema into the public
|
|
43
|
+
* ElicitationRequestedSchema type.
|
|
44
|
+
*
|
|
45
|
+
* The MCP SDK guarantees that the runtime
|
|
46
|
+
* `ElicitRequest["params"]["requestedSchema"]` shape stays aligned with the
|
|
47
|
+
* spec-defined `ElicitRequestFormParams["requestedSchema"]`. This helper
|
|
48
|
+
* centralizes the cast based on that contract so that if a future SDK version
|
|
49
|
+
* ever diverges, we have a single place to tighten the implementation (for
|
|
50
|
+
* example with structural validation or normalization).
|
|
51
|
+
* @returns requestedSchema as ElicitationRequestedSchema
|
|
52
|
+
*/
|
|
53
|
+
export declare function toElicitationRequestedSchema(value: ElicitRequestParamsWithRequestedSchema["requestedSchema"]): ElicitationRequestedSchema;
|
|
54
|
+
/**
|
|
55
|
+
* Type guard for the elicitation form params shape.
|
|
56
|
+
* @returns true when params include requestedSchema
|
|
57
|
+
*/
|
|
58
|
+
export declare function hasRequestedSchema(params: ElicitRequest["params"]): params is ElicitRequestParamsWithRequestedSchema;
|
|
59
|
+
//# sourceMappingURL=elicitation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elicitation.d.ts","sourceRoot":"","sources":["../../src/mcp/elicitation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EAC1B,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GACpC,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,0BAA0B,CAAC;IAC5C,iFAAiF;IACjF,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C,KAAK,sCAAsC,GAAG,OAAO,CACnD,aAAa,CAAC,QAAQ,CAAC,EACvB;IAAE,eAAe,EAAE,OAAO,CAAA;CAAE,CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,0DAA0D;IAC1D,WAAW,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAC5C,sFAAsF;IACtF,kBAAkB,EAAE,CAAC,CAAC,QAAQ,EAAE,wBAAwB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAC3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,sCAAsC,CAAC,iBAAiB,CAAC,GAC/D,0BAA0B,CAE5B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC9B,MAAM,IAAI,sCAAsC,CAElD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toElicitationRequestedSchema = toElicitationRequestedSchema;
|
|
4
|
+
exports.hasRequestedSchema = hasRequestedSchema;
|
|
5
|
+
/**
|
|
6
|
+
* Narrow the runtime ElicitRequest requestedSchema into the public
|
|
7
|
+
* ElicitationRequestedSchema type.
|
|
8
|
+
*
|
|
9
|
+
* The MCP SDK guarantees that the runtime
|
|
10
|
+
* `ElicitRequest["params"]["requestedSchema"]` shape stays aligned with the
|
|
11
|
+
* spec-defined `ElicitRequestFormParams["requestedSchema"]`. This helper
|
|
12
|
+
* centralizes the cast based on that contract so that if a future SDK version
|
|
13
|
+
* ever diverges, we have a single place to tighten the implementation (for
|
|
14
|
+
* example with structural validation or normalization).
|
|
15
|
+
* @returns requestedSchema as ElicitationRequestedSchema
|
|
16
|
+
*/
|
|
17
|
+
function toElicitationRequestedSchema(value) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Type guard for the elicitation form params shape.
|
|
22
|
+
* @returns true when params include requestedSchema
|
|
23
|
+
*/
|
|
24
|
+
function hasRequestedSchema(params) {
|
|
25
|
+
return "requestedSchema" in params;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=elicitation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elicitation.js","sourceRoot":"","sources":["../../src/mcp/elicitation.ts"],"names":[],"mappings":";;AAgEA,oEAIC;AAMD,gDAIC;AA1BD;;;;;;;;;;;GAWG;AACH,SAAgB,4BAA4B,CAC1C,KAAgE;IAEhE,OAAO,KAAmC,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAChC,MAA+B;IAE/B,OAAO,iBAAiB,IAAI,MAAM,CAAC;AACrC,CAAC","sourcesContent":["import type {\n ElicitRequestFormParams,\n PrimitiveSchemaDefinition,\n} from \"@modelcontextprotocol/sdk/spec.types.js\";\nimport type { ElicitRequest } from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * Schema type for elicitation request fields\n */\nexport type ElicitationRequestedSchema =\n ElicitRequestFormParams[\"requestedSchema\"];\n\n/**\n * Elicitation request from MCP server\n */\nexport interface TamboElicitationRequest {\n message: string;\n requestedSchema: ElicitationRequestedSchema;\n /** AbortSignal that fires when the server cancels the request (e.g., timeout) */\n signal?: AbortSignal;\n}\n\n/**\n * Re-export PrimitiveSchemaDefinition for consumers that need to work with schema fields\n */\nexport type { PrimitiveSchemaDefinition };\n\ntype ElicitRequestParamsWithRequestedSchema = Extract<\n ElicitRequest[\"params\"],\n { requestedSchema: unknown }\n>;\n\n/**\n * Elicitation response to be sent back\n */\nexport interface TamboElicitationResponse {\n action: \"accept\" | \"decline\" | \"cancel\";\n content?: Record<string, unknown>;\n [x: string]: unknown;\n}\n\n/**\n * Elicitation context state - read-only interface for consumers.\n * State management is handled internally by useElicitation hook.\n */\nexport interface ElicitationContextState {\n /** Current elicitation request, or null if none active */\n elicitation: TamboElicitationRequest | null;\n /** Function to call when user responds to elicitation (clears state automatically) */\n resolveElicitation: ((response: TamboElicitationResponse) => void) | null;\n}\n\n/**\n * Narrow the runtime ElicitRequest requestedSchema into the public\n * ElicitationRequestedSchema type.\n *\n * The MCP SDK guarantees that the runtime\n * `ElicitRequest[\"params\"][\"requestedSchema\"]` shape stays aligned with the\n * spec-defined `ElicitRequestFormParams[\"requestedSchema\"]`. This helper\n * centralizes the cast based on that contract so that if a future SDK version\n * ever diverges, we have a single place to tighten the implementation (for\n * example with structural validation or normalization).\n * @returns requestedSchema as ElicitationRequestedSchema\n */\nexport function toElicitationRequestedSchema(\n value: ElicitRequestParamsWithRequestedSchema[\"requestedSchema\"],\n): ElicitationRequestedSchema {\n return value as ElicitationRequestedSchema;\n}\n\n/**\n * Type guard for the elicitation form params shape.\n * @returns true when params include requestedSchema\n */\nexport function hasRequestedSchema(\n params: ElicitRequest[\"params\"],\n): params is ElicitRequestParamsWithRequestedSchema {\n return \"requestedSchema\" in params;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { MCPClient, type MCPToolCallResult, type MCPToolSpec, type MCPElicitationHandler, type MCPSamplingHandler, type MCPHandlers, } from "./mcp-client.js";
|
|
2
|
+
export { MCPTransport } from "./mcp-client.js";
|
|
3
|
+
export { ServerType, REGISTRY_SERVER_KEY } from "./mcp-constants.js";
|
|
4
|
+
export type { ElicitationRequestedSchema, TamboElicitationRequest, TamboElicitationResponse, ElicitationContextState, PrimitiveSchemaDefinition, } from "./elicitation.js";
|
|
5
|
+
export { toElicitationRequestedSchema, hasRequestedSchema, } from "./elicitation.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAClE,YAAY,EACV,0BAA0B,EAC1B,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,eAAe,CAAC"}
|
package/esm/mcp/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasRequestedSchema = exports.toElicitationRequestedSchema = exports.REGISTRY_SERVER_KEY = exports.ServerType = exports.MCPTransport = exports.MCPClient = void 0;
|
|
4
|
+
var mcp_client_1 = require("./mcp-client.js");
|
|
5
|
+
Object.defineProperty(exports, "MCPClient", { enumerable: true, get: function () { return mcp_client_1.MCPClient; } });
|
|
6
|
+
var mcp_client_2 = require("./mcp-client.js");
|
|
7
|
+
Object.defineProperty(exports, "MCPTransport", { enumerable: true, get: function () { return mcp_client_2.MCPTransport; } });
|
|
8
|
+
var mcp_constants_1 = require("./mcp-constants.js");
|
|
9
|
+
Object.defineProperty(exports, "ServerType", { enumerable: true, get: function () { return mcp_constants_1.ServerType; } });
|
|
10
|
+
Object.defineProperty(exports, "REGISTRY_SERVER_KEY", { enumerable: true, get: function () { return mcp_constants_1.REGISTRY_SERVER_KEY; } });
|
|
11
|
+
var elicitation_1 = require("./elicitation.js");
|
|
12
|
+
Object.defineProperty(exports, "toElicitationRequestedSchema", { enumerable: true, get: function () { return elicitation_1.toElicitationRequestedSchema; } });
|
|
13
|
+
Object.defineProperty(exports, "hasRequestedSchema", { enumerable: true, get: function () { return elicitation_1.hasRequestedSchema; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";;;AAAA,2CAOsB;AANpB,uGAAA,SAAS,OAAA;AAOX,2CAA4C;AAAnC,0GAAA,YAAY,OAAA;AACrB,iDAAkE;AAAzD,2GAAA,UAAU,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAQxC,6CAGuB;AAFrB,2HAAA,4BAA4B,OAAA;AAC5B,iHAAA,kBAAkB,OAAA","sourcesContent":["export {\n MCPClient,\n type MCPToolCallResult,\n type MCPToolSpec,\n type MCPElicitationHandler,\n type MCPSamplingHandler,\n type MCPHandlers,\n} from \"./mcp-client\";\nexport { MCPTransport } from \"./mcp-client\";\nexport { ServerType, REGISTRY_SERVER_KEY } from \"./mcp-constants\";\nexport type {\n ElicitationRequestedSchema,\n TamboElicitationRequest,\n TamboElicitationResponse,\n ElicitationContextState,\n PrimitiveSchemaDefinition,\n} from \"./elicitation\";\nexport {\n toElicitationRequestedSchema,\n hasRequestedSchema,\n} from \"./elicitation\";\n"]}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { type OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
+
import { ClientNotification, ClientRequest, CreateMessageRequest, CreateMessageResult, ElicitRequest, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { JSONSchema7 } from "json-schema";
|
|
6
|
+
import { MCPTransport } from "../model/mcp-server-info.js";
|
|
7
|
+
export { MCPTransport };
|
|
8
|
+
/**
|
|
9
|
+
* Handler for MCP elicitation requests.
|
|
10
|
+
* Receives the elicit request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
|
|
11
|
+
* @param request - The elicitation request from the server
|
|
12
|
+
* @param extra - Additional context including AbortSignal for cancellation
|
|
13
|
+
* @returns Promise resolving to the elicitation result
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const handler: MCPElicitationHandler = async (request, extra) => {
|
|
17
|
+
* // Listen for cancellation
|
|
18
|
+
* extra.signal.addEventListener('abort', () => {
|
|
19
|
+
* console.log('Request cancelled');
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Return user's response
|
|
23
|
+
* return {
|
|
24
|
+
* action: 'accept',
|
|
25
|
+
* content: { name: 'John' }
|
|
26
|
+
* };
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type MCPElicitationHandler = (e: ElicitRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<ElicitResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Handler for MCP sampling requests (create_message).
|
|
33
|
+
* Receives the sampling request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
|
|
34
|
+
* @param request - The sampling/create_message request from the server
|
|
35
|
+
* @param extra - Additional context including AbortSignal for cancellation
|
|
36
|
+
* @returns Promise resolving to the sampling result
|
|
37
|
+
*/
|
|
38
|
+
export type MCPSamplingHandler = (e: CreateMessageRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<CreateMessageResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Handlers for MCP requests - these are only used if the server supports the corresponding capabilities
|
|
41
|
+
* @param elicitation - Handler for elicitation requests (receives request and RequestHandlerExtra with AbortSignal)
|
|
42
|
+
* @param sampling - Handler for sampling requests (receives request and RequestHandlerExtra with AbortSignal)
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const mcp = await MCPClient.create(
|
|
46
|
+
* 'https://api.example.com/mcp',
|
|
47
|
+
* MCPTransport.HTTP,
|
|
48
|
+
* {},
|
|
49
|
+
* undefined,
|
|
50
|
+
* undefined,
|
|
51
|
+
* {
|
|
52
|
+
* elicitation: (e, extra) => Promise.resolve({...}),
|
|
53
|
+
* },
|
|
54
|
+
* );
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export interface MCPHandlers {
|
|
58
|
+
elicitation: MCPElicitationHandler;
|
|
59
|
+
sampling: MCPSamplingHandler;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A client for interacting with MCP (Model Context Protocol) servers.
|
|
63
|
+
* Provides a simple interface for listing and calling tools exposed by the server.
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const mcp = await MCPClient.create('https://api.example.com/mcp');
|
|
67
|
+
* const tools = await mcp.listTools();
|
|
68
|
+
* const result = await mcp.callTool('toolName', { arg1: 'value1' });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare class MCPClient {
|
|
72
|
+
/**
|
|
73
|
+
* The underlying MCP client
|
|
74
|
+
*
|
|
75
|
+
* Be careful not to mutate the client directly, use the methods provided instead.
|
|
76
|
+
*/
|
|
77
|
+
client: Client;
|
|
78
|
+
private transport;
|
|
79
|
+
private transportType;
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
private endpoint;
|
|
82
|
+
private headers;
|
|
83
|
+
private authProvider?;
|
|
84
|
+
private handlers;
|
|
85
|
+
/**
|
|
86
|
+
* Private constructor to enforce using the static create method.
|
|
87
|
+
* @param endpoint - The URL of the MCP server to connect to
|
|
88
|
+
* @param transportType - The transport to use for the MCP client
|
|
89
|
+
* @param headers - Optional custom headers to include in requests
|
|
90
|
+
*/
|
|
91
|
+
private constructor();
|
|
92
|
+
/**
|
|
93
|
+
* Creates and initializes a new MCPClient instance. This is the recommended
|
|
94
|
+
* way to create an MCPClient as it handles both instantiation and connection
|
|
95
|
+
* setup.
|
|
96
|
+
* @param endpoint - The URL of the MCP server to connect to
|
|
97
|
+
* @param transportType - The transport type to use for the MCP client. Defaults to HTTP.
|
|
98
|
+
* @param headers - Optional custom headers to include in requests
|
|
99
|
+
* @param authProvider - Optional auth provider to use for authentication
|
|
100
|
+
* @param sessionId - Optional session id to use for the MCP client - if not
|
|
101
|
+
* provided, a new session will be created
|
|
102
|
+
* @returns A connected MCPClient instance ready for use
|
|
103
|
+
* @throws {Error} Will throw an error if connection fails
|
|
104
|
+
*/
|
|
105
|
+
static create(endpoint: string, transportType: MCPTransport | undefined, headers: Record<string, string> | undefined, authProvider: OAuthClientProvider | undefined, sessionId: string | undefined, handlers?: Partial<MCPHandlers>): Promise<MCPClient>;
|
|
106
|
+
private initializeTransport;
|
|
107
|
+
/**
|
|
108
|
+
* Initializes the MCP client with the appropriate capabilities and handlers
|
|
109
|
+
* @returns The initialized MCP client
|
|
110
|
+
*/
|
|
111
|
+
private initializeClient;
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves a complete list of all available tools from the MCP server.
|
|
114
|
+
* Handles pagination automatically by following cursors until all tools are fetched.
|
|
115
|
+
* @returns A complete list of all available tools and their descriptions
|
|
116
|
+
* @throws {Error} Will throw an error if any server request fails during pagination
|
|
117
|
+
*/
|
|
118
|
+
listTools(): Promise<MCPToolSpec[]>;
|
|
119
|
+
getServerCapabilities(): {
|
|
120
|
+
experimental?: {
|
|
121
|
+
[x: string]: object;
|
|
122
|
+
} | undefined;
|
|
123
|
+
logging?: object | undefined;
|
|
124
|
+
completions?: object | undefined;
|
|
125
|
+
prompts?: {
|
|
126
|
+
listChanged?: boolean | undefined;
|
|
127
|
+
} | undefined;
|
|
128
|
+
resources?: {
|
|
129
|
+
subscribe?: boolean | undefined;
|
|
130
|
+
listChanged?: boolean | undefined;
|
|
131
|
+
} | undefined;
|
|
132
|
+
tools?: {
|
|
133
|
+
listChanged?: boolean | undefined;
|
|
134
|
+
} | undefined;
|
|
135
|
+
tasks?: {
|
|
136
|
+
[x: string]: unknown;
|
|
137
|
+
list?: object | undefined;
|
|
138
|
+
cancel?: object | undefined;
|
|
139
|
+
requests?: {
|
|
140
|
+
[x: string]: unknown;
|
|
141
|
+
tools?: {
|
|
142
|
+
[x: string]: unknown;
|
|
143
|
+
call?: object | undefined;
|
|
144
|
+
} | undefined;
|
|
145
|
+
} | undefined;
|
|
146
|
+
} | undefined;
|
|
147
|
+
} | undefined;
|
|
148
|
+
getServerVersion(): {
|
|
149
|
+
version: string;
|
|
150
|
+
name: string;
|
|
151
|
+
websiteUrl?: string | undefined;
|
|
152
|
+
description?: string | undefined;
|
|
153
|
+
icons?: {
|
|
154
|
+
src: string;
|
|
155
|
+
mimeType?: string | undefined;
|
|
156
|
+
sizes?: string[] | undefined;
|
|
157
|
+
theme?: "light" | "dark" | undefined;
|
|
158
|
+
}[] | undefined;
|
|
159
|
+
title?: string | undefined;
|
|
160
|
+
} | undefined;
|
|
161
|
+
getInstructions(): string | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Calls a specific tool on the MCP server with the provided arguments.
|
|
164
|
+
* @param name - The name of the tool to call
|
|
165
|
+
* @param args - Arguments to pass to the tool, must match the tool's expected schema
|
|
166
|
+
* @returns The result from the tool execution
|
|
167
|
+
* @throws {Error} Will throw an error if the tool call fails or if arguments are invalid
|
|
168
|
+
*/
|
|
169
|
+
callTool(name: string, args: Record<string, unknown>, _meta?: Record<string, unknown>): Promise<MCPToolCallResult>;
|
|
170
|
+
updateElicitationHandler(handler: MCPElicitationHandler | undefined): void;
|
|
171
|
+
updateSamplingHandler(handler: MCPSamplingHandler | undefined): void;
|
|
172
|
+
close(): Promise<void>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The result of a tool call.
|
|
176
|
+
* This is the same as the result of a tool call in the OpenAI SDK, but is reified here
|
|
177
|
+
*/
|
|
178
|
+
export type MCPToolCallResult = Awaited<ReturnType<typeof Client.prototype.callTool>>;
|
|
179
|
+
export interface MCPToolSpec {
|
|
180
|
+
name: string;
|
|
181
|
+
description?: string;
|
|
182
|
+
inputSchema?: JSONSchema7;
|
|
183
|
+
maxCalls?: number;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=mcp-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"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